[Top][All Lists]

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

Re: About the usage of `with-eval-after-load'.

From: Joost Kremers
Subject: Re: About the usage of `with-eval-after-load'.
Date: Sat, 18 Sep 2021 12:40:29 +0200
User-agent: mu4e 1.6.3; emacs 27.2.50

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

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`.


Joost Kremers
Life has its moments

reply via email to

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