diff options
| author | Stefan Monnier | 2019-05-29 15:56:14 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-05-29 15:56:14 -0400 |
| commit | fe0cb43fb80db52a79ef898f8de49560cc5cdd90 (patch) | |
| tree | 4825956db223eb96d69583e707cbf13a4d280789 /doc | |
| parent | 49cdbb4a35f8d1d2139e8469bffcf33f65679094 (diff) | |
| download | emacs-fe0cb43fb80db52a79ef898f8de49560cc5cdd90.tar.gz emacs-fe0cb43fb80db52a79ef898f8de49560cc5cdd90.zip | |
* lisp/subr.el (add-hook): Turn `append` into `depth` (bug#35508)
Make it possible to control the relative ordering of functions on hooks by
specifying `depth` in the same was as was possible with `add-function`.
* lisp/electric.el (electric--sort-post-self-insertion-hook):
Delete function.
(electric-indent-mode, electric-layout-mode, electric-quote-mode):
* lisp/elec-pair.el (electric-pair-mode): Use new `depth` arg instead of
electric--sort-post-self-insertion-hook.
* lisp/emacs-lisp/syntax.el (syntax-propertize, syntax-ppss):
Use new `depth` arg to make sure noone accidentally gets added
after syntax-ppss-flush-cache.
* doc/lispref/modes.texi (Setting Hooks): Document new `depth` arg.
* test/lisp/subr-tests.el (subr-tests-add-hook-depth): New test.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/modes.texi | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index 97e9be9918f..27c5d77579f 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi | |||
| @@ -142,7 +142,7 @@ in Lisp Interaction mode: | |||
| 142 | (add-hook 'lisp-interaction-mode-hook 'auto-fill-mode) | 142 | (add-hook 'lisp-interaction-mode-hook 'auto-fill-mode) |
| 143 | @end example | 143 | @end example |
| 144 | 144 | ||
| 145 | @defun add-hook hook function &optional append local | 145 | @defun add-hook hook function &optional depth local |
| 146 | This function is the handy way to add function @var{function} to hook | 146 | This function is the handy way to add function @var{function} to hook |
| 147 | variable @var{hook}. You can use it for abnormal hooks as well as for | 147 | variable @var{hook}. You can use it for abnormal hooks as well as for |
| 148 | normal hooks. @var{function} can be any Lisp function that can accept | 148 | normal hooks. @var{function} can be any Lisp function that can accept |
| @@ -167,9 +167,18 @@ For a normal hook, hook functions should be designed so that the order | |||
| 167 | in which they are executed does not matter. Any dependence on the order | 167 | in which they are executed does not matter. Any dependence on the order |
| 168 | is asking for trouble. However, the order is predictable: normally, | 168 | is asking for trouble. However, the order is predictable: normally, |
| 169 | @var{function} goes at the front of the hook list, so it is executed | 169 | @var{function} goes at the front of the hook list, so it is executed |
| 170 | first (barring another @code{add-hook} call). If the optional argument | 170 | first (barring another @code{add-hook} call). |
| 171 | @var{append} is non-@code{nil}, the new hook function goes at the end of | 171 | |
| 172 | the hook list and is executed last. | 172 | In some cases, it is important to control the relative ordering of functions |
| 173 | on the hook. The optional argument @var{depth} lets you indicate where the | ||
| 174 | function should be inserted in the list: it should then be a number | ||
| 175 | between -100 and 100 where the higher the value, the closer to the end of the | ||
| 176 | list the function should go. The @var{depth} defaults to 0 and for backward | ||
| 177 | compatibility when @var{depth} is a non-nil symbol it is interpreted as a depth | ||
| 178 | of 90. Furthermore, when @var{depth} is strictly greater than 0 the function | ||
| 179 | is added @emph{after} rather than before functions of the same depth. | ||
| 180 | One should never use a depth of 100 (or -100), because one can never be | ||
| 181 | sure that no other function will ever need to come before (or after) us. | ||
| 173 | 182 | ||
| 174 | @code{add-hook} can handle the cases where @var{hook} is void or its | 183 | @code{add-hook} can handle the cases where @var{hook} is void or its |
| 175 | value is a single function; it sets or changes the value to a list of | 184 | value is a single function; it sets or changes the value to a list of |