* 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.
This commit is contained in:
Stefan Monnier 2019-05-29 15:56:14 -04:00
parent 49cdbb4a35
commit fe0cb43fb8
8 changed files with 113 additions and 53 deletions

View file

@ -298,7 +298,7 @@ END) suitable for `syntax-propertize-function'."
;; between syntax-ppss and syntax-propertize, we also have to make
;; sure the flush function is installed here (bug#29767).
(add-hook 'before-change-functions
#'syntax-ppss-flush-cache t t))
#'syntax-ppss-flush-cache 99 t))
(save-excursion
(with-silent-modifications
(make-local-variable 'syntax-propertize--done) ;Just in case!
@ -430,7 +430,7 @@ These are valid when the buffer has no restriction.")
;; Unregister if there's no cache left. Sadly this doesn't work
;; because `before-change-functions' is temporarily bound to nil here.
;; (unless cache
;; (remove-hook 'before-change-functions 'syntax-ppss-flush-cache t))
;; (remove-hook 'before-change-functions #'syntax-ppss-flush-cache t))
(setcar cell last)
(setcdr cell cache)))
))
@ -534,13 +534,14 @@ running the hook."
;; Setup the before-change function if necessary.
(unless (or ppss-cache ppss-last)
;; We should be either the very last function on
;; before-change-functions or the very first on
;; after-change-functions.
;; Note: combine-change-calls-1 needs to be kept in sync
;; with this!
(add-hook 'before-change-functions
'syntax-ppss-flush-cache t t))
#'syntax-ppss-flush-cache
;; We should be either the very last function on
;; before-change-functions or the very first on
;; after-change-functions.
99 t))
;; Use the best of OLD-POS and CACHE.
(if (or (not old-pos) (< old-pos pt-min))