[Top][All Lists]

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

Re: with-eval-after-load with sh-mode

From: Arthur Miller
Subject: Re: with-eval-after-load with sh-mode
Date: Fri, 02 Jul 2021 15:08:33 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) writes:

>>From: Arthur Miller <>
>>Subject: Re: with-eval-after-load with sh-mode
>>Date: 02/07/2021 10:56:14 Europe/Paris
>> writes:
>>>From: Arthur Miller <>
>>>Subject: Re: with-eval-after-load with sh-mode
>>>Date: 02/07/2021 10:42:38 Europe/Paris
>>> writes:
>>>> How can I use `with-eval-after-load` with sh-mode?
>>>> Basically I want to defer call to sh-mode-map until sh-mode is loaded
>>>> (with-eval-after-load 'sh
>>>Try this:
>>>(with-eval-after-load 'sh-script
>>>(message "My cool one-time config follows here ..."))
>>>sh-mode is defined in lisp/progmodes/sh-script.el.
>> What is the difference between 
>> (with-eval-after-load 'sh-script
>> (myfun))
>> and
>> (add-hook 'sh-mode-hook #'myfun)
>>Obviously sh-mode-hook gets executed every time you load sh-mode, i.e,
>>when you open a shell file.
>>eval after load will kick in when feature is loaded, i.e. when you read
>>in (load or require) sh-script.el, so it least in theory it should get
>>executed only once, unless you unload feature 'sh-script for some reason.
> This leads to another consideraion.  There are certainly advantages about 
> using
> `with-eval-after-load`.  But, then, what are the circumstances for using 
> `add-hook`?

As said above: the circustance is when you wish a piece of code to run
every time a mode is loaded.

You should probably read the fine manual:

reply via email to

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