diff options
| author | Andrew Schwartzmeyer | 2018-09-24 21:09:39 -0700 |
|---|---|---|
| committer | Eli Zaretskii | 2018-09-29 09:56:46 +0300 |
| commit | 48ff4c0b2f78f1812fa12e3a56ee5f2a0bc712f7 (patch) | |
| tree | 0572bf3bf14553e78dcbe58ffa3d0b8b754b4f04 | |
| parent | c973a0f15efe173671d82ac9a6ba67d5a592dc2e (diff) | |
| download | emacs-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/NEWS | 5 | ||||
| -rw-r--r-- | lisp/subr.el | 10 | ||||
| -rw-r--r-- | test/lisp/subr-tests.el | 12 |
3 files changed, 24 insertions, 3 deletions
| @@ -982,6 +982,11 @@ This works like 'dolist', but reports progress similar to | |||
| 982 | This works like 'delete-frame-functions', but runs after the frame to | 982 | This works like 'delete-frame-functions', but runs after the frame to |
| 983 | be deleted has been made dead and removed from the frame list. | 983 | be 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. | ||
| 987 | The function now returns non-nil when the argument MODE is derived | ||
| 988 | from any alias of any of MODES. | ||
| 989 | |||
| 985 | +++ | 990 | +++ |
| 986 | ** New frame focus state inspection interface. | 991 | ** New frame focus state inspection interface. |
| 987 | The hooks 'focus-in-hook' and 'focus-out-hook' are now obsolete. | 992 | The 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. |
| 1922 | Uses the `derived-mode-parent' property of the symbol to trace backwards. | 1922 | Uses the `derived-mode-parent' property of the symbol to trace backwards. |
| 1923 | If you just want to check `major-mode', use `derived-mode-p'." | 1923 | If 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)) |