emacs-devel
[Top][All Lists]
Advanced

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

Re: Question: loading code when two packages are load?


From: Stefan Monnier
Subject: Re: Question: loading code when two packages are load?
Date: Wed, 08 Sep 2021 23:31:50 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> Thanks! This looks like exactly what I need.
> I don’t understand why the manual says
> "well-designed Lisp programs should not use with-eval-after-load”
> and advocate for using require though.
> Isn’t with-eval-after-load exactly the lazy counterpart of require?

Experience shows that `with-eval-after-load` (and its brother
`after-load-functions`) can make debugging more difficult (typically
when you aren't aware that such and such package you're using uses
`with-eval-after-load` on the file you're trying to debug), which is why
we recommend to use alternatives when possible.

For example often you can replace use of `with-eval-after-load` by using
the hook of the (major or minor) mode defined in that file.

> It sounds like after-load-functions (although eval-after-load works as well
> because we just need to target some specific packages),
> but somehow manual says it’s an “abnormal hook” which I don’t really 
> understand.

Normal hooks have a specific calling convention (no arguments, no
return value).  Any hook which uses a different calling convention is
hence an abnormal hook (and this is reflected in its name ending in
`functions` rather than `-hook`).  "Abnormal" does not mean "bad".

> The Hooks for Loading info section seems to try very hard to
> talk people out of using itself.

Emacs is full of tools to shoot oneself (and others) in the foot,
because we feel it's important to make sure users can do that when they
feel the need.  But yes we do try and discourage them from using those
tools ;-)


        Stefan




reply via email to

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