aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--test/test-perspective.el17
2 files changed, 18 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bf05c6b..13d98b9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### ERT tests added
+- `persp-test-kill-extra-buffers`: utility function for cleaning up and killing extra buffers.
- `basic-persp-test-match-scratch-buffers`: evaluate `persp-test-match-scratch-buffers`.
- `persp-test-match-scratch-buffers`: utility function to list live scratch buffers.
- `basic-persp-test-with-persp`: evaluate `persp-test-with-persp` macro.
diff --git a/test/test-perspective.el b/test/test-perspective.el
index 9c5cdb4..eeab952 100644
--- a/test/test-perspective.el
+++ b/test/test-perspective.el
@@ -58,6 +58,23 @@ with \"*scratch*\". Sort the list by names via `string-lessp'."
(lambda (a b)
(string-lessp (buffer-name a) (buffer-name b)))))))
+(defun persp-test-kill-extra-buffers (&rest buffer-or-name)
+ "Kill BUFFER-OR-NAME and extra scratch buffers found.
+Return a list of names of the killed buffers, or nil if there's
+no candidate to kill.
+
+Extra scratch buffers have a name that begins with \"*scratch*\",
+like \"*scratch* \" and \"*scratch* (NAME)\"."
+ (let* (kill-list-names
+ (scratch-buffer (get-buffer "*scratch*"))
+ (extra-buffers (mapcar #'get-buffer buffer-or-name))
+ (matched-buffers (remq scratch-buffer (persp-test-match-scratch-buffers))))
+ (dolist (buffer (cl-remove-duplicates (append extra-buffers matched-buffers)))
+ (when (buffer-live-p buffer)
+ (push (buffer-name buffer) kill-list-names)
+ (kill-buffer buffer)))
+ (sort kill-list-names #'string-lessp)))
+
(defmacro persp-test-with-persp (&rest body)
"Allow multiple tests to run with reasonable assumption of
isolation. This macro assumes persp-mode is turned off, then