From 00b84ceaf484adadbf60e1457eef9292395ca6be Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 11 Oct 2015 12:25:20 -0400 Subject: [PATCH 1/3] Add (failing) yas--modes-to-activate test * yasnippet-tests.el (extra-modes-parenthood): New (failing) test. (loading-with-cyclic-parenthood): Use equal + sort instead of set operation + length. --- yasnippet-tests.el | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/yasnippet-tests.el b/yasnippet-tests.el index fbf79f8..4756571 100644 --- a/yasnippet-tests.el +++ b/yasnippet-tests.el @@ -491,15 +491,40 @@ TODO: correct this bug!" yet-another-c-mode and-also-this-one and-that-one - ;; prog-mode doesn't exit in emacs 24.3 + ;; prog-mode doesn't exist in emacs 24.3 ,@(if (fboundp 'prog-mode) '(prog-mode)) emacs-lisp-mode lisp-interaction-mode)) (observed (yas--modes-to-activate))) - (should (null (cl-set-exclusive-or expected observed))) - (should (= (length expected) - (length observed)))))))) + (should (equal (sort expected #'string<) (sort observed #'string<)))))))) + +(ert-deftest extra-modes-parenthood () + "Test activation of parents of `yas--extra-modes'." + (yas-saving-variables + (yas-with-snippet-dirs '((".emacs.d/snippets" + ("c-mode" + (".yas-parents" . "cc-mode")) + ("cc-mode" + (".yas-parents" . "yet-another-c-mode and-that-one")) + ("yet-another-c-mode" + (".yas-parents" . "c-mode and-also-this-one lisp-interaction-mode")))) + (yas-reload-all) + (with-temp-buffer + (let* ((_ (yas-activate-extra-mode 'c-mode)) + (expected `(,major-mode + c-mode + cc-mode + yet-another-c-mode + and-also-this-one + and-that-one + ;; prog-mode doesn't exist in emacs 24.3 + ,@(if (fboundp 'prog-mode) + '(prog-mode)) + emacs-lisp-mode + lisp-interaction-mode)) + (observed (yas--modes-to-activate))) + (should (equal (sort expected #'string<) (sort observed #'string<)))))))) (ert-deftest issue-492-and-494 () (defalias 'yas--phony-c-mode 'c-mode) From e56aa6f7b335e34788f479cc5816f4789ed45b9c Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 11 Oct 2015 12:40:17 -0400 Subject: [PATCH 2/3] Build a single `explored' list. * yasnippet.el (yas--modes-to-activate): Make helper dfs function produce the list of modes only by updating a single `explored' list, instead of building up the list by value and having to remove duplicated after. --- yasnippet.el | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/yasnippet.el b/yasnippet.el index 1311cd0..c38b9db 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -728,22 +728,23 @@ defined direct keybindings to the command (defun yas--modes-to-activate (&optional mode) "Compute list of mode symbols that are active for `yas-expand' and friends." - (let (dfs) - (setq dfs (lambda (mode &optional explored) - (push mode explored) - (cons mode - (loop for neighbour - 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 (if mode - (funcall dfs mode) - (append yas--extra-modes - (funcall dfs major-mode)))))) + (let (dfs explored) + (setq dfs (lambda (mode) + (unless (memq mode explored) + (push mode explored) + (loop for neighbour + 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)) + do (funcall dfs neighbour))))) + (if mode + (progn (funcall dfs mode) + explored) + (funcall dfs major-mode) + (append yas--extra-modes explored)))) (defvar yas-minor-mode-hook nil "Hook run when `yas-minor-mode' is turned on.") From fb6ec6722827b812a2e8bed85378a06d234cdd56 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 11 Oct 2015 12:55:47 -0400 Subject: [PATCH 3/3] Fix #619; find parents for extra-modes too * yasnippet.el (yas--modes-to-activate): Call dfs on yas--extra-modes as well. --- yasnippet.el | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/yasnippet.el b/yasnippet.el index c38b9db..a119011 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -741,10 +741,9 @@ and friends." (symbolp neighbour)) do (funcall dfs neighbour))))) (if mode - (progn (funcall dfs mode) - explored) - (funcall dfs major-mode) - (append yas--extra-modes explored)))) + (funcall dfs mode) + (mapcar dfs (cons major-mode yas--extra-modes))) + explored)) (defvar yas-minor-mode-hook nil "Hook run when `yas-minor-mode' is turned on.")