Don't turn on yas-minor-mode in temp buffers

Generally, the user won't be interacting with, or creating snippets in
temporary buffers.
* yasnippet.el (yas-temp-buffer-p): New function.
(yas-dont-activate-functions): Add it to default value.
* yasnippet-tests.el (complicated-yas-key-syntaxes)
(test-yas-activate-extra-modes): Call yas-minor-mode instead of
yas-minor-mode-on, to ensure activation.
This commit is contained in:
Noam Postavsky 2019-03-31 19:52:47 -04:00
parent 8b25d627a4
commit dabc719921
2 changed files with 6 additions and 3 deletions

View File

@ -998,7 +998,7 @@ hello ${1:$(when (stringp yas-text) (funcall func yas-text))} foo${1:$$(concat \
("'quote" . "OKquoteOK"))))
(yas-reload-all)
(emacs-lisp-mode)
(yas-minor-mode-on)
(yas-minor-mode +1)
(let ((yas-key-syntaxes '("w" "w_")))
(let ((yas--barbaz t))
(yas-should-expand '(("foo-barbaz" . "foo-OKbarbazOK")
@ -1620,7 +1620,7 @@ add the snippets associated with the given mode."
("car" . "(car )"))))
(yas-reload-all)
(emacs-lisp-mode)
(yas-minor-mode-on)
(yas-minor-mode +1)
(yas-activate-extra-mode 'markdown-mode)
(should (eq 'markdown-mode (car yas--extra-modes)))
(yas-should-expand '(("_" . "_Text_ ")))

View File

@ -918,9 +918,12 @@ activate snippets associated with that mode."
(remove mode
yas--extra-modes)))
(defun yas-temp-buffer-p (&optional buffer)
(eq (aref (buffer-name buffer) 0) ?\s))
(define-obsolete-variable-alias 'yas-dont-activate
'yas-dont-activate-functions "0.9.2")
(defvar yas-dont-activate-functions (list #'minibufferp)
(defvar yas-dont-activate-functions (list #'minibufferp #'yas-temp-buffer-p)
"Special hook to control which buffers `yas-global-mode' affects.
Functions are called with no argument, and should return non-nil to prevent
`yas-global-mode' from enabling yasnippet in this buffer.