summaryrefslogtreecommitdiff
path: root/test/lisp/subr-tests.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 /test/lisp/subr-tests.el
parent49cdbb4a35f8d1d2139e8469bffcf33f65679094 (diff)
downloademacs-fe0cb43fb80db52a79ef898f8de49560cc5cdd90.tar.gz
emacs-fe0cb43fb80db52a79ef898f8de49560cc5cdd90.tar.bz2
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 'test/lisp/subr-tests.el')
-rw-r--r--test/lisp/subr-tests.el33
1 files changed, 30 insertions, 3 deletions
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index c458eef2f93..06db8f5c902 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -61,6 +61,9 @@
(quote
(0 font-lock-keyword-face))))))))
+(defalias 'subr-tests--parent-mode
+ (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
+
(ert-deftest provided-mode-derived-p ()
;; base case: `derived-mode' directly derives `prog-mode'
(should (progn
@@ -68,9 +71,7 @@
(provided-mode-derived-p 'derived-mode 'prog-mode)))
;; edge case: `derived-mode' derives an alias of `prog-mode'
(should (progn
- (defalias 'parent-mode
- (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
- (define-derived-mode derived-mode parent-mode "test")
+ (define-derived-mode derived-mode subr-tests--parent-mode "test")
(provided-mode-derived-p 'derived-mode 'prog-mode))))
(ert-deftest number-sequence-test ()
@@ -373,5 +374,31 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
(should (equal (flatten-tree '(1 ("foo" "bar") 2))
'(1 "foo" "bar" 2))))
+(defvar subr-tests--hook nil)
+
+(ert-deftest subr-tests-add-hook-depth ()
+ "Test the `depth' arg of `add-hook'."
+ (setq-default subr-tests--hook nil)
+ (add-hook 'subr-tests--hook 'f1)
+ (add-hook 'subr-tests--hook 'f2)
+ (should (equal subr-tests--hook '(f2 f1)))
+ (add-hook 'subr-tests--hook 'f3 t)
+ (should (equal subr-tests--hook '(f2 f1 f3)))
+ (add-hook 'subr-tests--hook 'f4 50)
+ (should (equal subr-tests--hook '(f2 f1 f4 f3)))
+ (add-hook 'subr-tests--hook 'f5 -50)
+ (should (equal subr-tests--hook '(f5 f2 f1 f4 f3)))
+ (add-hook 'subr-tests--hook 'f6)
+ (should (equal subr-tests--hook '(f5 f6 f2 f1 f4 f3)))
+ ;; Make sure `t' is equivalent to 90.
+ (add-hook 'subr-tests--hook 'f7 90)
+ (add-hook 'subr-tests--hook 'f8 t)
+ (should (equal subr-tests--hook '(f5 f6 f2 f1 f4 f3 f7 f8)))
+ ;; Make sue `nil' is equivalent to 0.
+ (add-hook 'subr-tests--hook 'f9 0)
+ (add-hook 'subr-tests--hook 'f10)
+ (should (equal subr-tests--hook '(f5 f10 f9 f6 f2 f1 f4 f3 f7 f8)))
+ )
+
(provide 'subr-tests)
;;; subr-tests.el ends here