all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* declare-function from included file
@ 2008-03-16 18:23 Ralf Angeli
  2008-03-19  0:47 ` Glenn Morris
  0 siblings, 1 reply; 10+ messages in thread
From: Ralf Angeli @ 2008-03-16 18:23 UTC (permalink / raw)
  To: emacs-devel

Hi,

is it possible to put calls to `declare-function' in a file to be
included during byte compilation?  The following does not seem not work:

Create the following three files ...

file.el:

(eval-when-compile
  (require 'include))
(defun foo ()
  (bar))

include.el:

(declare-function bar "ext:baz")
(provide 'include)

lpath.el:

(setq load-path (cons "." load-path))

... and compile file.el with
emacs -batch -q -l lpath.el -f batch-byte-compile file.el

With this recipe there is still a warning from the byte compiler about
`bar' being undefined.

I can silence the byte compiler by using
(fset 'bar (lambda (&rest args) nil))
in include.el instead of the `declare-function' call.  Would this be a
better alternative?

-- 
Ralf





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: declare-function from included file
  2008-03-16 18:23 declare-function from included file Ralf Angeli
@ 2008-03-19  0:47 ` Glenn Morris
  2008-03-19 18:57   ` Ralf Angeli
  0 siblings, 1 reply; 10+ messages in thread
From: Glenn Morris @ 2008-03-19  0:47 UTC (permalink / raw)
  To: Ralf Angeli; +Cc: emacs-devel

Ralf Angeli wrote:

> is it possible to put calls to `declare-function' in a file to be
> included during byte compilation?  The following does not seem not work:

No, because by design declare-function only has an effect when being
_compiled_, and you're not compiling the code in the included file.
(At least, I think that explains it.)

> I can silence the byte compiler by using (fset 'bar (lambda (&rest
>args) nil)) in include.el instead of the `declare-function' call.
> Would this be a better alternative?

That looks ugly to me, and could break loading of the non-compiled
code. Why not just put your declare-function statements in the right
file? Though I guess the whole point of this is that you don't want
to. Or live with the warnings.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: declare-function from included file
  2008-03-19  0:47 ` Glenn Morris
@ 2008-03-19 18:57   ` Ralf Angeli
  2008-03-19 19:30     ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Ralf Angeli @ 2008-03-19 18:57 UTC (permalink / raw)
  To: Glenn Morris; +Cc: emacs-devel

* Glenn Morris (2008-03-19) writes:

> Ralf Angeli wrote:
>
>> is it possible to put calls to `declare-function' in a file to be
>> included during byte compilation?  The following does not seem not work:
>
> No, because by design declare-function only has an effect when being
> _compiled_, and you're not compiling the code in the included file.
> (At least, I think that explains it.)

Hm, this is what I suspected as well.

>> I can silence the byte compiler by using (fset 'bar (lambda (&rest
>>args) nil)) in include.el instead of the `declare-function' call.
>> Would this be a better alternative?
>
> That looks ugly to me, and could break loading of the non-compiled
> code.

Why is that?  Would the body of `eval-when-compile' be executed in this
case?  That's the only thing I can imagine causing trouble.

> Why not just put your declare-function statements in the right
> file? Though I guess the whole point of this is that you don't want
> to.

Yes, it clutters the file contents.  And the package -- we are talking
about RefTeX here -- is supposed to work with Emacs 21 and XEmacs as
well.  This means one would have to define `declare-function' in every
file it is used in case Emacs or XEmacs does not provide it.  This is
how it's done in Gnus at the moment and it looks quite clunky.  If the
`declare-function' statements where in a separate file, one could define
`declare-function' only once.

> Or live with the warnings.

Personally I'm not bothered too much by them but since we are talking
about code which is part of Emacs this is likely not an option.

-- 
Ralf




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: declare-function from included file
  2008-03-19 18:57   ` Ralf Angeli
@ 2008-03-19 19:30     ` Stefan Monnier
  2008-03-19 20:32       ` Ralf Angeli
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2008-03-19 19:30 UTC (permalink / raw)
  To: Ralf Angeli; +Cc: Glenn Morris, emacs-devel

> Personally I'm not bothered too much by them but since we are talking
> about code which is part of Emacs this is likely not an option.

Silencing incorrect warnings is a good thing.  But it's not a priority
and most importantly, is less important than keeping code simple.

So the `fset' hack is a really bad idea, just like the tramp-let-maybe.
Better live with warnings than with such contraptions.

Adding `declare-function' is not that big a problem since it doesn't
make code more complex, but if you don't like it, don't use it.

This said, if you have a need for *many* declare-function, then maybe
the problem is elsewhere and you should report it (maybe Emacs could be
more clever about how to detect when a warning is needed).


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: declare-function from included file
  2008-03-19 19:30     ` Stefan Monnier
@ 2008-03-19 20:32       ` Ralf Angeli
  2008-03-19 20:42         ` Dan Nicolaescu
  0 siblings, 1 reply; 10+ messages in thread
From: Ralf Angeli @ 2008-03-19 20:32 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Glenn Morris, emacs-devel

* Stefan Monnier (2008-03-19) writes:

> This said, if you have a need for *many* declare-function, then maybe
> the problem is elsewhere and you should report it (maybe Emacs could be
> more clever about how to detect when a warning is needed).

In case of RefTeX most of the warnings stem from calls to AUCTeX
functions in reftex-auc.el.  (The functions are only used if
`reftex-plug-into-AUCTeX' is non-nil.)  So this is not really Emacs'
fault of not being clever enough.

-- 
Ralf




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: declare-function from included file
  2008-03-19 20:32       ` Ralf Angeli
@ 2008-03-19 20:42         ` Dan Nicolaescu
  2008-03-19 21:00           ` Ralf Angeli
  0 siblings, 1 reply; 10+ messages in thread
From: Dan Nicolaescu @ 2008-03-19 20:42 UTC (permalink / raw)
  To: Ralf Angeli; +Cc: Glenn Morris, Stefan Monnier, emacs-devel

Ralf Angeli <angeli@caeruleus.net> writes:

  > * Stefan Monnier (2008-03-19) writes:
  > 
  > > This said, if you have a need for *many* declare-function, then maybe
  > > the problem is elsewhere and you should report it (maybe Emacs could be
  > > more clever about how to detect when a warning is needed).
  > 
  > In case of RefTeX most of the warnings stem from calls to AUCTeX
  > functions in reftex-auc.el.  (The functions are only used if
  > `reftex-plug-into-AUCTeX' is non-nil.)  So this is not really Emacs'
  > fault of not being clever enough.

In CVS trunk reftex compiles without warnings.  There are 10
`declare-function's in reftex*el, 8 of which are in reftex-auc.el.
That does not sound like too much, it's hard to see that it's even worth discussing...




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: declare-function from included file
  2008-03-19 20:42         ` Dan Nicolaescu
@ 2008-03-19 21:00           ` Ralf Angeli
  2008-03-19 21:19             ` Dan Nicolaescu
  0 siblings, 1 reply; 10+ messages in thread
From: Ralf Angeli @ 2008-03-19 21:00 UTC (permalink / raw)
  To: Dan Nicolaescu; +Cc: Glenn Morris, Stefan Monnier, emacs-devel

* Dan Nicolaescu (2008-03-19) writes:

> In CVS trunk reftex compiles without warnings.

In RefTeX's own repository compiling still emits warnings.

> There are 10
> `declare-function's in reftex*el, 8 of which are in reftex-auc.el.
> That does not sound like too much, it's hard to see that it's even worth discussing...

It's not just the `declare-function' stuff I'm after.  RefTeX contains a
lot of `defvar' statements which are only there for the sake of the byte
compiler.  And I'd like to put those into a separate file as well along
with stuff like `declare-function' calls.

-- 
Ralf




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: declare-function from included file
  2008-03-19 21:00           ` Ralf Angeli
@ 2008-03-19 21:19             ` Dan Nicolaescu
  2008-03-19 21:45               ` Ralf Angeli
  0 siblings, 1 reply; 10+ messages in thread
From: Dan Nicolaescu @ 2008-03-19 21:19 UTC (permalink / raw)
  To: Ralf Angeli; +Cc: Glenn Morris, Stefan Monnier, emacs-devel

Ralf Angeli <angeli@caeruleus.net> writes:

  > * Dan Nicolaescu (2008-03-19) writes:
  > 
  > > In CVS trunk reftex compiles without warnings.
  > 
  > In RefTeX's own repository compiling still emits warnings.

What's wrong with just copying the declare-functions from emacs CVS to
get rid of them? 

  > > There are 10
  > > `declare-function's in reftex*el, 8 of which are in reftex-auc.el.
  > > That does not sound like too much, it's hard to see that it's even worth discussing...
  > 
  > It's not just the `declare-function' stuff I'm after.  RefTeX contains a
  > lot of `defvar' statements which are only there for the sake of the byte
  > compiler.  
  >
  > And I'd like to put those into a separate file as well along with
  > stuff like `declare-function' calls.

defvars work, they are well known by any elisp hackers.
Why develop a new facility the everyone looking at the code will have to
figure out?
There's not that many defvars either, about 50 if my grep command was right.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: declare-function from included file
  2008-03-19 21:19             ` Dan Nicolaescu
@ 2008-03-19 21:45               ` Ralf Angeli
  2008-03-19 22:18                 ` Dan Nicolaescu
  0 siblings, 1 reply; 10+ messages in thread
From: Ralf Angeli @ 2008-03-19 21:45 UTC (permalink / raw)
  To: Dan Nicolaescu; +Cc: Glenn Morris, Stefan Monnier, emacs-devel

* Dan Nicolaescu (2008-03-19) writes:

> Ralf Angeli <angeli@caeruleus.net> writes:
>
>   > In RefTeX's own repository compiling still emits warnings.
>
> What's wrong with just copying the declare-functions from emacs CVS to
> get rid of them? 

I've already explained this in this thread.

>   > It's not just the `declare-function' stuff I'm after.  RefTeX contains a
>   > lot of `defvar' statements which are only there for the sake of the byte
>   > compiler.  
>   >
>   > And I'd like to put those into a separate file as well along with
>   > stuff like `declare-function' calls.
>
> defvars work, they are well known by any elisp hackers.
> Why develop a new facility the everyone looking at the code will have to
> figure out?

Oh, I see putting them in a separate file does not work either.  I guess
I'll have to live with the cruft then.

-- 
Ralf




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: declare-function from included file
  2008-03-19 21:45               ` Ralf Angeli
@ 2008-03-19 22:18                 ` Dan Nicolaescu
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Nicolaescu @ 2008-03-19 22:18 UTC (permalink / raw)
  To: Ralf Angeli; +Cc: Glenn Morris, Stefan Monnier, emacs-devel

Ralf Angeli <angeli@caeruleus.net> writes:

  > * Dan Nicolaescu (2008-03-19) writes:
  > 
  > > Ralf Angeli <angeli@caeruleus.net> writes:
  > >
  > >   > In RefTeX's own repository compiling still emits warnings.
  > >
  > > What's wrong with just copying the declare-functions from emacs CVS to
  > > get rid of them? 
  > 
  > I've already explained this in this thread.

The 3 files that use declare-function would need to add a one liner
for compatibility with older versions or XEmacs:

(eval-and-compile (unless (fboundp 'declare-function) (defmacro declare-function (&rest))))

This is already done by other files in the emacs tree.

As a GNU package reftex should not deliberately diverge from Emacs CVS HEAD...




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-03-19 22:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-16 18:23 declare-function from included file Ralf Angeli
2008-03-19  0:47 ` Glenn Morris
2008-03-19 18:57   ` Ralf Angeli
2008-03-19 19:30     ` Stefan Monnier
2008-03-19 20:32       ` Ralf Angeli
2008-03-19 20:42         ` Dan Nicolaescu
2008-03-19 21:00           ` Ralf Angeli
2008-03-19 21:19             ` Dan Nicolaescu
2008-03-19 21:45               ` Ralf Angeli
2008-03-19 22:18                 ` Dan Nicolaescu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.