summaryrefslogtreecommitdiff
path: root/lisp/electric.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2019-05-29 15:56:14 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2019-05-29 15:56:14 -0400
commitfe0cb43fb80db52a79ef898f8de49560cc5cdd90 (patch)
tree4825956db223eb96d69583e707cbf13a4d280789 /lisp/electric.el
parent49cdbb4a35f8d1d2139e8469bffcf33f65679094 (diff)
downloademacs-fe0cb43fb80db52a79ef898f8de49560cc5cdd90.tar.gz
* 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 'lisp/electric.el')
-rw-r--r--lisp/electric.el29
1 files changed, 6 insertions, 23 deletions
diff --git a/lisp/electric.el b/lisp/electric.el
index 07da2f1d9e7..53e53bd975c 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -190,17 +190,6 @@ Returns nil when we can't find this char."
(eq (char-before) last-command-event)))))
pos)))
-(defun electric--sort-post-self-insertion-hook ()
- "Ensure order of electric functions in `post-self-insertion-hook'.
-
-Hooks in this variable interact in non-trivial ways, so a
-relative order must be maintained within it."
- (setq-default post-self-insert-hook
- (sort (default-value 'post-self-insert-hook)
- #'(lambda (fn1 fn2)
- (< (or (if (symbolp fn1) (get fn1 'priority)) 0)
- (or (if (symbolp fn2) (get fn2 'priority)) 0))))))
-
;;; Electric indentation.
;; Autoloading variables is generally undesirable, but major modes
@@ -297,8 +286,6 @@ or comment."
(indent-according-to-mode)
(error (throw 'indent-error nil)))))))))
-(put 'electric-indent-post-self-insert-function 'priority 60)
-
(defun electric-indent-just-newline (arg)
"Insert just a newline, without any auto-indentation."
(interactive "*P")
@@ -341,8 +328,8 @@ use `electric-indent-local-mode'."
(remove-hook 'post-self-insert-hook
#'electric-indent-post-self-insert-function))
(add-hook 'post-self-insert-hook
- #'electric-indent-post-self-insert-function)
- (electric--sort-post-self-insertion-hook)))
+ #'electric-indent-post-self-insert-function
+ 60)))
;;;###autoload
(define-minor-mode electric-indent-local-mode
@@ -472,8 +459,6 @@ If multiple rules match, only first one is executed.")
('after-stay (save-excursion (funcall nl-after)))
('around (funcall nl-before) (funcall nl-after))))))))
-(put 'electric-layout-post-self-insert-function 'priority 40)
-
;;;###autoload
(define-minor-mode electric-layout-mode
"Automatically insert newlines around some chars.
@@ -482,8 +467,8 @@ The variable `electric-layout-rules' says when and how to insert newlines."
:global t :group 'electricity
(cond (electric-layout-mode
(add-hook 'post-self-insert-hook
- #'electric-layout-post-self-insert-function)
- (electric--sort-post-self-insertion-hook))
+ #'electric-layout-post-self-insert-function
+ 40))
(t
(remove-hook 'post-self-insert-hook
#'electric-layout-post-self-insert-function))))
@@ -623,8 +608,6 @@ This requotes when a quoting key is typed."
(replace-match (string q>>))
(setq last-command-event q>>))))))))))
-(put 'electric-quote-post-self-insert-function 'priority 10)
-
;;;###autoload
(define-minor-mode electric-quote-mode
"Toggle on-the-fly requoting (Electric Quote mode).
@@ -651,8 +634,8 @@ use `electric-quote-local-mode'."
(remove-hook 'post-self-insert-hook
#'electric-quote-post-self-insert-function))
(add-hook 'post-self-insert-hook
- #'electric-quote-post-self-insert-function)
- (electric--sort-post-self-insertion-hook)))
+ #'electric-quote-post-self-insert-function
+ 10)))
;;;###autoload
(define-minor-mode electric-quote-local-mode