Next: Example Major Modes, Previous: Generic Modes, Up: Major Modes
Every major mode function should finish by running its mode hook and
the mode-independent normal hook after-change-major-mode-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
call to run-mode-hooks runs the parent's mode hook too.
See Major Mode Conventions.
Emacs versions before Emacs 22 did not have delay-mode-hooks.
When user-implemented major modes have not been updated to use it,
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 defined a major mode using define-derived-mode, it
automatically makes sure these conventions are followed. If you
define a major mode “by hand,” not using define-derived-mode,
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 runsafter-change-major-mode-hook.When this function is called during the execution of a
delay-mode-hooksform, it does not run the hooks immediately. Instead, it arranges for the next call torun-mode-hooksto run them.
When one major mode command calls another, it should do so inside of
delay-mode-hooks.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 torun-mode-hooksafter the end of thedelay-mode-hooksconstruct.
This is a normal hook run by
run-mode-hooks. It is run at the very end of every properly-written major mode function.
