[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is it a good idea to use `add-hook' and `remove-hook' in a minor mod
From: |
Ship Mints |
Subject: |
Re: Is it a good idea to use `add-hook' and `remove-hook' in a minor mode? |
Date: |
Thu, 22 May 2025 13:44:16 -0400 |
On Thu, May 22, 2025 at 1:06 PM <mbork@mbork.pl> wrote:
> On 2025-05-22, at 12:52, Michael Heerdegen via Users list for the GNU
> Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> > mbork@mbork.pl writes:
> >
> >> Hi all,
> >>
> >> I'd like to define a minor mode which enables me to use ElDoc to show
> >> some information about the thing at point. Is it a good practice to use
> >> `add-hook' and `remove-hook' in its definition to add/remove my function
> >> to/from `eldoc-documentation-functions'? AFAIU, hooks are usually to be
> >> used by the user and not modified by a mode.
> >
> > For such things it's ok - normal practice.
>
> Thanks!
>
> > Instead of removing your function when the mode is turned off you can
> > also make your function test whether the mode is on or off, and keep it
> > always installed. Sometimes this is even necessary to handle different
> > buffers with different states (of the mode).
>
> Thanks again - I did not think about it. I'll probably not use this
> approach in my current project, but I agree, this is something worth
> keeping in mind.
>
Also read up on buffer-local hooks as they might be useful for this use
case (which granted I know nothing about and am just guessing). It's at
the end of the end-user hook docs and mentioned in the elisp manual.
https://www.gnu.org/software/emacs/manual/html_node/emacs/Hooks.html
https://www.gnu.org/software/emacs/manual/html_node/elisp/Hooks.html
https://www.gnu.org/software/emacs/manual/html_node/elisp/Setting-Hooks.html
HTH,
-Stephane