aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorAlan Mackenzie2016-05-08 13:24:20 +0000
committerAlan Mackenzie2016-05-08 13:24:20 +0000
commit2eb6817ba971184cc109f8530f4b3b38f65650ea (patch)
treeb23258db9a4d1720583784fd1b90824a45835f91 /doc
parent344eb61ab3607827930354589174bb8d270241b9 (diff)
downloademacs-2eb6817ba971184cc109f8530f4b3b38f65650ea.tar.gz
emacs-2eb6817ba971184cc109f8530f4b3b38f65650ea.zip
Add :after-hook facility to define-derived-mode.
This allow a form to be evaluated _after_ a major mode's hooks have been run. It is needed to solve some problems in CC Mode, including bug #16759 and bug #23476. * lisp/emacs-lisp/derived.el (define-derived-mode): introduce the new argument `:after-hook', and generate the requisite code for it. (derived-mode-make-docstring): Take account of the possibility of :after-hook. * lisp/subr.el (delayed-after-hook-forms): New variable. (run-mode-hooks): As the last thing evaluate the forms in delayed-after-hook-forms. * doc/lispref/modes.texi (Derived Modes): Document :after-hook. (Mode Hooks): Document the new feature in run-mode-hooks. * etc/NEWS: Note the new feature.
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/modes.texi26
1 files changed, 20 insertions, 6 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 76e5174bd20..7b76e6af9c3 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -752,7 +752,8 @@ The new mode has its own abbrev table, kept in the variable
752@item 752@item
753The new mode has its own mode hook, @code{@var{variant}-hook}. It 753The new mode has its own mode hook, @code{@var{variant}-hook}. It
754runs this hook, after running the hooks of its ancestor modes, with 754runs this hook, after running the hooks of its ancestor modes, with
755@code{run-mode-hooks}, as the last thing it does. @xref{Mode Hooks}. 755@code{run-mode-hooks}, as the last thing it does, apart from running
756any @code{:after-hook} form it may have. @xref{Mode Hooks}.
756@end itemize 757@end itemize
757 758
758In addition, you can specify how to override other aspects of 759In addition, you can specify how to override other aspects of
@@ -776,8 +777,9 @@ about the mode's hook, followed by the mode's keymap, at the end of this
776documentation string. If you omit @var{docstring}, 777documentation string. If you omit @var{docstring},
777@code{define-derived-mode} generates a documentation string. 778@code{define-derived-mode} generates a documentation string.
778 779
779The @var{keyword-args} are pairs of keywords and values. The values 780The @var{keyword-args} are pairs of keywords and values. The values,
780are evaluated. The following keywords are currently supported: 781except for @code{:after-hook}'s, are evaluated. The following
782keywords are currently supported:
781 783
782@table @code 784@table @code
783@item :syntax-table 785@item :syntax-table
@@ -801,6 +803,15 @@ this mode. (Not all major modes have one.) Only the (still
801experimental and unadvertised) command @code{customize-mode} currently 803experimental and unadvertised) command @code{customize-mode} currently
802uses this. @code{define-derived-mode} does @emph{not} automatically 804uses this. @code{define-derived-mode} does @emph{not} automatically
803define the specified customization group. 805define the specified customization group.
806
807@item :after-hook
808This optional keyword specifies a single Lisp form to evaluate as the
809final act of the mode function, after the mode hooks have been run.
810It should not be quoted. Since the form might be evaluated after the
811mode function has terminated, it should not access any element of the
812mode function's local state. An @code{:after-hook} form is useful for
813setting up aspects of the mode which depend on the user's settings,
814which in turn may have been changed in a mode hook.
804@end table 815@end table
805 816
806Here is a hypothetical example: 817Here is a hypothetical example:
@@ -912,12 +923,15 @@ Major modes should run their mode hook using this function. It is
912similar to @code{run-hooks} (@pxref{Hooks}), but it also runs 923similar to @code{run-hooks} (@pxref{Hooks}), but it also runs
913@code{change-major-mode-after-body-hook}, @code{hack-local-variables} 924@code{change-major-mode-after-body-hook}, @code{hack-local-variables}
914(when the buffer is visiting a file) (@pxref{File Local Variables}), 925(when the buffer is visiting a file) (@pxref{File Local Variables}),
915and @code{after-change-major-mode-hook}. 926and @code{after-change-major-mode-hook}. The last thing it does is to
927evaluate any @code{:after-hook} forms declared by parent modes
928(@pxref{Derived Modes}).
916 929
917When this function is called during the execution of a 930When this function is called during the execution of a
918@code{delay-mode-hooks} form, it does not run the hooks or 931@code{delay-mode-hooks} form, it does not run the hooks or
919@code{hack-local-variables} immediately. Instead, it arranges for the 932@code{hack-local-variables} or evaluate the forms immediately.
920next call to @code{run-mode-hooks} to run them. 933Instead, it arranges for the next call to @code{run-mode-hooks} to run
934them.
921@end defun 935@end defun
922 936
923@defmac delay-mode-hooks body@dots{} 937@defmac delay-mode-hooks body@dots{}