unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Joost Kremers <joostkremers@fastmail.fm>
To: Hongyi Zhao <hongyi.zhao@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: About the usage of `with-eval-after-load'.
Date: Sat, 18 Sep 2021 12:40:29 +0200	[thread overview]
Message-ID: <87wnnetazo.fsf@fastmail.fm> (raw)
In-Reply-To: <CAGP6POJ=BxLWKL0w7mYsz_WgoC3fBJFKapyu=SO9cXO4XYfe7g@mail.gmail.com>


On Sat, Sep 18 2021, Hongyi Zhao wrote:
> `C-h o with-eval-after-load RET' gives the following description:
>
> with-eval-after-load is a Lisp macro in ‘subr.el’.
>
> (with-eval-after-load FILE &rest BODY)
>
> Execute BODY after FILE is loaded.
> FILE is normally a feature name, but it can also be a file name,
> in case that file does not provide any feature.  See ‘eval-after-load’
> for more details about the different forms of FILE and their semantics.
> ;;;
>
> Based on the above explanation, it seems that only one FILE can be
> used, but according to my tries, the following code snippet also take
> effect:
>
>   (add-hook 'python-mode-hook 'hs-minor-mode)
>   (with-eval-after-load
>     "python"
>     (progn
>       (define-key python-mode-map (kbd "C-c TAB") 'hs-toggle-hiding)
>       (add-to-list
> 'python-shell-completion-native-disabled-interpreters "jupyter")
>       )
>
>     'elpy (pyvenv-activate "~/.pyenv/versions/datasci")
>     )
>
> Is there anything wrong with my understanding of this macro? Any hints
> will be helpful.

Remember that in Lisp, a quoted symbol just evaluates to the symbol. So what
happens in your code is that when "python.el" is loaded, three sexps are
evaluated: the `progn`, the quoted symbol `'elpy` and the call to
`pyvenv-activate`.

The form *appears* to work because you probably load elpy whenever you open a
Python file, so you don't notice what's really going on. You'd have to
experiment with two packages that are completely independent from each other.

BTW, `with-eval-after-load` doesn't need `progn`. That was one of the reasons
for introducing `with-eval-after-load` as an alternative for `eval-after-load`.

HTH

-- 
Joost Kremers
Life has its moments



  parent reply	other threads:[~2021-09-18 10:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-18  9:51 About the usage of `with-eval-after-load' Hongyi Zhao
2021-09-18 10:28 ` Omar Polo
2021-09-18 10:40 ` Joost Kremers [this message]
2021-09-18 14:56   ` [External] : " Drew Adams
2021-09-19  3:41     ` Hongyi Zhao
2021-09-19  4:25       ` Drew Adams
2021-09-19  0:16 ` Michael Heerdegen
2021-09-19  1:16   ` Hongyi Zhao
2021-09-19  1:50     ` Michael Heerdegen
2021-09-19  1:55       ` Hongyi Zhao

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87wnnetazo.fsf@fastmail.fm \
    --to=joostkremers@fastmail.fm \
    --cc=help-gnu-emacs@gnu.org \
    --cc=hongyi.zhao@gmail.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).