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

@ -20,7 +20,7 @@
;;; Commentary: ;;; Commentary:
;; Test basic snippet mechanics and the loading system ;; Test basic snippet mechanics and the loading system
;;; Code: ;;; Code:
@ -38,7 +38,7 @@
(yas/expand-snippet "${1:brother} from another ${2:mother}") (yas/expand-snippet "${1:brother} from another ${2:mother}")
(should (string= (buffer-substring-no-properties (point-min) (point-max)) (should (string= (buffer-substring-no-properties (point-min) (point-max))
"brother from another mother")) "brother from another mother"))
(should (looking-at "brother")) (should (looking-at "brother"))
(ert-simulate-command '(yas/next-field-or-maybe-expand)) (ert-simulate-command '(yas/next-field-or-maybe-expand))
(should (looking-at "mother")) (should (looking-at "mother"))
@ -96,7 +96,7 @@
;;; Misc tests ;;; Misc tests
;;; ;;;
(ert-deftest protection-overlay-no-cheating () (ert-deftest protection-overlay-no-cheating ()
"Protection overlays at the very end of the buffer, are dealt by cheatingly inserting a newline! "Protection overlays at the very end of the buffer, are dealt by cheatingly inserting a newline!
@ -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
;;; ;;;