emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Treatise on require


From: Stefan Monnier
Subject: Re: Treatise on require
Date: Sun, 08 Jan 2006 21:20:09 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

> Is there a treatise on loading that shows best practices in the use of
> require, autoload, defvar, eval-when-compile, eval-and-compile?

I think `defvar' in an outlier in your list.  It's unrelated.
`eval-and-compile' is only useful for self-dependencies (e.g. when a macro
uses the value of a variable defined in the same file: so the variable
definition needs to be evaluated both at compile time (when you use the
macros) and at run time) so it's not related either.

> Over time, nasty circular dependencies have reared their ugly head in
> MH-E.

Get rid of them by moving things around, including into new files.
Sometimes merging small files into one big one makes more sense.

> For example, mh-e requires just about other file

That's to be expected: mh-e.el probably uses most/all of the mh-e code.

> and just about every other file requires mh-e.

That can't be right.

> This is currently handled by putting the call to provides (in mh-e.el)
> before the various calls to require (whose files require mh-e).

Bad idea.

> I'm sort of thinking that it might be better to replace the require
> calls with something like:

>   (eval-when-compile
>     (autoload 'foo "foo")
>     (defvar foo))

Better not.  Especially the `defvar' inside `eval-when-compile' is
basically meaningless, it should be moved out.

> This would placate the compiler without creating require loops.

If you like to fix symptoms rather than causes, go for it.  Or better yet:
use `with-no-warnings'.  But I'd advise you against it.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]