diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-11 15:35:43 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-11 15:35:43 -0500 |
| commit | 0ddbcde1e9f17021377f4160b39cd0790afcbdcc (patch) | |
| tree | d1872d799dc7554b128989411a23b9cad65a6671 /tests/test-undead-buffers--kill-other-window-buffer.el | |
| parent | f837e5f7464932fc49c10a7442dc1a23af61b257 (diff) | |
| download | dotemacs-0ddbcde1e9f17021377f4160b39cd0790afcbdcc.tar.gz dotemacs-0ddbcde1e9f17021377f4160b39cd0790afcbdcc.zip | |
feat(window): kill the other window's buffer with C-; b K
`cj/kill-other-window-buffer' (in undead-buffers.el, on `C-; b K') kills or buries the buffer shown in the other window and leaves that window and the split alone. The window just shows whatever bury/kill surfaces next. It reuses `cj/kill-buffer-or-bury-alive', so buffers in `cj/undead-buffer-list' (like `*scratch*') get buried. With more than two windows it acts on `next-window'. Sibling of `cj/kill-other-window' (M-S-o), which deletes the other window. This one keeps it.
Diffstat (limited to 'tests/test-undead-buffers--kill-other-window-buffer.el')
| -rw-r--r-- | tests/test-undead-buffers--kill-other-window-buffer.el | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/test-undead-buffers--kill-other-window-buffer.el b/tests/test-undead-buffers--kill-other-window-buffer.el new file mode 100644 index 00000000..4dbbb710 --- /dev/null +++ b/tests/test-undead-buffers--kill-other-window-buffer.el @@ -0,0 +1,74 @@ +;;; test-undead-buffers--kill-other-window-buffer.el --- Tests for cj/kill-other-window-buffer -*- lexical-binding: t; -*- + +;;; Commentary: +;; `cj/kill-other-window-buffer' kills (or buries, for `cj/undead-buffer-list' +;; buffers) the buffer shown in the other window, leaving that window and the +;; split intact -- the window then shows whatever bury/kill surfaces next. +;; Sibling of `cj/kill-other-window' (which deletes the other window); the +;; distinguishing trait here is that the split is preserved. + +;;; Code: + +(require 'ert) +(require 'cl-lib) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory)) +(require 'undead-buffers) + +(ert-deftest test-undead-buffers-kill-other-window-buffer-keeps-the-window () + "Normal: kills the other window's (non-undead) buffer but keeps the window +and the split -- the current window is left untouched." + (let ((other (generate-new-buffer "test-kill-other-window-buffer")) + (orig (copy-sequence cj/undead-buffer-list))) + (unwind-protect + (save-window-excursion + (delete-other-windows) + (split-window-right) + (let* ((win-a (selected-window)) + (buf-a (window-buffer win-a)) + (win-b (next-window win-a))) + (set-window-buffer win-b other) + (select-window win-a) + (cj/kill-other-window-buffer) + (should (window-live-p win-b)) + (should-not (buffer-live-p other)) + (should (eq (window-buffer win-a) buf-a)))) + (setq cj/undead-buffer-list orig) + (when (buffer-live-p other) (kill-buffer other))))) + +(ert-deftest test-undead-buffers-kill-other-window-buffer-buries-undead () + "Boundary: an undead buffer in the other window is buried, not killed -- +still alive, no longer shown there; the window stays." + (let ((other (generate-new-buffer "test-kill-other-undead")) + (orig (copy-sequence cj/undead-buffer-list))) + (unwind-protect + (save-window-excursion + (add-to-list 'cj/undead-buffer-list (buffer-name other)) + (delete-other-windows) + (split-window-right) + (let* ((win-a (selected-window)) + (win-b (next-window win-a))) + (set-window-buffer win-b other) + (select-window win-a) + (cj/kill-other-window-buffer) + (should (window-live-p win-b)) + (should (buffer-live-p other)) + (should-not (eq (window-buffer win-b) other)))) + (setq cj/undead-buffer-list orig) + (when (buffer-live-p other) (kill-buffer other))))) + +(ert-deftest test-undead-buffers-kill-other-window-buffer-errors-with-one-window () + "Error: with only one window there is no other window to act on." + (save-window-excursion + (delete-other-windows) + (should-error (cj/kill-other-window-buffer) :type 'user-error))) + +(ert-deftest test-undead-buffers-kill-other-window-buffer-bound-under-c-semicolon-b () + "Normal: reachable via C-; b K." + (require 'custom-buffer-file) + (should (eq (keymap-lookup cj/buffer-and-file-map "K") + #'cj/kill-other-window-buffer))) + +(provide 'test-undead-buffers--kill-other-window-buffer) +;;; test-undead-buffers--kill-other-window-buffer.el ends here |
