help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: add-hook without need for intermediate functions


From: uzibalqa
Subject: Re: add-hook without need for intermediate functions
Date: Sat, 10 Jun 2023 15:21:07 +0000

------- Original Message -------
On Saturday, June 10th, 2023 at 8:20 PM, Platon Pronko 
<platon7pronko@gmail.com> wrote:


> On 2023-06-09 23:48, uzibalqa wrote:
> 
> > I have seen that since Emacs 24.1 one does not need the intermediate 
> > 'turn-on-foo-mode'
> > style functions when using hooks.
> > 
> > Does this apply to all modes, including minor modes ?
> > 
> > And thusly one can write
> > 
> > (add-hook 'emacs-lisp-mode-hook #'foo-minor-mode)
> 
> 
> foo-minor-mode is just a function, so it is called when hook executes. Any 
> other modes that are turned on via a single function call will also "work".
> 
> However note that this won't work for your use-case (from previous thread) - 
> hook is called both when mode is turned on, and when it is turned off. So in 
> your code snippet foo-minor-mode will be turned on when emacs-lisp-mode is 
> turned off, which is probably not something you would want. - Platon Pronko


What would one do then, remove the hook at some point.  Would you show me an 
example on how to handle the situation
properly.




reply via email to

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