From 92eaba30ae35727509f1d9d6dcc467c248f627dc Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 25 May 2026 08:00:20 -0500 Subject: 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. --- modules/prog-general.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/prog-general.el b/modules/prog-general.el index dedf8a80..93a3a95c 100644 --- a/modules/prog-general.el +++ b/modules/prog-general.el @@ -137,6 +137,15 @@ (unless (file-exists-p projectile-bookmark-file) (run-at-time "3" nil 'projectile-discover-projects-in-search-path)))) +(defun cj/--find-file-respecting-split (file) + "Open FILE in another window when the frame is split, else in this window. +\"Split\" means the selected window is not the only one in its frame, so +opening the file lands it in the other pane rather than replacing the +buffer the user is looking at." + (if (one-window-p) + (find-file file) + (find-file-other-window file))) + (use-package projectile :bind-keymap ("C-c p" . projectile-command-map) @@ -171,7 +180,7 @@ If no such file exists there, display a message." (if-let ((root (projectile-project-root))) (let ((file (cj/find-project-root-file "^todo\\.org$"))) (if file - (find-file (expand-file-name file root)) + (cj/--find-file-respecting-split (expand-file-name file root)) (message "No todo.org in project root: %s" root))) (message "Not in a Projectile project"))) -- cgit v1.2.3