help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: An alternative to a monolithic ~/.emacs init file


From: Sebastian Tennant
Subject: Re: An alternative to a monolithic ~/.emacs init file
Date: Fri, 09 Nov 2007 16:18:17 +0200
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux)

Quoth rustom <rustompmody@gmail.com>:
> Thanks. I think I understand autoload. Also I dont want needless
> loading at emacs-startup -- its unlikely that in a given session I
> will do C and python and ruby and org and tramp and elisp and .....
> though I do use all these once in a while. What I dont understand are
> magic cookies and how emacs uses them; or more correctly *When* emacs
> uses them.  The elisp manual says:
>
> "These comments do nothing on their own, but they serve as a guide for
>  the command `update-file-autoloads', which constructs calls to
>  'autoload' and arranges to execute them when Emacs is built."

> Does this mean I have to rebuild emacs if I want to use this ?!

First of all, autoloads exist precisely for the reason you've stated;
avoiding needless loading of functions at startup.  Consider the
function 'foo' defined in bar.el.  If your ~/.emacs includes the line

  (autoload 'foo "bar.el" "My function foo" t)

then Emacs knows where to find the function definition, if and when you
type the command 'M-x foo'.  The function itself is not loaded until you
call it, (the autoload call means Emacs is simply aware of the name of
the function, and the file where it is found), thus saving memory
resources and reducing startup time.  A better name than 'autoload'
might be:

 'load-later'

or,

 'dont-load-until-needed-but-heres-where-to-find-it-anyway'

I agree the explanation in the manual is unclear/inadequate.  You
certainly don't have to rebuild Emacs!  update-file-autoloads is called
when emacs is rebuilt, yes, but there's nothing to stop you calling
update-file-autoloads yourself.  It works by parsing a file and
constructing autoload calls (like the one above) based on occurrences of
magic cookies (;;;###autoload) in elisp code.  The constructed autoload
calls are then written to a file named according to the value of the
variable generated-autoload-file.

update-directory-autoloads works in exactly the same way, but on all the
files within a directory.  So,

 (let ((generated-autoload-file "~/elisp/dotemacs/auto-autoloads.el"))
   (update-directory-autoloads "~/elisp/lib/"))

works by temporarily binding the value of generated-autoload-file so
that autoload calls based on magic cookies found within files in
~/elisp/lib are written to a file within ~/elisp/dotemacs.

As for loaddefs.el, this is the equivalent of auto-autoloads.el above.
It is a file full of autoload calls created by the update-file-autoloads
function.  There are no less than six loaddefs.el on my machine but the
main one (/usr/share/emacs/22.1/lisp/loaddefs.el) is some 33,000 lines
long and I have no doubt it was generated once at build time, but is
loaded every time at startup, making all those functions available to
me, but not actually loading any of them until they're needed.

Perhaps someone else could confirm that this is the case.

Sebastian





reply via email to

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