* Nested `with-eval-after-load'?
@ 2015-08-10 20:13 Alexander Shukaev
2015-08-12 17:21 ` Michael Heerdegen
0 siblings, 1 reply; 3+ messages in thread
From: Alexander Shukaev @ 2015-08-10 20:13 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
is nested `with-eval-after-load' considered a bad practice? 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)?
Regards,
Alexander
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Nested `with-eval-after-load'?
2015-08-10 20:13 Nested `with-eval-after-load'? Alexander Shukaev
@ 2015-08-12 17:21 ` Michael Heerdegen
2015-08-13 11:18 ` Alexander Shukaev
0 siblings, 1 reply; 3+ messages in thread
From: Michael Heerdegen @ 2015-08-12 17:21 UTC (permalink / raw)
To: Alexander Shukaev; +Cc: help-gnu-emacs
Alexander Shukaev <haroogan@gmail.com> 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
`after-load-alist'.
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?
Michael.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Nested `with-eval-after-load'?
2015-08-12 17:21 ` Michael Heerdegen
@ 2015-08-13 11:18 ` Alexander Shukaev
0 siblings, 0 replies; 3+ messages in thread
From: Alexander Shukaev @ 2015-08-13 11:18 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
> So, your question is too general to give a more concrete answer. What
> is your real-life problem?
Nothing special, it's just that I have two nested
`with-eval-after-load' quite often when I have to configure one
package using another one (for example, `evil' and `helm', etc.).
However, it looks like with
> 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).
I'm on the safe side even if packages get reloaded during Emacs usage
(manually, for instance).
Regards,
Alexander
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-13 11:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-10 20:13 Nested `with-eval-after-load'? Alexander Shukaev
2015-08-12 17:21 ` Michael Heerdegen
2015-08-13 11:18 ` Alexander Shukaev
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.