* About the usage of `with-eval-after-load'.
@ 2021-09-18 9:51 Hongyi Zhao
2021-09-18 10:28 ` Omar Polo
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Hongyi Zhao @ 2021-09-18 9:51 UTC (permalink / raw)
To: help-gnu-emacs
`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.
Regards
--
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: About the usage of `with-eval-after-load'.
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
2021-09-19 0:16 ` Michael Heerdegen
2 siblings, 0 replies; 10+ messages in thread
From: Omar Polo @ 2021-09-18 10:28 UTC (permalink / raw)
To: Hongyi Zhao; +Cc: help-gnu-emacs
h
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> `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")
> )
this is wrong. as the signature says, it accepts a first argument
"file" and then the body to execute. here, it seems that you want to
execute something when `python' is loaded and something else when `elpy'
is loaded, which warrants two `with-eval-after-load':
(with-eval-after-load 'python
(define-key ...)
(add-to-list ...))
(with-eval-after-load 'elpy
(pyvenv-activate ...))
Other than that, I don't usually write python so can't comment further
on the code
> Is there anything wrong with my understanding of this macro? Any hints
> will be helpful.
>
> Regards
Cheers,
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: About the usage of `with-eval-after-load'.
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
2021-09-18 14:56 ` [External] : " Drew Adams
2021-09-19 0:16 ` Michael Heerdegen
2 siblings, 1 reply; 10+ messages in thread
From: Joost Kremers @ 2021-09-18 10:40 UTC (permalink / raw)
To: Hongyi Zhao; +Cc: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [External] : Re: About the usage of `with-eval-after-load'.
2021-09-18 10:40 ` Joost Kremers
@ 2021-09-18 14:56 ` Drew Adams
2021-09-19 3:41 ` Hongyi Zhao
0 siblings, 1 reply; 10+ messages in thread
From: Drew Adams @ 2021-09-18 14:56 UTC (permalink / raw)
To: Joost Kremers, Hongyi Zhao; +Cc: help-gnu-emacs@gnu.org
> > 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...) 'elpy (pyvenv-activate...))
Joost explained well what's going on. In addition,
just in case it still isn't clear:
You're using only _one_ FILE arg, "python". The 3
other args you pass correspond to the &rest arg (aka
&body defmacro arg), BODY. So BODY is the list of
actual args: ((progn...) 'elpy (pyenv-activate...)).
Before macro `with-eval-after-load' was added, users
sometimes forgot to quote (or otherwise generate) the
second arg to the _function_ `eval-after-load' (and it
is a single arg, FORM, not an &rest list of args BODY).
That was the main reason `with-*' was introduced: for
convenience because 99% of the time FORM was a quoted
sexp, and sometimes users forgot the quote char.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: About the usage of `with-eval-after-load'.
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
@ 2021-09-19 0:16 ` Michael Heerdegen
2021-09-19 1:16 ` Hongyi Zhao
2 siblings, 1 reply; 10+ messages in thread
From: Michael Heerdegen @ 2021-09-19 0:16 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> Is there anything wrong with my understanding of this macro? Any hints
> will be helpful.
`macroexpand' your macro call.
Michael.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: About the usage of `with-eval-after-load'.
2021-09-19 0:16 ` Michael Heerdegen
@ 2021-09-19 1:16 ` Hongyi Zhao
2021-09-19 1:50 ` Michael Heerdegen
0 siblings, 1 reply; 10+ messages in thread
From: Hongyi Zhao @ 2021-09-19 1:16 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
On Sun, Sep 19, 2021 at 8:17 AM Michael Heerdegen
<michael_heerdegen@web.de> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > Is there anything wrong with my understanding of this macro? Any hints
> > will be helpful.
>
> `macroexpand' your macro call.
`C-j' gives the following:
(macroexpand
'(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")))
(eval-after-load 'python (lambda nil (progn (define-key
python-mode-map ... ...) (add-to-list ... "jupyter")) 'elpy
(pyvenv-activate "~/.pyenv/versions/datasci")))
Best, HZ
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: About the usage of `with-eval-after-load'.
2021-09-19 1:16 ` Hongyi Zhao
@ 2021-09-19 1:50 ` Michael Heerdegen
2021-09-19 1:55 ` Hongyi Zhao
0 siblings, 1 reply; 10+ messages in thread
From: Michael Heerdegen @ 2021-09-19 1:50 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> > `macroexpand' your macro call.
>
> `C-j' gives the following:
>
> (macroexpand
> '(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")))
> (eval-after-load 'python (lambda nil (progn (define-key
> python-mode-map ... ...) (add-to-list ... "jupyter")) 'elpy
> (pyvenv-activate "~/.pyenv/versions/datasci")))
... which shows that everything ends in one lambda, called after loading
"python".
Michael.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: About the usage of `with-eval-after-load'.
2021-09-19 1:50 ` Michael Heerdegen
@ 2021-09-19 1:55 ` Hongyi Zhao
0 siblings, 0 replies; 10+ messages in thread
From: Hongyi Zhao @ 2021-09-19 1:55 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
On Sun, Sep 19, 2021 at 9:51 AM Michael Heerdegen
<michael_heerdegen@web.de> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > > `macroexpand' your macro call.
> >
> > `C-j' gives the following:
> >
> > (macroexpand
> > '(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")))
> > (eval-after-load 'python (lambda nil (progn (define-key
> > python-mode-map ... ...) (add-to-list ... "jupyter")) 'elpy
> > (pyvenv-activate "~/.pyenv/versions/datasci")))
>
> ... which shows that everything ends in one lambda, called after loading
> "python".
So, my usage is wrong.
Best, HZ
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [External] : Re: About the usage of `with-eval-after-load'.
2021-09-18 14:56 ` [External] : " Drew Adams
@ 2021-09-19 3:41 ` Hongyi Zhao
2021-09-19 4:25 ` Drew Adams
0 siblings, 1 reply; 10+ messages in thread
From: Hongyi Zhao @ 2021-09-19 3:41 UTC (permalink / raw)
To: Drew Adams; +Cc: Joost Kremers, help-gnu-emacs@gnu.org
On Sat, Sep 18, 2021 at 10:56 PM Drew Adams <drew.adams@oracle.com> wrote:
>
> > > 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...) 'elpy (pyvenv-activate...))
>
> Joost explained well what's going on. In addition,
> just in case it still isn't clear:
>
> You're using only _one_ FILE arg, "python". The 3
> other args you pass correspond to the &rest arg (aka
> &body defmacro arg), BODY. So BODY is the list of
> actual args: ((progn...) 'elpy (pyenv-activate...)).
>
> Before macro `with-eval-after-load' was added, users
> sometimes forgot to quote (or otherwise generate) the
> second arg to the _function_ `eval-after-load' (and it
> is a single arg, FORM, not an &rest list of args BODY).
>
> That was the main reason `with-*' was introduced: for
> convenience because 99% of the time FORM was a quoted
> sexp, and sometimes users forgot the quote char.
Thank you for your thoughtful further explanation, which makes me feel
that the Emacs community is indeed one of the few places in the world
where dedicated experts and masters gather. Even though my LISP
language level is still fairly rudimentary, I still have the
motivation to improve with the help of many mentors in such an
environment.
BTW, why do you write the title for your post like the following:
RE: [External] :
Best, HZ
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [External] : Re: About the usage of `with-eval-after-load'.
2021-09-19 3:41 ` Hongyi Zhao
@ 2021-09-19 4:25 ` Drew Adams
0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2021-09-19 4:25 UTC (permalink / raw)
To: Hongyi Zhao; +Cc: Joost Kremers, help-gnu-emacs@gnu.org
> BTW, why do you write the title for your post like the following:
> RE: [External] :
Apologies for that noise. There's nothing I
can do about that. It's introduced by the
mail server used by my employer; IOW, it's
configured at the server level.
I could manually remove it from _each_ mail
I send outside the company, but I'm too lazy
to do that.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-09-19 4:25 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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.