all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Omar Polo <op@omarpolo.com>
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:28:16 +0200	[thread overview]
Message-ID: <87mtoaqio8.fsf@omarpolo.com> (raw)
In-Reply-To: <CAGP6POJ=BxLWKL0w7mYsz_WgoC3fBJFKapyu=SO9cXO4XYfe7g@mail.gmail.com>

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,



  reply	other threads:[~2021-09-18 10:28 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 [this message]
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

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=87mtoaqio8.fsf@omarpolo.com \
    --to=op@omarpolo.com \
    --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.
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.