From 185c771dedea5c29fa18dc8d624674c3a62e8326 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Tue, 6 Nov 2012 15:52:33 +0000 Subject: [PATCH] Closes #253. --- yasnippet-tests.el | 41 ++++++++++++++++++++++++++--------------- yasnippet.el | 23 ++++++++++++++--------- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/yasnippet-tests.el b/yasnippet-tests.el index ca80346c0..388b7eafc 100644 --- a/yasnippet-tests.el +++ b/yasnippet-tests.el @@ -257,23 +257,34 @@ TODO: correct this bug!" ;;; Loading ;;; +(defmacro yas-with-overriden-buffer-list (&rest body) + (let ((saved-sym (gensym))) + `(let ((,saved-sym (symbol-function 'buffer-list))) + (flet ((buffer-list () + (remove-if #'(lambda (buf) + (with-current-buffer buf + (eq major-mode 'lisp-interaction-mode))) + (funcall ,saved-sym)))) + ,@body)))) + (defmacro yas-with-some-interesting-snippet-dirs (&rest body) `(yas-saving-variables - (yas-with-snippet-dirs - '((".emacs.d/snippets" - ("c-mode" - (".yas-parents" . "cc-mode") - ("printf" . "printf($1);")) ;; notice the overriding for issue #281 - ("emacs-lisp-mode" ("ert-deftest" . "(ert-deftest ${1:name} () $0)")) - ("lisp-interaction-mode" (".yas-parents" . "emacs-lisp-mode"))) - ("library/snippets" - ("c-mode" - (".yas-parents" . "c++-mode") - ("printf" . "printf")) - ("cc-mode" ("def" . "# define")) - ("emacs-lisp-mode" ("dolist" . "(dolist)")) - ("lisp-interaction-mode" ("sc" . "brother from another mother")))) - ,@body))) + (yas-with-overriden-buffer-list + (yas-with-snippet-dirs + '((".emacs.d/snippets" + ("c-mode" + (".yas-parents" . "cc-mode") + ("printf" . "printf($1);")) ;; notice the overriding for issue #281 + ("emacs-lisp-mode" ("ert-deftest" . "(ert-deftest ${1:name} () $0)")) + ("lisp-interaction-mode" (".yas-parents" . "emacs-lisp-mode"))) + ("library/snippets" + ("c-mode" + (".yas-parents" . "c++-mode") + ("printf" . "printf")) + ("cc-mode" ("def" . "# define")) + ("emacs-lisp-mode" ("dolist" . "(dolist)")) + ("lisp-interaction-mode" ("sc" . "brother from another mother")))) + ,@body)))) (ert-deftest basic-jit-loading () "Test basic loading and expansion of snippets" diff --git a/yasnippet.el b/yasnippet.el index 2acc3843b..cd944d2db 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -1629,7 +1629,13 @@ Optional USE-JIT use jit-loading of snippets." (let ((form `(yas--load-directory-1 ,dir ',mode-sym ',parents))) - (if use-jit + (if (and use-jit + (not (some #'(lambda (buffer) + (with-current-buffer buffer + (when (eq major-mode mode-sym) + (yas--message 3 "Discovered there was already %s in %s" buffer mode-sym) + t))) + (buffer-list)))) (yas--schedule-jit mode-sym form) (eval form))))) (when (interactive-p) @@ -1737,14 +1743,13 @@ loading." (if errors " (some errors, check *Messages*)" ""))))) (defun yas--load-pending-jits () - (when yas-minor-mode - (dolist (mode (yas--modes-to-activate)) - (let ((forms (reverse (gethash mode yas--scheduled-jit-loads)))) - ;; must reverse to maintain coherence with `yas-snippet-dirs' - (dolist (form forms) - (yas--message 3 "Loading for `%s', just-in-time: %s!" mode form) - (eval form)) - (remhash mode yas--scheduled-jit-loads))))) + (dolist (mode (yas--modes-to-activate)) + (let ((forms (reverse (gethash mode yas--scheduled-jit-loads)))) + ;; must reverse to maintain coherence with `yas-snippet-dirs' + (dolist (form forms) + (yas--message 3 "Loading for `%s', just-in-time: %s!" mode form) + (eval form)) + (remhash mode yas--scheduled-jit-loads)))) ;; (when (<= emacs-major-version 22) ;; (add-hook 'after-change-major-mode-hook 'yas--load-pending-jits)) -- 2.39.2