浏览代码

org-test: fix macro definitions so that eager macro expansion doesn't fail

* testing/org-test.el (org-test-with-temp-text,
  org-test-with-temp-text-in-file): Correct quoting of macro
  expansion.

Macro arguments must not be used during macro expansion since they are
not available at that time; conversely, bindings established during
macro expansion generally can not be used at macro execution
time (unless un-quoted during expansion).
Achim Gratz 11 年之前
父节点
当前提交
c6e0157095
共有 1 个文件被更改,包括 15 次插入14 次删除
  1. 15 14
      testing/org-test.el

+ 15 - 14
testing/org-test.el

@@ -205,31 +205,32 @@ mode holding TEXT.  If the string \"<point>\" appears in TEXT
 then remove it and place the point there before running BODY,
 then remove it and place the point there before running BODY,
 otherwise place the point at the beginning of the inserted text."
 otherwise place the point at the beginning of the inserted text."
   (declare (indent 1))
   (declare (indent 1))
-  (let ((inside-text (if (stringp text) text (eval text))))
-    `(with-temp-buffer
+  `(let ((inside-text (if (stringp ,text) ,text (eval ,text))))
+     (with-temp-buffer
        (org-mode)
        (org-mode)
-       ,(let ((point (string-match (regexp-quote "<point>") inside-text)))
+       (let ((point (string-match (regexp-quote "<point>") inside-text)))
 	  (if point
 	  (if point
-	      `(progn (insert `(replace-match "" nil nil inside-text))
-		      (goto-char ,(match-beginning 0)))
-	    `(progn (insert ,inside-text)
-		    (goto-char (point-min)))))
+	      (progn (insert (replace-match "" nil nil inside-text))
+		     (goto-char (match-beginning 0)))
+	    (progn (insert inside-text)
+		   (goto-char (point-min)))))
        ,@body)))
        ,@body)))
 (def-edebug-spec org-test-with-temp-text (form body))
 (def-edebug-spec org-test-with-temp-text (form body))
 
 
 (defmacro org-test-with-temp-text-in-file (text &rest body)
 (defmacro org-test-with-temp-text-in-file (text &rest body)
   "Run body in a temporary file buffer with Org-mode as the active mode."
   "Run body in a temporary file buffer with Org-mode as the active mode."
   (declare (indent 1))
   (declare (indent 1))
-  (let ((file (make-temp-file "org-test"))
-	(inside-text (if (stringp text) text (eval text)))
-	(results (gensym)))
-    `(let ((kill-buffer-query-functions nil) ,results)
-       (with-temp-file ,file (insert ,inside-text))
-       (find-file ,file)
+  (let ((results (gensym)))
+    `(let ((file (make-temp-file "org-test"))
+	   (kill-buffer-query-functions nil)
+	   (inside-text (if (stringp ,text) ,text (eval ,text)))
+	   ,results)
+       (with-temp-file file (insert inside-text))
+       (find-file file)
        (org-mode)
        (org-mode)
        (setq ,results (progn ,@body))
        (setq ,results (progn ,@body))
        (save-buffer) (kill-buffer (current-buffer))
        (save-buffer) (kill-buffer (current-buffer))
-       (delete-file ,file)
+       (delete-file file)
        ,results)))
        ,results)))
 (def-edebug-spec org-test-with-temp-text-in-file (form body))
 (def-edebug-spec org-test-with-temp-text-in-file (form body))