aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-16 14:56:59 -0500
committerCraig Jennings <c@cjennings.net>2026-06-16 14:56:59 -0500
commitd845b34bb44a61e673cb715dbe5309d40f52c5fe (patch)
tree1aa3057d0a5dfc0809ccc2b0c8ec41552dd70100
parentd5d861cf3b7a53ac4d9d5d5a4f0fad55eee16137 (diff)
downloaddotemacs-d845b34bb44a61e673cb715dbe5309d40f52c5fe.tar.gz
dotemacs-d845b34bb44a61e673cb715dbe5309d40f52c5fe.zip
feat(ui-navigation): split from the dashboard opens scratch, not the dashboard
C-x 2 / C-x 3 already show the dashboard in the new window while point stays put. The one dead spot was splitting from the dashboard itself, which put the dashboard in both panes. Now the new window shows *scratch* when the current buffer is the dashboard, and the dashboard everywhere else. I pulled the choice into a pure predicate (cj/--split-from-dashboard-p) and a companion helper, both tested.
-rw-r--r--modules/ui-navigation.el23
-rw-r--r--tests/test-ui-navigation--split-dashboard.el21
2 files changed, 40 insertions, 4 deletions
diff --git a/modules/ui-navigation.el b/modules/ui-navigation.el
index e9c9eaf2..d8d7162e 100644
--- a/modules/ui-navigation.el
+++ b/modules/ui-navigation.el
@@ -118,15 +118,30 @@ window. Return the new window."
(set-window-buffer new buffer))
new))
+(defun cj/--split-from-dashboard-p (buffer-name)
+ "Return non-nil when BUFFER-NAME is the dashboard.
+Splitting from the dashboard shows *scratch* in the new window instead of
+the dashboard again."
+ (equal buffer-name "*dashboard*"))
+
+(defun cj/--split-companion-buffer ()
+ "Buffer to show in the new window after a C-x 2 / C-x 3 split.
+The dashboard, or the *scratch* buffer when splitting from the dashboard."
+ (if (cj/--split-from-dashboard-p (buffer-name))
+ (get-scratch-buffer-create)
+ (cj/--dashboard-buffer)))
+
(defun cj/split-below-with-dashboard ()
- "Split below and show the dashboard in the new window; stay in this one."
+ "Split below and show the companion buffer in the new window; stay in this one.
+The companion is the dashboard, or *scratch* when splitting from the dashboard."
(interactive)
- (cj/--split-show-buffer #'split-window-below (cj/--dashboard-buffer)))
+ (cj/--split-show-buffer #'split-window-below (cj/--split-companion-buffer)))
(defun cj/split-right-with-dashboard ()
- "Split right and show the dashboard in the new window; stay in this one."
+ "Split right and show the companion buffer in the new window; stay in this one.
+The companion is the dashboard, or *scratch* when splitting from the dashboard."
(interactive)
- (cj/--split-show-buffer #'split-window-right (cj/--dashboard-buffer)))
+ (cj/--split-show-buffer #'split-window-right (cj/--split-companion-buffer)))
(keymap-global-set "C-x 2" #'cj/split-below-with-dashboard)
(keymap-global-set "C-x 3" #'cj/split-right-with-dashboard)
diff --git a/tests/test-ui-navigation--split-dashboard.el b/tests/test-ui-navigation--split-dashboard.el
index b815a4c5..407335f8 100644
--- a/tests/test-ui-navigation--split-dashboard.el
+++ b/tests/test-ui-navigation--split-dashboard.el
@@ -54,6 +54,27 @@
(should (eq (car captured) #'split-window-right))
(should (eq (cadr captured) 'dashboard))))
+(ert-deftest test-ui-navigation-split-from-dashboard-p ()
+ "Normal/Boundary: only the dashboard buffer routes the companion to *scratch*."
+ (should (cj/--split-from-dashboard-p "*dashboard*"))
+ (should-not (cj/--split-from-dashboard-p "todo.org"))
+ (should-not (cj/--split-from-dashboard-p "*scratch*")))
+
+(ert-deftest test-ui-navigation-split-companion-scratch-from-dashboard ()
+ "Normal: splitting from the dashboard yields the *scratch* buffer, not the
+dashboard again."
+ (cl-letf (((symbol-function 'cj/--split-from-dashboard-p) (lambda (_) t))
+ ((symbol-function 'get-scratch-buffer-create) (lambda () 'scratch))
+ ((symbol-function 'cj/--dashboard-buffer) (lambda () 'dashboard)))
+ (should (eq (cj/--split-companion-buffer) 'scratch))))
+
+(ert-deftest test-ui-navigation-split-companion-dashboard-otherwise ()
+ "Normal: splitting from any other buffer yields the dashboard."
+ (cl-letf (((symbol-function 'cj/--split-from-dashboard-p) (lambda (_) nil))
+ ((symbol-function 'get-scratch-buffer-create) (lambda () 'scratch))
+ ((symbol-function 'cj/--dashboard-buffer) (lambda () 'dashboard)))
+ (should (eq (cj/--split-companion-buffer) 'dashboard))))
+
(ert-deftest test-ui-navigation-dashboard-buffer-returns-existing ()
"Boundary: cj/--dashboard-buffer returns an existing *dashboard* without opening."
(let ((db (get-buffer-create "*dashboard*"))