From f6e4ddeafdcf6184355cc9d0c70035019718447c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 31 Aug 2025 19:06:58 -0500 Subject: added function and keybinding to open projects todo.org file refactored for switch project function to leverage same code --- modules/prog-general.el | 50 +++++++++++++++++++++++++--------- todo.org | 71 ------------------------------------------------- 2 files changed, 37 insertions(+), 84 deletions(-) diff --git a/modules/prog-general.el b/modules/prog-general.el index a5b0e849f..009c56049 100644 --- a/modules/prog-general.el +++ b/modules/prog-general.el @@ -8,6 +8,8 @@ ;;; Code: +(require 'seq) + ;; ---------------------- General Prog Settings ---------------------- ;; keybindings, minor-modes, and prog-mode settings @@ -48,25 +50,47 @@ ;; backtab is shift-tab ("" . bicycle-cycle-global))) -;; --------------------------- Project Switch Actions -------------------------- -;; when switching projects, display the todo file if it exists, or display -;; magit-status if it doesn't. +;; ----------------------------- 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) ""))))) (defun cj/project-switch-actions () - "Opens TODO or README file on projectile switch project. -If none exists, it opens magit-status." - (let* ((files (directory-files (projectile-project-root))) - (todo-file (seq-find (lambda (file) - (string-match-p "todo\\.\\(org\\|md\\|txt\\)\\'" - (downcase file))) files))) - (if todo-file - (find-file (concat (projectile-project-root) todo-file)) - (magit-status)))) + "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 -;; only run discover projects when there's no bookmarks file +;; only discover projects when there's no bookmarks file (defun cj/projectile-schedule-project-discovery () (let ((projectile-bookmark-file (concat user-emacs-directory "/projectile-bookmarks.eld"))) (unless (file-exists-p projectile-bookmark-file) diff --git a/todo.org b/todo.org index e9229da1a..9b80b35a9 100644 --- a/todo.org +++ b/todo.org @@ -1,75 +1,4 @@ * Emacs Open Work -** DOING [#A] Refactor Custom Functions -Custom Function Refactor Notes - -Note: all operations must indicate when completed in minibuffer - -Main prefix is C-; - -Miscellaneous (no prefix, but must not conflict with others) - "M" cj/merge-list-to-list - ")" cj/jump-to-matching-paren - "f" cj/format-region-or-buffer - "W" cj/count-words-buffer-or-region (pull out into statistics) - "/" cj/replace-fraction-glyphs (pull out into sanitation) - "m" cj/buffer-strip-ctrl-m (pull out into sanitation) - "c" cj/copy-buffer - "r" align-regexp - -"b" Buffer-and-file operations - "m" cj/move-buffer-and-file - "r" cj/rename-buffer-and-file - "d" cj/delete-buffer-and-file - "c" cj/copy-link-to-source-file - -"w" Whitespace - "r" cj/remove-leading-trailing-whitespace - "c" cj/collapse-whitespace-line-or-region (rename to collapse - "l" cj/delete-blank-lines-region-or-buffer - "h" cj/hyphenate-region (rename to hyphenate-whitespace-in-region) - consider changing this to replace all whitespace with a char. - -"s" Surround, Append, Prepend - "s" cj/surround-word-or-region - "a" cj/append-to-lines-in-region-or-buffer - "p" cj/prepend-to-lines-in-region-or-buffer - -"d" Date & time insertion - "r" cj/insert-readable-date-time - "s" cj/insert-sortable-date-time - "t" cj/insert-sortable-time - "T" cj/insert-readable-time - "d" cj/insert-sortable-date - "D" cj/insert-readable-date - -"l" Line & paragraph operations - "j" cj/join-line-or-region "j" - "J" cj/join-paragraph "J" - "d" cj/duplicate-line-or-region "d" - "u" cj/underscore-line "u" - -"m" Comment Operations - "r" cj/comment-reformat - "c" cj/comment-centered - "-" cj/comment-hyphen - "b" cj/comment-box - "R" cj/remove-buffer-comments - - -"o" Ordering - "a" cj/arrayify - "y" cj/unarrayify - "," cj/comma-separated-text-to-lines - "A" cj/alphabetize-region - • (new) create lines to text - • (new) create reverse region - -"c" Case-change - • cj/title-case-region - • upcase-region - • downcase-dwim - - ** DOING [#A] Refactor Comment Boxes ** TODO [#A] Delete whitespace from region is broken ** TODO [#A] Reconfigure ai-config.el -- cgit v1.2.3