aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorStefan Monnier2019-05-29 15:56:14 -0400
committerStefan Monnier2019-05-29 15:56:14 -0400
commitfe0cb43fb80db52a79ef898f8de49560cc5cdd90 (patch)
tree4825956db223eb96d69583e707cbf13a4d280789 /doc
parent49cdbb4a35f8d1d2139e8469bffcf33f65679094 (diff)
downloademacs-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.texi17
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
146This function is the handy way to add function @var{function} to hook 146This function is the handy way to add function @var{function} to hook
147variable @var{hook}. You can use it for abnormal hooks as well as for 147variable @var{hook}. You can use it for abnormal hooks as well as for
148normal hooks. @var{function} can be any Lisp function that can accept 148normal 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
167in which they are executed does not matter. Any dependence on the order 167in which they are executed does not matter. Any dependence on the order
168is asking for trouble. However, the order is predictable: normally, 168is 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
170first (barring another @code{add-hook} call). If the optional argument 170first (barring another @code{add-hook} call).
171@var{append} is non-@code{nil}, the new hook function goes at the end of 171
172the hook list and is executed last. 172In some cases, it is important to control the relative ordering of functions
173on the hook. The optional argument @var{depth} lets you indicate where the
174function should be inserted in the list: it should then be a number
175between -100 and 100 where the higher the value, the closer to the end of the
176list the function should go. The @var{depth} defaults to 0 and for backward
177compatibility when @var{depth} is a non-nil symbol it is interpreted as a depth
178of 90. Furthermore, when @var{depth} is strictly greater than 0 the function
179is added @emph{after} rather than before functions of the same depth.
180One should never use a depth of 100 (or -100), because one can never be
181sure 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
175value is a single function; it sets or changes the value to a list of 184value is a single function; it sets or changes the value to a list of