unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Joost Kremers <joostkremers@fastmail.fm>
Cc: 43868@debbugs.gnu.org
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	[thread overview]
Message-ID: <83a6ww7d1q.fsf@gnu.org> (raw)
In-Reply-To: <87sgao7dyd.fsf@fastmail.fm> (message from Joost Kremers on Thu,  08 Oct 2020 20:46:50 +0200)

> 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	other threads:[~2020-10-08 19:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08 18:46 bug#43868: 27.1.50; Documentation: Mention that minor mode hooks are also run when the minor mode is deactivated Joost Kremers
2020-10-08 19:06 ` Eli Zaretskii [this message]
2020-10-09  4:37   ` Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83a6ww7d1q.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=43868@debbugs.gnu.org \
    --cc=joostkremers@fastmail.fm \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).