From 9b04860a22b30db746bbe4cd3376383cc19432ea Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Wed, 27 May 2026 15:08:52 -0500 Subject: refactor(prog): open daily-prep respecting the window split C-c p d (cj/open-project-daily-prep) always forced the prep doc into another window. I switched it to cj/--find-file-respecting-split, the same helper the sibling C-c p t (project todo) uses: it opens the other window when the frame is split and reuses the current window when it isn't. The two project-open commands now behave the same way. --- modules/prog-general.el | 7 ++++--- tests/test-prog-general-open-project-daily-prep.el | 21 ++++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/prog-general.el b/modules/prog-general.el index e8d48b70..e09c3f40 100644 --- a/modules/prog-general.el +++ b/modules/prog-general.el @@ -146,15 +146,16 @@ buffer the user is looking at." (find-file-other-window file))) (defun cj/open-project-daily-prep () - "Open the current Projectile project's daily prep in another window. + "Open the current Projectile project's daily prep, respecting the split. The prep file is inbox/today-prep.org under the project root (a stable symlink to the dated prep doc). Project-scoped: a project without one gets a -message. Opens in another window so it sits beside the current work." +message. Opens in the other window when the frame is split and reuses the +current window otherwise, matching `cj/open-project-root-todo'." (interactive) (if-let ((root (projectile-project-root))) (let ((file (expand-file-name "inbox/today-prep.org" root))) (if (file-exists-p file) - (find-file-other-window file) + (cj/--find-file-respecting-split file) (message "No inbox/today-prep.org in project: %s" root))) (message "Not in a Projectile project"))) diff --git a/tests/test-prog-general-open-project-daily-prep.el b/tests/test-prog-general-open-project-daily-prep.el index 9a38757a..07895ed4 100644 --- a/tests/test-prog-general-open-project-daily-prep.el +++ b/tests/test-prog-general-open-project-daily-prep.el @@ -2,12 +2,14 @@ ;;; Commentary: ;; `cj/open-project-daily-prep' (C-c p d) opens inbox/today-prep.org under the -;; current Projectile project root, in another window. It is project-scoped: -;; projects without a prep file get a message instead. `projectile-project-root' -;; (external project state) and `find-file-other-window' (the window/visit -;; boundary) are stubbed; real temp directories drive the file-exists check, and -;; the message branches are checked via the command's return value rather than -;; by stubbing `message'. +;; current Projectile project root, via `cj/--find-file-respecting-split' so it +;; lands in the other window when the frame is split and reuses the current +;; window otherwise (matching `cj/open-project-root-todo'). It is +;; project-scoped: projects without a prep file get a message instead. +;; `projectile-project-root' (external project state) and +;; `cj/--find-file-respecting-split' (the window/visit boundary) are stubbed; +;; real temp directories drive the file-exists check, and the message branches +;; are checked via the command's return value rather than by stubbing `message'. ;;; Code: @@ -16,8 +18,8 @@ (add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) (require 'prog-general) -(ert-deftest test-prog-general-daily-prep-opens-existing-in-other-window () - "Normal: in a project with a prep file, open it in another window." +(ert-deftest test-prog-general-daily-prep-opens-existing-respecting-split () + "Normal: in a project with a prep file, open it respecting the split." (let* ((root (file-name-as-directory (make-temp-file "cj-prep-" t))) (prep (expand-file-name "inbox/today-prep.org" root)) opened) @@ -26,7 +28,8 @@ (make-directory (expand-file-name "inbox" root) t) (write-region "" nil prep) (cl-letf (((symbol-function 'projectile-project-root) (lambda () root)) - ((symbol-function 'find-file-other-window) (lambda (f) (setq opened f)))) + ((symbol-function 'cj/--find-file-respecting-split) + (lambda (f) (setq opened f)))) (cj/open-project-daily-prep)) (should (equal opened prep))) (delete-directory root t)))) -- cgit v1.2.3