diff options
| -rw-r--r-- | modules/prog-general.el | 21 | ||||
| -rw-r--r-- | tests/test-prog-general-open-project-daily-prep.el | 57 |
2 files changed, 74 insertions, 4 deletions
diff --git a/modules/prog-general.el b/modules/prog-general.el index 93a3a95c..369a8b08 100644 --- a/modules/prog-general.el +++ b/modules/prog-general.el @@ -146,13 +146,27 @@ buffer the user is looking at." (find-file file) (find-file-other-window file))) +(defun cj/open-project-daily-prep () + "Open the current Projectile project's daily prep in another window. +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." + (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) + (message "No inbox/today-prep.org in project: %s" root))) + (message "Not in a Projectile project"))) + (use-package projectile :bind-keymap ("C-c p" . projectile-command-map) :bind (:map projectile-command-map ("r" . projectile-replace-regexp) - ("t" . cj/open-project-root-todo)) + ("t" . cj/open-project-root-todo) + ("d" . cj/open-project-daily-prep)) :custom (projectile-auto-discover nil) (projectile-project-search-path `(,code-dir ,projects-dir)) @@ -219,9 +233,8 @@ If no such file exists there, display a message." :after projectile :bind (:map projectile-command-map - ("G" . deadgrep) ;; project-wide search - ("g" . cj/deadgrep-here) ;; search in context directory - ("d" . cj/deadgrep-in-dir)) ;; prompt for directory + ("G" . cj/deadgrep-in-dir) ;; prompt for any directory + ("g" . cj/deadgrep-here)) ;; search in context directory :config (require 'thingatpt) diff --git a/tests/test-prog-general-open-project-daily-prep.el b/tests/test-prog-general-open-project-daily-prep.el new file mode 100644 index 00000000..9a38757a --- /dev/null +++ b/tests/test-prog-general-open-project-daily-prep.el @@ -0,0 +1,57 @@ +;;; test-prog-general-open-project-daily-prep.el --- daily-prep opener -*- lexical-binding: t; -*- + +;;; 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'. + +;;; 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-daily-prep-opens-existing-in-other-window () + "Normal: in a project with a prep file, open it in another window." + (let* ((root (file-name-as-directory (make-temp-file "cj-prep-" t))) + (prep (expand-file-name "inbox/today-prep.org" root)) + opened) + (unwind-protect + (progn + (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)))) + (cj/open-project-daily-prep)) + (should (equal opened prep))) + (delete-directory root t)))) + +(ert-deftest test-prog-general-daily-prep-missing-file-messages () + "Boundary: in a project without a prep file, do not open; report it." + (let* ((root (file-name-as-directory (make-temp-file "cj-prep-" t))) + opened result) + (unwind-protect + (progn + (cl-letf (((symbol-function 'projectile-project-root) (lambda () root)) + ((symbol-function 'find-file-other-window) (lambda (f) (setq opened f)))) + (setq result (cj/open-project-daily-prep))) + (should-not opened) + (should (string-match-p "No inbox/today-prep.org" result))) + (delete-directory root t)))) + +(ert-deftest test-prog-general-daily-prep-not-in-project-messages () + "Error: outside a Projectile project, do not open; report it." + (let (opened result) + (cl-letf (((symbol-function 'projectile-project-root) (lambda () nil)) + ((symbol-function 'find-file-other-window) (lambda (f) (setq opened f)))) + (setq result (cj/open-project-daily-prep))) + (should-not opened) + (should (string-match-p "Not in a Projectile project" result)))) + +(provide 'test-prog-general-open-project-daily-prep) +;;; test-prog-general-open-project-daily-prep.el ends here |
