diff options
| author | Alan Mackenzie | 2016-05-08 13:24:20 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2016-05-08 13:24:20 +0000 |
| commit | 2eb6817ba971184cc109f8530f4b3b38f65650ea (patch) | |
| tree | b23258db9a4d1720583784fd1b90824a45835f91 /doc | |
| parent | 344eb61ab3607827930354589174bb8d270241b9 (diff) | |
| download | emacs-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.texi | 26 |
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 |
| 753 | The new mode has its own mode hook, @code{@var{variant}-hook}. It | 753 | The new mode has its own mode hook, @code{@var{variant}-hook}. It |
| 754 | runs this hook, after running the hooks of its ancestor modes, with | 754 | runs 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 |
| 756 | any @code{:after-hook} form it may have. @xref{Mode Hooks}. | ||
| 756 | @end itemize | 757 | @end itemize |
| 757 | 758 | ||
| 758 | In addition, you can specify how to override other aspects of | 759 | In 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 | |||
| 776 | documentation string. If you omit @var{docstring}, | 777 | documentation 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 | ||
| 779 | The @var{keyword-args} are pairs of keywords and values. The values | 780 | The @var{keyword-args} are pairs of keywords and values. The values, |
| 780 | are evaluated. The following keywords are currently supported: | 781 | except for @code{:after-hook}'s, are evaluated. The following |
| 782 | keywords 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 | |||
| 801 | experimental and unadvertised) command @code{customize-mode} currently | 803 | experimental and unadvertised) command @code{customize-mode} currently |
| 802 | uses this. @code{define-derived-mode} does @emph{not} automatically | 804 | uses this. @code{define-derived-mode} does @emph{not} automatically |
| 803 | define the specified customization group. | 805 | define the specified customization group. |
| 806 | |||
| 807 | @item :after-hook | ||
| 808 | This optional keyword specifies a single Lisp form to evaluate as the | ||
| 809 | final act of the mode function, after the mode hooks have been run. | ||
| 810 | It should not be quoted. Since the form might be evaluated after the | ||
| 811 | mode function has terminated, it should not access any element of the | ||
| 812 | mode function's local state. An @code{:after-hook} form is useful for | ||
| 813 | setting up aspects of the mode which depend on the user's settings, | ||
| 814 | which in turn may have been changed in a mode hook. | ||
| 804 | @end table | 815 | @end table |
| 805 | 816 | ||
| 806 | Here is a hypothetical example: | 817 | Here is a hypothetical example: |
| @@ -912,12 +923,15 @@ Major modes should run their mode hook using this function. It is | |||
| 912 | similar to @code{run-hooks} (@pxref{Hooks}), but it also runs | 923 | similar 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}), |
| 915 | and @code{after-change-major-mode-hook}. | 926 | and @code{after-change-major-mode-hook}. The last thing it does is to |
| 927 | evaluate any @code{:after-hook} forms declared by parent modes | ||
| 928 | (@pxref{Derived Modes}). | ||
| 916 | 929 | ||
| 917 | When this function is called during the execution of a | 930 | When 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. |
| 920 | next call to @code{run-mode-hooks} to run them. | 933 | Instead, it arranges for the next call to @code{run-mode-hooks} to run |
| 934 | them. | ||
| 921 | @end defun | 935 | @end defun |
| 922 | 936 | ||
| 923 | @defmac delay-mode-hooks body@dots{} | 937 | @defmac delay-mode-hooks body@dots{} |