1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-05 22:20:24 -08:00

* 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

@ -246,7 +246,7 @@ functions when `parse-sexp-lookup-properties' is non-nil. The
cache is flushed from position START, defaulting to point."
(declare (debug ((form &optional form) body)) (indent 1))
(let ((start-var (make-symbol "start")))
`(let ((syntax-propertize-function nil)
`(let ((syntax-propertize-function #'ignore)
(,start-var ,(or start '(point))))
(unwind-protect
(with-syntax-table ,table
@ -564,13 +564,6 @@ happened."
(matching-paren (char-after))))
(save-excursion (newline 1 t)))))))
;; Prioritize this to kick in after
;; `electric-layout-post-self-insert-function': that considerably
;; simplifies interoperation when `electric-pair-mode',
;; `electric-layout-mode' and `electric-indent-mode' are used
;; together. Use `vc-region-history' on these lines for more info.
(put 'electric-pair-post-self-insert-function 'priority 50)
(defun electric-pair-will-use-region ()
(and (use-region-p)
(memq (car (electric-pair-syntax-info last-command-event))
@ -622,8 +615,14 @@ To toggle the mode in a single buffer, use `electric-pair-local-mode'."
(if electric-pair-mode
(progn
(add-hook 'post-self-insert-hook
#'electric-pair-post-self-insert-function)
(electric--sort-post-self-insertion-hook)
#'electric-pair-post-self-insert-function
;; Prioritize this to kick in after
;; `electric-layout-post-self-insert-function': that
;; considerably simplifies interoperation when
;; `electric-pair-mode', `electric-layout-mode' and
;; `electric-indent-mode' are used together.
;; Use `vc-region-history' on these lines for more info.
50)
(add-hook 'self-insert-uses-region-functions
#'electric-pair-will-use-region))
(remove-hook 'post-self-insert-hook