aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Schwartzmeyer2018-09-24 21:09:39 -0700
committerEli Zaretskii2018-09-29 09:56:46 +0300
commit48ff4c0b2f78f1812fa12e3a56ee5f2a0bc712f7 (patch)
tree0572bf3bf14553e78dcbe58ffa3d0b8b754b4f04
parentc973a0f15efe173671d82ac9a6ba67d5a592dc2e (diff)
downloademacs-48ff4c0b2f78f1812fa12e3a56ee5f2a0bc712f7.tar.gz
emacs-48ff4c0b2f78f1812fa12e3a56ee5f2a0bc712f7.zip
Support mode aliases in 'provided-mode-derived-p'
* lisp/subr.el (provided-mode-derived-p): Check aliases of MODES as well as MODES themselves. (Bug#32795) * test/lisp/subr-tests.el (provided-mode-derived-p): New test. Copyright-paperwork-exempt: yes
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/subr.el10
-rw-r--r--test/lisp/subr-tests.el12
3 files changed, 24 insertions, 3 deletions
diff --git a/etc/NEWS b/etc/NEWS
index e6508eb60bb..354072fc814 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -982,6 +982,11 @@ This works like 'dolist', but reports progress similar to
982This works like 'delete-frame-functions', but runs after the frame to 982This works like 'delete-frame-functions', but runs after the frame to
983be deleted has been made dead and removed from the frame list. 983be deleted has been made dead and removed from the frame list.
984 984
985---
986** The function 'provided-mode-derived-p' was extended to support aliases.
987The function now returns non-nil when the argument MODE is derived
988from any alias of any of MODES.
989
985+++ 990+++
986** New frame focus state inspection interface. 991** New frame focus state inspection interface.
987The hooks 'focus-in-hook' and 'focus-out-hook' are now obsolete. 992The hooks 'focus-in-hook' and 'focus-out-hook' are now obsolete.
diff --git a/lisp/subr.el b/lisp/subr.el
index 9e880bc880e..4c05111f516 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1918,11 +1918,15 @@ Only affects hooks run in the current buffer."
1918;; PUBLIC: find if the current mode derives from another. 1918;; PUBLIC: find if the current mode derives from another.
1919 1919
1920(defun provided-mode-derived-p (mode &rest modes) 1920(defun provided-mode-derived-p (mode &rest modes)
1921 "Non-nil if MODE is derived from one of MODES. 1921 "Non-nil if MODE is derived from one of MODES or their aliases.
1922Uses the `derived-mode-parent' property of the symbol to trace backwards. 1922Uses the `derived-mode-parent' property of the symbol to trace backwards.
1923If you just want to check `major-mode', use `derived-mode-p'." 1923If you just want to check `major-mode', use `derived-mode-p'."
1924 (while (and (not (memq mode modes)) 1924 (while
1925 (setq mode (get mode 'derived-mode-parent)))) 1925 (and
1926 (not (memq mode modes))
1927 (let* ((parent (get mode 'derived-mode-parent))
1928 (parentfn (symbol-function parent)))
1929 (setq mode (if (and parentfn (symbolp parentfn)) parentfn parent)))))
1926 mode) 1930 mode)
1927 1931
1928(defun derived-mode-p (&rest modes) 1932(defun derived-mode-p (&rest modes)
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 86938d5dbe0..f218a7663e0 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -61,6 +61,18 @@
61 (quote 61 (quote
62 (0 font-lock-keyword-face)))))))) 62 (0 font-lock-keyword-face))))))))
63 63
64(ert-deftest provided-mode-derived-p ()
65 ;; base case: `derived-mode' directly derives `prog-mode'
66 (should (progn
67 (define-derived-mode derived-mode prog-mode "test")
68 (provided-mode-derived-p 'derived-mode 'prog-mode)))
69 ;; edge case: `derived-mode' derives an alias of `prog-mode'
70 (should (progn
71 (defalias 'parent-mode
72 (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
73 (define-derived-mode derived-mode parent-mode "test")
74 (provided-mode-derived-p 'derived-mode 'prog-mode))))
75
64(ert-deftest number-sequence-test () 76(ert-deftest number-sequence-test ()
65 (should (= (length 77 (should (= (length
66 (number-sequence (1- most-positive-fixnum) most-positive-fixnum)) 78 (number-sequence (1- most-positive-fixnum) most-positive-fixnum))