(funcall ,saved-sym))))
,@body))))
+
(defmacro yas-with-some-interesting-snippet-dirs (&rest body)
`(yas-saving-variables
(yas-with-overriden-buffer-list
("lisp-interaction-mode" ("sc" . "brother from another mother"))))
,@body))))
+
(ert-deftest basic-jit-loading ()
"Test basic loading and expansion of snippets"
(yas-with-some-interesting-snippet-dirs
("c-mode"
(".yas-parents" . "cc-mode"))
("cc-mode"
- (".yas-parents" . "yet-another-c-mode"))
+ (".yas-parents" . "yet-another-c-mode and-that-one"))
("yet-another-c-mode"
- (".yas-parents" . "c-mode"))))
+ (".yas-parents" . "c-mode and-also-this-one lisp-interaction-mode"))))
(yas-reload-all)
- (condition-case nil
- (yas--all-parents 'c-mode)
- (error
- (ert-fail "cyclic parenthood test failed"))))))
+ (with-temp-buffer
+ (let* ((major-mode 'c-mode)
+ (expected '(c-mode
+ cc-mode
+ yet-another-c-mode
+ and-also-this-one
+ and-that-one
+ 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))))))))
(defun yas--basic-jit-loading-1 ()
(with-temp-buffer
;; `yas-snippet-dirs' and is used for deciding which
;; snippets to consider for the active buffer.
;;
-;; Deprecated `yas/mode-symbol' aliases this variable for
-;; backward-compatibility.
-;;
;; Major commands are:
;;
;; M-x yas-expand
`derived-mode-parent' property of some mode symbols, but that is
not recorded here.")
-(defvar yas--ancestors (make-hash-table)
- "A hash table of mode symbols do lists of all parent mode symbols.
-
-A cache managed by `yas--all-parents'")
-
(defvar yas--direct-keymaps (list)
"Keymap alist supporting direct snippet keybindings.
(defun yas--modes-to-activate ()
"Compute list of mode symbols that are active for `yas-expand'
and friends."
- (let ((modes-to-activate (list major-mode))
- (mode major-mode))
- (while (setq mode (get mode 'derived-mode-parent))
- (push mode modes-to-activate))
- (dolist (mode (yas-extra-modes))
- (push mode modes-to-activate))
- (remove-duplicates
- (append modes-to-activate
- (mapcan #'(lambda (mode)
- (yas--all-parents mode))
- modes-to-activate)))))
+ (cl-labels
+ ((dfs (mode &optional explored)
+ (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)
+ append (dfs neighbour explored)))))
+ (remove-duplicates (append yas-extra-modes
+ (dfs major-mode)))))
(defvar yas-minor-mode-hook nil
"Hook run when `yas-minor-mode' is turned on.")
(t
(eq requirement result)))))
-(defun yas--all-parents (mode)
- "Return a list of all parent modes of MODE."
- (or (gethash mode yas--ancestors)
- (let ((seen '()))
- (labels ((yas--all-parents-1
- (m)
- (cond ((memq m seen)
- (yas--message 1
- "Cyclic parenthood: mode %s has already seen as a parent of mode %s"
- m mode)
- nil)
- (t
- (let* ((parents (gethash m yas--parents)))
- (setq seen (append seen parents))
- (append parents (mapcan #'yas--all-parents-1 parents)))))))
- (puthash mode (yas--all-parents-1 mode)
- yas--ancestors)))))
-
(defun yas--table-templates (table)
(when table
(let ((acc (list)))
This variable probably makes more sense as buffer-local, so
ensure your use `make-local-variable' when you set it.")
-(defun yas-extra-modes ()
- (if (listp yas-extra-modes) yas-extra-modes (list yas-extra-modes)))
-(defvaralias 'yas/mode-symbol 'yas-extra-modes)
(defun yas--table-get-create (mode)
"Get or create the snippet table corresponding to MODE."