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.
This commit is contained in:
Noam Postavsky 2015-10-11 12:40:17 -04:00
parent 00b84ceaf4
commit e56aa6f7b3

View File

@ -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.")