emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/assess af8b3a8d8b 14/95: with-temp-buffers now works li


From: ELPA Syncer
Subject: [elpa] externals/assess af8b3a8d8b 14/95: with-temp-buffers now works like let.
Date: Tue, 19 Jul 2022 15:57:29 -0400 (EDT)

branch: externals/assess
commit af8b3a8d8bb083b6f225ee94ce5bf411f1755050
Author: Phillip Lord <phillip.lord@newcastle.ac.uk>
Commit: Phillip Lord <phillip.lord@newcastle.ac.uk>

    with-temp-buffers now works like let.
    
    It is now possible to evaluate forms within the context of each
    generated temp buffer inside the `sisyphus-with-temp-buffers' form.
---
 sisyphus.el           | 24 ++++++++++++++++++------
 test/sisyphus-test.el | 26 +++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/sisyphus.el b/sisyphus.el
index 5a09f643ff..356f89ac61 100644
--- a/sisyphus.el
+++ b/sisyphus.el
@@ -239,17 +239,29 @@ print any messages!"
         (-difference (buffer-list)
                      before-buffer-list)))))
 
+(defun sisyphus--temp-buffer-let-form (item)
+  (if (not (listp item))
+      (sisyphus--temp-buffer-let-form
+       (list item))
+    `(,(car item)
+      (with-current-buffer
+          (generate-new-buffer "sisyphus-with-temp-buffers")
+        ,@(cdr item)
+        (current-buffer)))))
+
 (defmacro sisyphus-with-temp-buffers (varlist &rest body)
   "Bind variables in VARLIST to temp buffers, then eval BODY.
 
-VARLIST is a list of symbols. Each is bound to a buffer generated
-with `generate-new-buffer'. Buffers are unconditionally killed at
-the end of the form."
+VARLIST is of the same form as a `let' binding. Each element is a
+symbol or a list (SYMBOL VALUEFORMS). Each symbol is bound to a
+buffer generated with `generate-new-buffer'. VALUEFORMS are
+evaluated with the buffer current. Buffers are unconditionally
+killed at the end of the form."
   (declare (indent 1)
-           (debug (sexp body)))
+           (debug let))
   (let ((let-form
-         (--map
-          `(,it (generate-new-buffer "sisyphus-with-temp-buffers"))
+         (-map
+          #'sisyphus--temp-buffer-let-form
           varlist)))
     `(sisyphus-with-preserved-buffer-list
       (let ,let-form
diff --git a/test/sisyphus-test.el b/test/sisyphus-test.el
index b83e561f54..74dd11a69c 100644
--- a/test/sisyphus-test.el
+++ b/test/sisyphus-test.el
@@ -176,4 +176,28 @@ This also tests the advice on string=."
 (ert-deftest with-temp-buffers ()
   (should
    (bufferp
-    (sisyphus-with-temp-buffers (a) a))))
+    (sisyphus-with-temp-buffers (a) a)))
+  (should
+   (bufferp
+    (sisyphus-with-temp-buffers
+        (a (insert "hello"))
+      a)))
+  (should
+   (equal
+    "hello"
+    (sisyphus-with-temp-buffers
+        ((a (insert "hello")))
+      (with-current-buffer
+          a
+        (buffer-string)))))
+  (should
+   (=
+    (+ 2 (length (buffer-list)))
+    (sisyphus-with-temp-buffers (a b)
+      (length (buffer-list)))))
+  (should
+   (=
+    (length (buffer-list))
+    (progn
+      (sisyphus-with-temp-buffers (a b))
+      (length (buffer-list))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]