From c6e015709516437518031655caa5ba983e24b840 Mon Sep 17 00:00:00 2001 From: Achim Gratz Date: Sun, 17 Nov 2013 21:31:03 +0100 Subject: [PATCH] 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). --- testing/org-test.el | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/testing/org-test.el b/testing/org-test.el index e64e99b16..ad70262fe 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -205,31 +205,32 @@ mode holding TEXT. If the string \"\" appears in TEXT then remove it and place the point there before running BODY, otherwise place the point at the beginning of the inserted text." (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) - ,(let ((point (string-match (regexp-quote "") inside-text))) + (let ((point (string-match (regexp-quote "") inside-text))) (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))) (def-edebug-spec org-test-with-temp-text (form 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." (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) (setq ,results (progn ,@body)) (save-buffer) (kill-buffer (current-buffer)) - (delete-file ,file) + (delete-file file) ,results))) (def-edebug-spec org-test-with-temp-text-in-file (form body))