mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 13:13:03 +00:00
Closes #253.
This commit is contained in:
parent
9de1c5f4fb
commit
185c771ded
@ -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"
|
||||
|
23
yasnippet.el
23
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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user