bugfix: better with-snippet-dirs macro

This commit is contained in:
João Távora 2012-06-30 20:00:11 +01:00
parent 275ac7fe00
commit b347b61360

View File

@ -205,10 +205,9 @@ TODO: correct this bug!"
(let ((default-directory (concat default-directory "/" file-or-dir-name))) (let ((default-directory (concat default-directory "/" file-or-dir-name)))
(mapc #'yas/make-file-or-dirs content))) (mapc #'yas/make-file-or-dirs content)))
((stringp content) ((stringp content)
(with-current-buffer (find-file file-or-dir-name) (with-temp-buffer
(insert content) (insert content)
(save-buffer) (write-region nil nil file-or-dir-name nil 'nomessage)))
(kill-buffer (current-buffer))))
(t (t
(message "[yas] oops don't know this content"))))) (message "[yas] oops don't know this content")))))
@ -228,15 +227,22 @@ TODO: correct this bug!"
(yas/variables)) (yas/variables))
,@body)) ,@body))
(defun yas/call-with-snippet-dirs (dirs fn)
(let ((default-directory (make-temp-file "yasnippet-fixture" t))
(message-log-max nil)
(yas/snippet-dirs (mapcar #'car (cadr dirs))))
(with-temp-message ""
(unwind-protect
(progn
(mapc #'yas/make-file-or-dirs dirs)
(funcall fn))
(when (>= emacs-major-version 23)
(delete-directory default-directory 'recursive))))))
(defmacro with-snippet-dirs (dirs &rest body) (defmacro with-snippet-dirs (dirs &rest body)
`(let ((default-directory (make-temp-file "yasnippet-fixture" t))) `(yas/call-with-snippet-dirs ,dirs
(unwind-protect #'(lambda ()
(progn ,@body)))
(setq yas/snippet-dirs ',(mapcar #'car (cadr dirs)))
(mapc #'yas/make-file-or-dirs ,dirs)
,@body)
(when (>= emacs-major-version 23)
(delete-directory default-directory 'recursive)))))
;;; Older emacsen ;;; Older emacsen
;;; ;;;