mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
Merge pull request #621 from npostavs/dfs-extra-modes2
find parents for extra-modes too (v2)
This commit is contained in:
commit
ac3fe83247
@ -491,15 +491,40 @@ TODO: correct this bug!"
|
|||||||
yet-another-c-mode
|
yet-another-c-mode
|
||||||
and-also-this-one
|
and-also-this-one
|
||||||
and-that-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)
|
,@(if (fboundp 'prog-mode)
|
||||||
'(prog-mode))
|
'(prog-mode))
|
||||||
emacs-lisp-mode
|
emacs-lisp-mode
|
||||||
lisp-interaction-mode))
|
lisp-interaction-mode))
|
||||||
(observed (yas--modes-to-activate)))
|
(observed (yas--modes-to-activate)))
|
||||||
(should (null (cl-set-exclusive-or expected observed)))
|
(should (equal (sort expected #'string<) (sort observed #'string<))))))))
|
||||||
(should (= (length expected)
|
|
||||||
(length observed))))))))
|
(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 ()
|
(ert-deftest issue-492-and-494 ()
|
||||||
(defalias 'yas--phony-c-mode 'c-mode)
|
(defalias 'yas--phony-c-mode 'c-mode)
|
||||||
|
32
yasnippet.el
32
yasnippet.el
@ -728,22 +728,22 @@ defined direct keybindings to the command
|
|||||||
(defun yas--modes-to-activate (&optional mode)
|
(defun yas--modes-to-activate (&optional mode)
|
||||||
"Compute list of mode symbols that are active for `yas-expand'
|
"Compute list of mode symbols that are active for `yas-expand'
|
||||||
and friends."
|
and friends."
|
||||||
(let (dfs)
|
(let (dfs explored)
|
||||||
(setq dfs (lambda (mode &optional explored)
|
(setq dfs (lambda (mode)
|
||||||
(push mode explored)
|
(unless (memq mode explored)
|
||||||
(cons mode
|
(push mode explored)
|
||||||
(loop for neighbour
|
(loop for neighbour
|
||||||
in (cl-list* (get mode 'derived-mode-parent)
|
in (cl-list* (get mode 'derived-mode-parent)
|
||||||
(ignore-errors (symbol-function mode))
|
(ignore-errors (symbol-function mode))
|
||||||
(gethash mode yas--parents))
|
(gethash mode yas--parents))
|
||||||
when (and neighbour
|
when (and neighbour
|
||||||
(not (memq neighbour explored))
|
(not (memq neighbour explored))
|
||||||
(symbolp neighbour))
|
(symbolp neighbour))
|
||||||
append (funcall dfs neighbour explored)))))
|
do (funcall dfs neighbour)))))
|
||||||
(remove-duplicates (if mode
|
(if mode
|
||||||
(funcall dfs mode)
|
(funcall dfs mode)
|
||||||
(append yas--extra-modes
|
(mapcar dfs (cons major-mode yas--extra-modes)))
|
||||||
(funcall dfs major-mode))))))
|
explored))
|
||||||
|
|
||||||
(defvar yas-minor-mode-hook nil
|
(defvar yas-minor-mode-hook nil
|
||||||
"Hook run when `yas-minor-mode' is turned on.")
|
"Hook run when `yas-minor-mode' is turned on.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user