Every major mode command should finish by running the mode-independent
change-major-mode-after-body-hook, its mode hook,
and the normal hook
It does this by calling
run-mode-hooks. If the major mode is a
derived mode, that is if it calls another major mode (the parent mode)
in its body, it should do this inside
delay-mode-hooks so that
the parent won't run these hooks itself. Instead, the derived mode's
run-mode-hooks runs the parent's mode hook too.
See Major Mode Conventions.
Emacs versions before Emacs 22 did not have
Versions before 24 did not have
When user-implemented major modes do not use
have not been updated to use these newer features, they won't entirely
follow these conventions: they may run the parent's mode hook too early,
or fail to run
after-change-major-mode-hook. If you encounter
such a major mode, please correct it to follow these conventions.
When you define a major mode using
automatically makes sure these conventions are followed. If you
define a major mode “by hand”, not using
use the following functions to handle these conventions automatically.
Major modes should run their mode hook using this function. It is similar to
run-hooks(see Hooks), but it also runs
hack-local-variables(when the buffer is visiting a file) (see File Local Variables), and
after-change-major-mode-hook. The last thing it does is to evaluate any
:after-hookforms declared by parent modes (see Derived Modes).
When this function is called during the execution of a
delay-mode-hooksform, it does not run the hooks or
hack-local-variablesor evaluate the forms immediately. Instead, it arranges for the next call to
run-mode-hooksto run them.
When one major mode command calls another, it should do so inside of
This macro executes body, but tells all
run-mode-hookscalls during the execution of body to delay running their hooks. The hooks will actually run during the next call to
run-mode-hooksafter the end of the
This is a normal hook run by
run-mode-hooks. It is run before the mode hooks.