all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Alexander Shukaev <haroogan@gmail.com>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: Nested `with-eval-after-load'?
Date: Wed, 12 Aug 2015 19:21:40 +0200	[thread overview]
Message-ID: <87zj1wo21n.fsf@web.de> (raw)
In-Reply-To: <CAKu-7WztYpknQoi7AqwqrTXaQEu0e+q7hxfLn5qw+GH6Ct-GAA@mail.gmail.com> (Alexander Shukaev's message of "Mon, 10 Aug 2015 22:13:24 +0200")

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.



  reply	other threads:[~2015-08-12 17:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-10 20:13 Nested `with-eval-after-load'? Alexander Shukaev
2015-08-12 17:21 ` Michael Heerdegen [this message]
2015-08-13 11:18   ` Alexander Shukaev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zj1wo21n.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=haroogan@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.