branch: master commit dabc71992158b749f7b7e745908a51a7011a117d Author: Noam Postavsky <npost...@users.sourceforge.net> Commit: Noam Postavsky <npost...@users.sourceforge.net>
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. --- yasnippet-tests.el | 4 ++-- yasnippet.el | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/yasnippet-tests.el b/yasnippet-tests.el index 064d6c9..9434ff7 100644 --- a/yasnippet-tests.el +++ b/yasnippet-tests.el @@ -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_ "))) diff --git a/yasnippet.el b/yasnippet.el index 065e709..d457afd 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -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.