]> code.delx.au - gnu-emacs-elpa/commitdiff
bugfix: better `with-snippet-dirs` macro
authorJoão Távora <joaotavora@gmail.com>
Sat, 30 Jun 2012 19:00:11 +0000 (20:00 +0100)
committerJoão Távora <joaotavora@gmail.com>
Sat, 30 Jun 2012 19:00:11 +0000 (20:00 +0100)
yasnippet-tests.el

index 007d125e4b86991012f8a7fb25738604d8cc98d2..0c25da5d621167dca8474fe931c8fb0d66158dbf 100755 (executable)
@@ -20,7 +20,7 @@
 \r
 ;;; Commentary:\r
 \r
-;; Test basic snippet mechanics and the loading system \r
+;; Test basic snippet mechanics and the loading system\r
 \r
 ;;; Code:\r
 \r
@@ -38,7 +38,7 @@
     (yas/expand-snippet "${1:brother} from another ${2:mother}")\r
     (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
                      "brother from another mother"))\r
-    \r
+\r
     (should (looking-at "brother"))\r
     (ert-simulate-command '(yas/next-field-or-maybe-expand))\r
     (should (looking-at "mother"))\r
@@ -96,7 +96,7 @@
 \r
 \r
 ;;; Misc tests\r
-;;; \r
+;;;\r
 \r
 (ert-deftest protection-overlay-no-cheating ()\r
   "Protection overlays at the very end of the buffer, are dealt by cheatingly inserting a newline!\r
@@ -205,10 +205,9 @@ TODO: correct this bug!"
            (let ((default-directory (concat default-directory "/" file-or-dir-name)))\r
              (mapc #'yas/make-file-or-dirs content)))\r
           ((stringp content)\r
-           (with-current-buffer (find-file file-or-dir-name)\r
+           (with-temp-buffer\r
              (insert content)\r
-             (save-buffer)\r
-             (kill-buffer (current-buffer))))\r
+             (write-region nil nil file-or-dir-name nil 'nomessage)))\r
           (t\r
            (message "[yas] oops don't know this content")))))\r
 \r
@@ -228,15 +227,22 @@ TODO: correct this bug!"
                  (yas/variables))\r
      ,@body))\r
 \r
+(defun yas/call-with-snippet-dirs (dirs fn)\r
+  (let ((default-directory (make-temp-file "yasnippet-fixture" t))\r
+        (message-log-max nil)\r
+        (yas/snippet-dirs (mapcar #'car (cadr dirs))))\r
+    (with-temp-message ""\r
+      (unwind-protect\r
+          (progn\r
+            (mapc #'yas/make-file-or-dirs dirs)\r
+            (funcall fn))\r
+        (when (>= emacs-major-version 23)\r
+          (delete-directory default-directory 'recursive))))))\r
+\r
 (defmacro with-snippet-dirs (dirs &rest body)\r
-  `(let ((default-directory (make-temp-file "yasnippet-fixture" t)))\r
-     (unwind-protect\r
-         (progn       \r
-           (setq yas/snippet-dirs ',(mapcar #'car (cadr dirs)))\r
-           (mapc #'yas/make-file-or-dirs ,dirs)\r
-           ,@body)\r
-       (when (>= emacs-major-version 23)\r
-         (delete-directory default-directory 'recursive)))))\r
+  `(yas/call-with-snippet-dirs ,dirs\r
+                               #'(lambda ()\r
+                                   ,@body)))\r
 \r
 ;;; Older emacsen\r
 ;;;\r