Function: run-mode-hooks
run-mode-hooks is a byte-compiled function defined in subr.el.gz.
Signature
(run-mode-hooks &rest HOOKS)
Documentation
Run mode hooks delayed-mode-hooks and HOOKS, or delay HOOKS.
Call hack-local-variables to set up file local and directory local
variables.
If the variable delay-mode-hooks(var)/delay-mode-hooks(fun) is non-nil, does not do anything,
just adds the HOOKS to the list delayed-mode-hooks.
Otherwise, runs hooks in the sequence: change-major-mode-after-body-hook,
delayed-mode-hooks (in reverse order), HOOKS, then runs
hack-local-variables (if the buffer is visiting a file),
runs the hook after-change-major-mode-hook, and finally
evaluates the functions in delayed-after-hook-functions (see
define-derived-mode).
Major mode functions should use this instead of run-hooks when
running their FOO-mode-hook.
Probably introduced at or before Emacs version 22.1.
Aliases
semantic-run-mode-hooks (obsolete since 28.1)
Source Code
;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defun run-mode-hooks (&rest hooks)
"Run mode hooks `delayed-mode-hooks' and HOOKS, or delay HOOKS.
Call `hack-local-variables' to set up file local and directory local
variables.
If the variable `delay-mode-hooks' is non-nil, does not do anything,
just adds the HOOKS to the list `delayed-mode-hooks'.
Otherwise, runs hooks in the sequence: `change-major-mode-after-body-hook',
`delayed-mode-hooks' (in reverse order), HOOKS, then runs
`hack-local-variables' (if the buffer is visiting a file),
runs the hook `after-change-major-mode-hook', and finally
evaluates the functions in `delayed-after-hook-functions' (see
`define-derived-mode').
Major mode functions should use this instead of `run-hooks' when
running their FOO-mode-hook."
(if delay-mode-hooks
;; Delaying case.
(dolist (hook hooks)
(push hook delayed-mode-hooks))
;; Normal case, just run the hook as before plus any delayed hooks.
(setq hooks (nconc (nreverse delayed-mode-hooks) hooks))
(and (bound-and-true-p syntax-propertize-function)
(not (local-variable-p 'parse-sexp-lookup-properties))
;; `syntax-propertize' sets `parse-sexp-lookup-properties' for us, but
;; in order for the sexp primitives to automatically call
;; `syntax-propertize' we need `parse-sexp-lookup-properties' to be
;; set first.
(setq-local parse-sexp-lookup-properties t))
(setq delayed-mode-hooks nil)
(apply #'run-hooks (cons 'change-major-mode-after-body-hook hooks))
(if (buffer-file-name)
(with-demoted-errors "File local-variables error: %s"
(hack-local-variables 'no-mode)))
(run-hooks 'after-change-major-mode-hook)
(dolist (fun (prog1 (nreverse delayed-after-hook-functions)
(setq delayed-after-hook-functions nil)))
(funcall fun))))