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
;;;
(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"

View File

@ -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))