diff options
| author | Matthew White <mehw.is.me@inventati.org> | 2021-08-06 03:31:02 +0000 |
|---|---|---|
| committer | Matthew White <mehw.is.me@inventati.org> | 2021-10-20 23:01:53 +0200 |
| commit | c7cffe1dc77c7ab55f2970df53f57c6e9805c59c (patch) | |
| tree | c20c084297a43b3ab82dffc549ef8469f718aee8 /test | |
| parent | f7dd9da5302951e292b9128aa47f9c380d5d23db (diff) | |
persp-test-kill-extra-buffers: ert kill extra buffers
Utility function to reset a state, cleaning up a list of extra buffers
and, automatically each time it is called, "*scratch* (NAME)" buffers.
Diffstat (limited to 'test')
| -rw-r--r-- | test/test-perspective.el | 17 |
1 files changed, 17 insertions, 0 deletions
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 |
