diff options
| author | Craig Jennings <c@cjennings.net> | 2025-08-31 20:08:14 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-08-31 20:08:14 -0500 |
| commit | a83f1fd25720567f0cd77f68946001f9434cd366 (patch) | |
| tree | 36a71fd333e140dfe53eba2b99dcdd552f69e07a /modules | |
| parent | 719a5fc3d10c2e8852423575100c1b0b7ac2192d (diff) | |
| download | dotemacs-a83f1fd25720567f0cd77f68946001f9434cd366.tar.gz dotemacs-a83f1fd25720567f0cd77f68946001f9434cd366.zip | |
refactor: Move project todo functions within projectile use-package
The project todo functions were relocated to be within the
projectile use-package declaration, which better organizes related
functionality. This keeps the code for finding and opening project
todo files alongside the projectile configuration that it depends
on, improving code organization and readability.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/prog-general.el | 72 |
1 files changed, 33 insertions, 39 deletions
diff --git a/modules/prog-general.el b/modules/prog-general.el index 009c5604..fcf1992f 100644 --- a/modules/prog-general.el +++ b/modules/prog-general.el @@ -50,43 +50,6 @@ ;; backtab is shift-tab ("<backtab>" . bicycle-cycle-global))) -;; ----------------------------- Project Todo Files ---------------------------- -;; allows the project todo file to be opened via keybinding or on project open. -;; if there's a project todo.org file, open it when the project launches. -;; if theres no project todo.org file, open magit status on project launch. - -(defun cj/find-project-root-file (regexp) - "Return first file in the current Projectile project root matching REGEXP. -Match is done against (downcase file) for case-insensitivity. -REGEXP must be a string or an rx form." - (when-let ((root (projectile-project-root))) - (seq-find (lambda (file) - (string-match-p (if (stringp regexp) - regexp - (rx-to-string regexp)) - (downcase file))) - (directory-files root)))) - -(defun cj/open-project-root-todo () - "Open todo.org in the current Projectile project root. -If no such file exists there, display a message." - (interactive) - (let ((file (cj/find-project-root-file "^todo\\.org$"))) - (if file - (find-file (expand-file-name file (projectile-project-root))) - (message "No todo.org in project root: %s" - (or (projectile-project-root) "<no project>"))))) - -(defun cj/project-switch-actions () - "On =projectile-after-switch-project-hook=, open TODO.{org,md,txt} or fall back to Magit." - (let ((file (cj/find-project-root-file - (rx bos "todo." (or "org" "md" "txt") eos)))) - (if file - (find-file (expand-file-name file (projectile-project-root))) - (magit-status (projectile-project-root))))) - -(define-key projectile-command-map (kbd "t") #'cj/open-project-root-todo) - ;; --------------------------------- Projectile -------------------------------- ;; project support @@ -102,11 +65,42 @@ If no such file exists there, display a message." ("C-c p" . projectile-command-map) :bind (:map projectile-command-map - ("r" . projectile-replace-regexp)) + ("r" . projectile-replace-regexp) + ("t" . cj/open-project-root-todo)) :custom (projectile-auto-discover nil) (projectile-project-search-path `(,code-dir ,projects-dir)) :config + (defun cj/find-project-root-file (regexp) + "Return first file in the current Projectile project root matching REGEXP. +Match is done against (downcase file) for case-insensitivity. +REGEXP must be a string or an rx form." + (when-let ((root (projectile-project-root))) + (seq-find (lambda (file) + (string-match-p (if (stringp regexp) + regexp + (rx-to-string regexp)) + (downcase file))) + (directory-files root)))) + + (defun cj/open-project-root-todo () + "Open todo.org in the current Projectile project root. +If no such file exists there, display a message." + (interactive) + (let ((file (cj/find-project-root-file "^todo\\.org$"))) + (if file + (find-file (expand-file-name file (projectile-project-root))) + (message "No todo.org in project root: %s" + (or (projectile-project-root) "<no project>"))))) + + (defun cj/project-switch-actions () + "On =projectile-after-switch-project-hook=, open TODO.{org,md,txt} or fall back to Magit." + (let ((file (cj/find-project-root-file + (rx bos "todo." (or "org" "md" "txt") eos)))) + (if file + (find-file (expand-file-name file (projectile-project-root))) + (magit-status (projectile-project-root))))) + ;; scan for projects if none are defined (cj/projectile-schedule-project-discovery) @@ -128,7 +122,7 @@ If no such file exists there, display a message." :commands flycheck-projectile-list-errors :bind (:map projectile-command-map - ("x" . flycheck-projectile-list-errors))) + ("x" . flycheck-projectile-list-errors))) ;; ---------------------------------- Ripgrep ---------------------------------- ;; allows fast searching for text anywhere in the project with C-c p G (grep) |
