[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master cd05da6 36/60: Activate extra and major modes first
From: |
João Távora |
Subject: |
[elpa] master cd05da6 36/60: Activate extra and major modes first |
Date: |
Thu, 21 Jan 2016 22:36:01 +0000 |
branch: master
commit cd05da61f9a6155f5ad3e284320daa6b5c73e011
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Activate extra and major modes first
This prevents snippets from a parent mode from overriding those of the
major-mode's (or yas--extra-modes). Snippets of ancestor modes may
still override snippets of some other ancestor modes, but hopefully this
won't cause much trouble in practice.
See [1] and subsequent comments.
[1]:
https://github.com/capitaomorte/yasnippet/issues/619#issuecomment-149127150
* yasnippet.el (yas--modes-to-activate): Reverse result, so that parents
of yas--extra-modes and major are later in the list.
* yasnippet-tests.el (loading-with-cyclic-parenthood)
(extra-modes-parenthood): Test it.
Close #626.
---
yasnippet-tests.el | 34 +++++++++++++++++++---------------
yasnippet.el | 31 +++++++++++++++----------------
2 files changed, 34 insertions(+), 31 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 4756571..52f0c39 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -497,6 +497,7 @@ TODO: correct this bug!"
emacs-lisp-mode
lisp-interaction-mode))
(observed (yas--modes-to-activate)))
+ (should (equal major-mode (car observed)))
(should (equal (sort expected #'string<) (sort observed
#'string<))))))))
(ert-deftest extra-modes-parenthood ()
@@ -505,26 +506,29 @@ TODO: correct this bug!"
(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))
+ (yas-activate-extra-mode 'c-mode)
+ (yas-activate-extra-mode 'yet-another-c-mode)
+ (yas-activate-extra-mode 'and-that-one)
+ (let* ((expected-first `(and-that-one
+ yet-another-c-mode
+ c-mode
+ ,major-mode))
+ (expected-rest `(cc-mode
+ ;; prog-mode doesn't exist in emacs 24.3
+ ,@(if (fboundp 'prog-mode)
+ '(prog-mode))
+ emacs-lisp-mode
+ and-also-this-one
+ lisp-interaction-mode))
(observed (yas--modes-to-activate)))
- (should (equal (sort expected #'string<) (sort observed
#'string<))))))))
+ (should (equal expected-first
+ (cl-subseq observed 0 (length expected-first))))
+ (should (equal (sort expected-rest #'string<)
+ (sort (cl-subseq observed (length expected-first))
#'string<))))))))
(ert-deftest issue-492-and-494 ()
(defalias 'yas--phony-c-mode 'c-mode)
diff --git a/yasnippet.el b/yasnippet.el
index facb2b6..4f06a48 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -728,22 +728,21 @@ 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 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
- (funcall dfs mode)
- (mapcar dfs (cons major-mode yas--extra-modes)))
- explored))
+ (let* ((explored (if mode (list mode) ; Building up list in reverse.
+ (cons major-mode (reverse yas--extra-modes))))
+ (dfs
+ (lambda (mode)
+ (cl-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 (push neighbour explored)
+ (funcall dfs neighbour)))))
+ (mapcar dfs explored)
+ (nreverse explored)))
(defvar yas-minor-mode-hook nil
"Hook run when `yas-minor-mode' is turned on.")
- [elpa] master 6c46878 43/60: Fix #587; set `this-command' on fallback., (continued)
- [elpa] master 6c46878 43/60: Fix #587; set `this-command' on fallback., João Távora, 2016/01/21
- [elpa] master 23ee54e 44/60: Use destructive list functions in yas--s-a-p, João Távora, 2016/01/21
- [elpa] master 3aa7cb2 40/60: M-x delete-trailing-whitespace, João Távora, 2016/01/21
- [elpa] master d78181a 46/60: Remove yas--inhibit-overlay-hooks macro., João Távora, 2016/01/21
- [elpa] master 17fe790 51/60: Fix #515; only clear field on self-insert, João Távora, 2016/01/21
- [elpa] master 67a45a6 48/60: * README.mdown: Add link to textmate-to-yas.el., João Távora, 2016/01/21
- [elpa] master c80fbf2 49/60: Cleanup yas--on-field-overlay-modification, João Távora, 2016/01/21
- [elpa] master 444c882 47/60: * README.mdown: update melpa URL., João Távora, 2016/01/21
- [elpa] master 61261c9 53/60: Fix #576; don't override yas-prompt-functions, João Távora, 2016/01/21
- [elpa] master a2c5292 55/60: Bless Noam Postavsky as the new official maintainer, João Távora, 2016/01/21
- [elpa] master cd05da6 36/60: Activate extra and major modes first,
João Távora <=
- [elpa] master 3cd64b7 45/60: yasnippet.el (yas--called-interactively-p): Remove., João Távora, 2016/01/21
- [elpa] master 140c415 52/60: Respect y-b-l-cond from binding triggered snippets, João Távora, 2016/01/21
- [elpa] master 71f0142 50/60: Improve test simulatulation of self-insert, João Távora, 2016/01/21
- [elpa] master e6fff09 54/60: Don't choose ido prompting based on Emacs version, João Távora, 2016/01/21
- [elpa] master af90528 56/60: Fix debugging code for newer Emacsen, João Távora, 2016/01/21
- [elpa] master 100d8d1 57/60: Fix bug reporting examples., João Távora, 2016/01/21
- [elpa] master 46256db 58/60: Fix #648; create ~/.emacs.d/snippets automatically, João Távora, 2016/01/21
- [elpa] master 1a98c38 59/60: Fix silly mistake in previous commit, João Távora, 2016/01/21
- [elpa] master 5817fe1 60/60: Update packages/yasnippet by subtree-merging from its external upstream, João Távora, 2016/01/21