diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-25 08:00:20 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-25 08:00:20 -0500 |
| commit | 92eaba30ae35727509f1d9d6dcc467c248f627dc (patch) | |
| tree | 941a9dfc2229185df5a8962da96e3473a99f4a1e /tests | |
| parent | 3f75b39bbbc4e1c136d3f786024c5c1ed19011ce (diff) | |
| download | dotemacs-92eaba30ae35727509f1d9d6dcc467c248f627dc.tar.gz dotemacs-92eaba30ae35727509f1d9d6dcc467c248f627dc.zip | |
fix(prog-general): open the project todo in the other window when split
C-c p t (cj/open-project-root-todo) called find-file, which always opened todo.org in the selected window, replacing whatever I was looking at. Now it opens in the other window when the frame is split and in the current window when it isn't, through a small cj/--find-file-respecting-split helper. The helper is a top-level defun rather than buried in the projectile :config block so it can be unit-tested without loading projectile.
I left cj/project-switch-actions alone. Opening the todo on a project switch is a different trigger and not what this fixes.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-prog-general--find-file-respecting-split.el | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/test-prog-general--find-file-respecting-split.el b/tests/test-prog-general--find-file-respecting-split.el new file mode 100644 index 00000000..6d45c51c --- /dev/null +++ b/tests/test-prog-general--find-file-respecting-split.el @@ -0,0 +1,63 @@ +;;; test-prog-general--find-file-respecting-split.el --- split-aware file open -*- lexical-binding: t; -*- + +;;; Commentary: +;; `cj/--find-file-respecting-split' opens a file in another window when the +;; frame is split and in the current window otherwise. It backs +;; `cj/open-project-root-todo' (C-c p t) so the project todo lands in the +;; other pane instead of replacing the buffer in the selected window. +;; +;; `find-file' / `find-file-other-window' are stubbed -- they are the file-I/O +;; boundary -- while the window layout is real. + +;;; Code: + +(require 'ert) +(require 'cl-lib) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'prog-general) + +(ert-deftest test-prog-general--find-file-respecting-split-single-window-uses-current () + "Normal: a single-window frame opens the file in the current window." + (save-window-excursion + (delete-other-windows) + (let (current-arg other-called) + (cl-letf (((symbol-function 'find-file) + (lambda (f) (setq current-arg f))) + ((symbol-function 'find-file-other-window) + (lambda (_f) (setq other-called t)))) + (cj/--find-file-respecting-split "/tmp/proj/todo.org")) + (should (equal current-arg "/tmp/proj/todo.org")) + (should-not other-called)))) + +(ert-deftest test-prog-general--find-file-respecting-split-two-windows-uses-other () + "Normal: a two-window split opens the file in the other window." + (save-window-excursion + (delete-other-windows) + (split-window-right) + (let (other-arg current-called) + (cl-letf (((symbol-function 'find-file-other-window) + (lambda (f) (setq other-arg f))) + ((symbol-function 'find-file) + (lambda (_f) (setq current-called t)))) + (cj/--find-file-respecting-split "/tmp/proj/todo.org")) + (should (equal other-arg "/tmp/proj/todo.org")) + (should-not current-called)))) + +(ert-deftest test-prog-general--find-file-respecting-split-three-windows-uses-other () + "Boundary: more than two windows still counts as split -> other window." + (save-window-excursion + (delete-other-windows) + (split-window-right) + (split-window-below) + (let (other-called current-called) + (cl-letf (((symbol-function 'find-file-other-window) + (lambda (_f) (setq other-called t))) + ((symbol-function 'find-file) + (lambda (_f) (setq current-called t)))) + (cj/--find-file-respecting-split "/tmp/proj/todo.org")) + (should other-called) + (should-not current-called)))) + +(provide 'test-prog-general--find-file-respecting-split) +;;; test-prog-general--find-file-respecting-split.el ends here |
