Last active
September 21, 2018 06:46
-
-
Save andyleejordan/075c113ea56117d60f6a3457e9d5674c to your computer and use it in GitHub Desktop.
Make `provided-mode-derived-p` support `defalias` parents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Fixed to support `(defalias 'my-parent-mode ...)` | |
(defun provided-mode-derived-p (mode &rest modes) | |
"Non-nil if MODE is derived from one of MODES. | |
Uses the `derived-mode-parent' property of the symbol to trace backwards. | |
If you just want to check `major-mode', use `derived-mode-p'." | |
(while (and (not (memq mode modes)) | |
(let ((parent (get mode 'derived-mode-parent))) | |
(let ((parentfn (symbol-function parent))) | |
(setq mode (if (and parentfn (symbolp parentfn)) | |
parentfn | |
parent)))))) | |
mode) | |
;; Broken behavior (seen in cmake-mode.el and groovy-mode.el): | |
(defalias 'alias-parent-mode | |
(if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode)) | |
(define-derived-mode alias-mode alias-parent-mode "Test") | |
(message "Aliased derived: %s" | |
(provided-mode-derived-p 'alias-mode 'prog-mode)) | |
;; Existing working behavior: | |
(define-derived-mode test-mode prog-mode "Test") | |
(message "Directly derived: %s" | |
(provided-mode-derived-p 'test-mode 'prog-mode)) | |
;; Original from subr.el: | |
;; (defun provided-mode-derived-p (mode &rest modes) | |
;; "Non-nil if MODE is derived from one of MODES. | |
;; Uses the `derived-mode-parent' property of the symbol to trace backwards. | |
;; If you just want to check `major-mode', use `derived-mode-p'." | |
;; (while (and (not (memq mode modes)) | |
;; (setq mode (get mode 'derived-mode-parent)))) | |
;; mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment