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

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

bug#43868: 27.1.50; Documentation: Mention that minor mode hooks are als


From: Eli Zaretskii
Subject: bug#43868: 27.1.50; Documentation: Mention that minor mode hooks are also run when the minor mode is deactivated
Date: Thu, 08 Oct 2020 22:06:25 +0300

> From: Joost Kremers <joostkremers@fastmail.fm>
> Date: Thu, 08 Oct 2020 20:46:50 +0200
> 
> Minor mode hooks are run when the minor mode is activated but also when
> the mode is deactivated. This is mentioned in the default doc string for minor
> mode hooks, but it does not seem to be mentioned in the Elisp manual.
> 
> I checked the section "Modes > Minor Modes > Defining Minor Modes", which
> mentions that `define-minor-mode` creates a hook variable, but it doesn't
> mention when it is run. I think it should be mentioned that it is run both 
> when
> the mode is activated and when the mode is deactivated.
> 
> (Other sections don't seem to be as relevant: while searching for information 
> on
> this, I also looked in the section "Customization > Variables > Hooks", but 
> that
> section doesn't mention minor mode hooks at all. Same thing for the Emacs
> manual: it doesn't seem to mention minor mode hooks anywhere.)

"Minor Mode Conventions"

     In addition, several major mode conventions (*note Major Mode
  Conventions::) apply to minor modes as well: those regarding the names
  of global symbols, the use of a hook at the end of the initialization
  function, and the use of keymaps and other tables.

"Major Mode Conventions":

     • Each major mode should have a normal “mode hook” named
       ‘MODENAME-mode-hook’.  The very last thing the major mode command
       should do is to call ‘run-mode-hooks’.  This runs the normal hook
       ‘change-major-mode-after-body-hook’, the mode hook, the function
       ‘hack-local-variables’ (when the buffer is visiting a file), and
       then the normal hook ‘after-change-major-mode-hook’.  *Note Mode
       Hooks::.

"Mode Hooks":

  Every major mode command should finish by running the mode-independent
  normal hook ‘change-major-mode-after-body-hook’, its mode hook, and the
  normal hook ‘after-change-major-mode-hook’.  It does this by calling
  ‘run-mode-hooks’.

Since the mode command runs both when turning the mode on and when
turning it off, the above implies that the mode hook runs in both
situations.





reply via email to

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