diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-27 18:26:58 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-27 18:26:58 -0500 |
| commit | 73f7656d02f916c361fc0da06d97d9bdaf9062a0 (patch) | |
| tree | 5b3f3e4a1412462ce888b65829e4312f3dfc670f | |
| parent | 34b4e5ecd8468129cb97e870987fc8bb8d27d6e2 (diff) | |
| download | pearl-73f7656d02f916c361fc0da06d97d9bdaf9062a0.tar.gz pearl-73f7656d02f916c361fc0da06d97d9bdaf9062a0.zip | |
feat(compose): open compose and conflict buffers in a configurable side window
The compose buffers (edit-description, add-comment) and the smerge conflict buffer popped wherever display-buffer happened to put them. Now they open in a side window, defaulting to the bottom at 30% of the frame, with two defcustoms to control it: pearl-compose-window-side (bottom / top / left / right) and pearl-compose-window-size (a fraction of the frame, or an absolute line/column count). pearl--compose-display-action builds the display-buffer-in-side-window action and both pop sites pass it through pop-to-buffer, so Pearl always applies the side window over any display-buffer-alist entry for these buffers.
| -rw-r--r-- | pearl.el | 32 | ||||
| -rw-r--r-- | tests/test-pearl-compose.el | 23 |
2 files changed, 53 insertions, 2 deletions
@@ -146,6 +146,34 @@ With the default nil, `pearl-surface-buffer' shows the buffer via :type 'boolean :group 'pearl) +(defcustom pearl-compose-window-side 'bottom + "Side of the frame Pearl's compose and conflict buffers open from. +One of `bottom', `top', `left', or `right'. Pearl always applies this side +window when popping a compose buffer, overriding any `display-buffer-alist' +entry for those buffers." + :type '(choice (const bottom) (const top) (const left) (const right)) + :group 'pearl) + +(defcustom pearl-compose-window-size 0.3 + "Size of Pearl's compose and conflict side window. +A float below 1 is a fraction of the frame (0.3 = 30%); an integer is an +absolute size in lines (for `bottom'/`top') or columns (for `left'/`right'). +Paired with `pearl-compose-window-side'." + :type 'number + :group 'pearl) + +(defun pearl--compose-display-action () + "Return the `display-buffer' action for a compose or conflict buffer. +A side window on `pearl-compose-window-side', sized by +`pearl-compose-window-size' -- `window-width' for the left/right sides, +`window-height' for top/bottom." + (cons '(display-buffer-in-side-window) + (list (cons 'side pearl-compose-window-side) + (cons (if (memq pearl-compose-window-side '(left right)) + 'window-width + 'window-height) + pearl-compose-window-size)))) + (defun pearl--surface-buffer (buffer) "Bring BUFFER to a window after a command updated it, unless already shown. No-op when `pearl-surface-buffer' is nil, BUFFER is dead, or BUFFER is already @@ -2136,7 +2164,7 @@ sibling of `pearl--resolve-conflict-in-smerge'." (local-set-key (kbd "C-c C-c") #'pearl--compose-submit) (local-set-key (kbd "C-c C-k") #'pearl--compose-abort) (goto-char (point-max))) - (pop-to-buffer buf) + (pop-to-buffer buf (pearl--compose-display-action)) buf)) (defvar-local pearl--conflict-on-finish nil @@ -2171,7 +2199,7 @@ given, is a thunk run on abort so the save engine can report the outcome." (setq-local header-line-format (substitute-command-keys "Resolve the conflict, then \\[pearl--conflict-commit] to push, \\[pearl--conflict-abort] to abort"))) - (pop-to-buffer buf))) + (pop-to-buffer buf (pearl--compose-display-action)))) (defun pearl--conflict-commit () "Finish the current pearl conflict buffer, pushing the reconciled text. diff --git a/tests/test-pearl-compose.el b/tests/test-pearl-compose.el index 7029297..3e62c09 100644 --- a/tests/test-pearl-compose.el +++ b/tests/test-pearl-compose.el @@ -149,5 +149,28 @@ Binds `captured' to the value the on-finish receives (or `:none'). Stubs (goto-char (point-min)) (should (re-search-forward "Edited description" nil t)))))) +;;; compose-window display action + +(ert-deftest test-pearl-compose-display-action-defaults-to-bottom-fraction () + "By default the compose window opens at the bottom, sized to 30% of the frame." + (should (equal '((display-buffer-in-side-window) (side . bottom) (window-height . 0.3)) + (pearl--compose-display-action)))) + +(ert-deftest test-pearl-compose-display-action-honors-side-and-size () + "The side and size defcustoms drive the action; left/right size the width, +top/bottom the height, and the size passes through as float or integer." + (let ((pearl-compose-window-side 'right) + (pearl-compose-window-size 40)) + (should (equal '((display-buffer-in-side-window) (side . right) (window-width . 40)) + (pearl--compose-display-action)))) + (let ((pearl-compose-window-side 'top) + (pearl-compose-window-size 0.25)) + (should (equal '((display-buffer-in-side-window) (side . top) (window-height . 0.25)) + (pearl--compose-display-action)))) + (let ((pearl-compose-window-side 'left) + (pearl-compose-window-size 0.2)) + (should (equal '((display-buffer-in-side-window) (side . left) (window-width . 0.2)) + (pearl--compose-display-action))))) + (provide 'test-pearl-compose) ;;; test-pearl-compose.el ends here |
