[Top][All Lists]

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

Re: Nested `with-eval-after-load'?

From: Michael Heerdegen
Subject: Re: Nested `with-eval-after-load'?
Date: Wed, 12 Aug 2015 19:21:40 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Alexander Shukaev <address@hidden> writes:

> Hello,
> is nested `with-eval-after-load' considered a bad practice?

At least I would try to avoid that where I can.

> I'm curious because of the following
> (with-eval-after-load 'x
>   (with-eval-after-load 'y
>     (message "Hello, World!")))
> (require 'x)
> (require 'y)
> ;; prints "Hello, World!"
> (unload-feature 'x)
> (require 'x)
> ;; prints "Hello, World!"
> ;; prints "Hello, World!"
> Is this true that "Hello, World!" would be printed 2 times after
> reloading (i.e. the same after-load routine would be added twice for
> the `y' package)?

In this example I think you get only one "Hello, World!" at the end, not
two.  When you do the second (require 'x) call, there is an entry for
each x and y in `after-load-alist'.  The entry for y is irrelevant since
you don't reload y.  So, after the second (require 'x),

   (with-eval-after-load 'y
     (message "Hello, World!"))

is executed.  And because y is already loaded, you get one "Hello,
World!" message.

For your question about adding duplicates:

`with-eval-after-load' builds a function and adds it to

Normally, `with-eval-after-load' tries to avoid to add duplicates of one
and the same function (it tests for presence with `equal' before adding
any function in the according alist value).  But note that
`with-eval-after-load' unconditionally executes any code when the
according feature is already present (like in your example).

So, your question is too general to give a more concrete answer.  What
is your real-life problem?


reply via email to

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