emacs-pretest-bug
[Top][All Lists]
Advanced

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

Should eval of `require' cause a `require' entry in `load-history'?


From: Drew Adams
Subject: Should eval of `require' cause a `require' entry in `load-history'?
Date: Sat, 22 Oct 2005 01:25:01 -0700

emacs -q

Edit a new file foo.el, which is not in your load-path. Put (require
'bar) and (provide 'foo) in it, where bar.el is a library in your
load-path.

Evaluate the `require' and `provide' (e.g. `eval-buffer).

Variable `load-history' now has a `provide' entry for foo, but not a
`require' entry for foo. (If bar.el contains `require's or `provide's,
they are entered in load-history correctly.)

IIUC, for a `require' entry to be added to `load-history', the file
containing it must be _loaded_, via `load', `load-file',
`load-library', or `require' - it is not enough to evaluate a
`require' expression for it to be added as an entry for the file in
which it is contained.

Do I understand this correctly? I'm not sure it's bad, but I'm also
not sure it's documented. It could be rationalized, saying that
`load-history' is, after all, a _load_ history. On the other hand,
functions like `file-requires', which depend on `load-history',
purport to give a list of file dependencies - that is, dependencies
defined by the `require's in files.

"Loaded" files, you'll say, but should it also include "evaluated"
files? Or perhaps I shouldn't speak of "evaluated files" but of
"evaluated expressions" or "buffers". Note too that function
`require's doc string speaks of it "loading" files and their features,
so evaluating `require' would presumably load a file just as `load'
does. It seems there is "loading" and "loading", with different
behaviors wrt `load-history'.

Here's the comment for the culprit code in the definition of `require'
in fns.c (note the last phrase: "not when we aren't loading a file"):

  /* Record the presence of `require' in this file
     even if the feature specified is already loaded.
     But not more than once in any file,
     and not when we aren't loading a file.  */

Again, I don't know if this is a bug, but if not it might be good to
document the behavior. I mention this because it not only confuses me,
but someone else was bitten by this misunderstanding when using my
code that uses `file-requires' recursively to track file dependencies
- he expected `eval-buffer' to do what needed to be done, in order for
`file-requires' to be able to pick up the dependency.

Also, I'll mention that my code has problems because of this `require'
behavior (suggestions welcome). I try to load each required library,
then recursively go after the libraries it requires by checking
`load-history'.

    (condition-case nil
        (load-library (symbol-name library))
      (error (require library)))

When I try to load the library, I can't just use `require', because
`require' won't record anything in `load-history' (since the `require'
is not found in a file).

And I can't just use `load-library', because of things like file
`float-sup.el' containing (provide 'lisp-float-type) - (load-library
'lisp-float-type) raises an error. So, my hack is to first try
`load-library', and punt with `require' (which loads, but doesn't
record sub-requires in `load-history') in case of error. I can get by
with this, for what I need, but it isn't pretty.

Thanks.


In GNU Emacs 22.0.50.1 (i386-mingw-nt5.1.2600)
 of 2005-06-26 on NONIQPC
X server distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc
(3.3) --cflags -I../../jpeg-6b-3/include -I../../libpng-1.2.8/include -I../.
./tiff-3.6.1-2/include -I../../xpm-nox-4.2.0/include -I../../zlib-1.2.2/incl
ude'





reply via email to

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