This commit is contained in:
João Távora 2012-11-06 15:52:33 +00:00
parent 9de1c5f4fb
commit 185c771ded
2 changed files with 40 additions and 24 deletions

View File

@ -257,23 +257,34 @@ TODO: correct this bug!"
;;; Loading ;;; 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) (defmacro yas-with-some-interesting-snippet-dirs (&rest body)
`(yas-saving-variables `(yas-saving-variables
(yas-with-snippet-dirs (yas-with-overriden-buffer-list
'((".emacs.d/snippets" (yas-with-snippet-dirs
("c-mode" '((".emacs.d/snippets"
(".yas-parents" . "cc-mode") ("c-mode"
("printf" . "printf($1);")) ;; notice the overriding for issue #281 (".yas-parents" . "cc-mode")
("emacs-lisp-mode" ("ert-deftest" . "(ert-deftest ${1:name} () $0)")) ("printf" . "printf($1);")) ;; notice the overriding for issue #281
("lisp-interaction-mode" (".yas-parents" . "emacs-lisp-mode"))) ("emacs-lisp-mode" ("ert-deftest" . "(ert-deftest ${1:name} () $0)"))
("library/snippets" ("lisp-interaction-mode" (".yas-parents" . "emacs-lisp-mode")))
("c-mode" ("library/snippets"
(".yas-parents" . "c++-mode") ("c-mode"
("printf" . "printf")) (".yas-parents" . "c++-mode")
("cc-mode" ("def" . "# define")) ("printf" . "printf"))
("emacs-lisp-mode" ("dolist" . "(dolist)")) ("cc-mode" ("def" . "# define"))
("lisp-interaction-mode" ("sc" . "brother from another mother")))) ("emacs-lisp-mode" ("dolist" . "(dolist)"))
,@body))) ("lisp-interaction-mode" ("sc" . "brother from another mother"))))
,@body))))
(ert-deftest basic-jit-loading () (ert-deftest basic-jit-loading ()
"Test basic loading and expansion of snippets" "Test basic loading and expansion of snippets"

View File

@ -1629,7 +1629,13 @@ Optional USE-JIT use jit-loading of snippets."
(let ((form `(yas--load-directory-1 ,dir (let ((form `(yas--load-directory-1 ,dir
',mode-sym ',mode-sym
',parents))) ',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) (yas--schedule-jit mode-sym form)
(eval form))))) (eval form)))))
(when (interactive-p) (when (interactive-p)
@ -1737,14 +1743,13 @@ loading."
(if errors " (some errors, check *Messages*)" ""))))) (if errors " (some errors, check *Messages*)" "")))))
(defun yas--load-pending-jits () (defun yas--load-pending-jits ()
(when yas-minor-mode (dolist (mode (yas--modes-to-activate))
(dolist (mode (yas--modes-to-activate)) (let ((forms (reverse (gethash mode yas--scheduled-jit-loads))))
(let ((forms (reverse (gethash mode yas--scheduled-jit-loads)))) ;; must reverse to maintain coherence with `yas-snippet-dirs'
;; must reverse to maintain coherence with `yas-snippet-dirs' (dolist (form forms)
(dolist (form forms) (yas--message 3 "Loading for `%s', just-in-time: %s!" mode form)
(yas--message 3 "Loading for `%s', just-in-time: %s!" mode form) (eval form))
(eval form)) (remhash mode yas--scheduled-jit-loads))))
(remhash mode yas--scheduled-jit-loads)))))
;; (when (<= emacs-major-version 22) ;; (when (<= emacs-major-version 22)
;; (add-hook 'after-change-major-mode-hook 'yas--load-pending-jits)) ;; (add-hook 'after-change-major-mode-hook 'yas--load-pending-jits))