branch: master
commit 0b7b34a333ff5fbb279f57980d6cc983e9a5d8c9
Author: João Távora <[email protected]>
Commit: João Távora <[email protected]>
Closes #492, closes #494: Consider defalias when calculating parent modes
* yasnippet-tests.el (issue-492-and-494): New test.
* yasnippet.el (yas--modes-to-activate): Consider each mode's
symbol-function as a neighbour in case it's a symbol as well.
---
yasnippet-tests.el | 18 ++++++++++++++++++
yasnippet.el | 11 ++++++-----
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index c6b878d..38aefc1 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -426,6 +426,24 @@ TODO: correct this bug!"
(should (= (length expected)
(length observed))))))))
+(ert-deftest issue-492-and-494 ()
+ (defalias 'yas--phony-c-mode 'c-mode)
+ (define-derived-mode yas--test-mode yas--phony-c-mode "Just a test mode")
+ (yas-with-snippet-dirs '((".emacs.d/snippets"
+ ("yas--test-mode")))
+ (yas-reload-all)
+ (with-temp-buffer
+ (let* ((major-mode 'yas--test-mode)
+ (expected `(c-mode
+ ,@(if (fboundp 'prog-mode)
+ '(prog-mode))
+ yas--phony-c-mode
+ yas--test-mode))
+ (observed (yas--modes-to-activate)))
+ (should (null (cl-set-exclusive-or expected
observed)))
+ (should (= (length expected)
+ (length observed)))))))
+
(defun yas--basic-jit-loading-1 ()
(with-temp-buffer
(should (= 4 (hash-table-count yas--scheduled-jit-loads)))
diff --git a/yasnippet.el b/yasnippet.el
index d0129b9..39b4c0e 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -699,11 +699,12 @@ and friends."
(push mode explored)
(cons mode
(loop for neighbour
- in (remove nil (cons (get mode
- 'derived-mode-parent)
- (gethash mode yas--parents)))
-
- unless (memq neighbour explored)
+ in (cl-list* (get mode 'derived-mode-parent)
+ (ignore-errors (symbol-function mode))
+ (gethash mode yas--parents))
+ when (and neighbour
+ (not (memq neighbour explored))
+ (symbolp neighbour))
append (funcall dfs neighbour explored)))))
(remove-duplicates (append yas--extra-modes
(funcall dfs major-mode)))))