diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/org-agenda-config.el | 85 | ||||
| -rw-r--r-- | modules/org-config.el | 1 | ||||
| -rw-r--r-- | modules/org-refile-config.el | 87 |
3 files changed, 98 insertions, 75 deletions
diff --git a/modules/org-agenda-config.el b/modules/org-agenda-config.el index c034aa05..f0bf7256 100644 --- a/modules/org-agenda-config.el +++ b/modules/org-agenda-config.el @@ -4,25 +4,26 @@ ;;; Commentary: ;; Agenda views are tied to the F8 (fate) key. -;; f8 - A daily schedule with task items with a scheduled date or deadline of -;; the current day. This is followed by a task list containing tasks from -;; all agenda sources. -;; C-f8 - A task list containing all tasks from all agenda sources -;; M-f8 - A task list containing all tasks from the current org-mode buffer. + +;; f8 - DAILY SCHEDULE containing a events with a scheduled date or deadline of +;; the current day. This is followed by... +;; - TASK LIST containing tasks from all agenda sources. + +;; C-f8 - TASK LIST containing all tasks from all agenda sources + +;; M-f8 - TASK LIST containing all tasks from the current org-mode buffer. ;; NOTE: ;; Files that contain information relevant to the agenda will be found in the -;; following places: the schedule-file, org-roam notes tagged as 'projects' and -;; project todo.org files found in project-dir and code-dir. The function -;; that rebuilds the agenda list. +;; following places: the schedule-file, org-roam notes tagged as 'Projects' and +;; project todo.org files found in project-dir and code-dir. ;; How the agenda is created: -;; In order to stay current, the files containing agenda information are queried -;; before calling the functions in the section org-agenda functions to display -;; the data. - -;; This way, we can maximize flexibility and limit the agenda-files to a smaller -;; set of files for a scoped agenda. +;; The inbox and schedule files are always included first. However, in order to +;; stay current, the files containing agenda information are queried before +;; calling the functions in the section org-agenda functions to display the +;; data. This way, any newly created events from project todo.org files, or +;; org-roam Project files will be included. ;;; Code: @@ -66,8 +67,8 @@ ;; ------------------ Org TODO Next/Previous Set Keybindings ----------------- (add-hook 'org-agenda-mode-hook (lambda () - (local-set-key (kbd "s-<right>") #'org-agenda-todo-nextset) - (local-set-key (kbd "s-<left>") #'org-agenda-todo-previousset))) + (local-set-key (kbd "s-<right>") #'org-agenda-todo-nextset) + (local-set-key (kbd "s-<left>") #'org-agenda-todo-previousset))) ;; ------------------------------ Org Super Agenda ----------------------------- @@ -170,35 +171,39 @@ This allows a line to show in an agenda without being scheduled or a deadline." ;; org-agenda-files list. (defun cj/add-files-to-org-agenda-files (directory) - "Recursively searches for files named 'todo.org'. -Searches in DIRECTORY and adds them to org-project-files." - (interactive "D") + "Recursively searches for files named 'todo.org', + Searches in DIRECTORY and adds them to org-project-files." + (interactive "D") (setq org-agenda-files - (append org-agenda-files - (directory-files-recursively directory "^[Tt][Oo][Dd][Oo]\\.[Oo][Rr][Gg]$" t)))) + (append (directory-files-recursively directory + "^[Tt][Oo][Dd][Oo]\\.[Oo][Rr][Gg]$" t) + org-agenda-files))) + ;; NOTE: the following functions require org-roam functionality (with-eval-after-load 'org-roam-config - ;; ---------------------------- Rebuild Org Agenda --------------------------- - - (defun cj/build-org-agenda-list () - "Rebuilds the org agenda list." - (interactive) - ;; reset org-agenda-files to inbox-file - (setq org-agenda-files (list inbox-file)) - (let ((new-files - (append - (cj/org-roam-list-notes-by-tag "Project")))) - (dolist (file new-files) - (unless (member file org-agenda-files) - (setq org-agenda-files (cons file org-agenda-files))))) - - (cj/add-files-to-org-agenda-files projects-dir) - (cj/add-files-to-org-agenda-files code-dir)) - - ;; build org-agenda-list for the first time once emacs init is complete. - (add-hook 'emacs-startup-hook 'cj/build-org-agenda-list) + ;; ---------------------------- Rebuild Org Agenda --------------------------- + + (defun cj/build-org-agenda-list () + "Rebuilds the org agenda list. +Begins with the inbox-file and schedule-file, then searches for org-roam +Projects and adds all todo.org files from code and project directories." + (interactive) + ;; reset org-agenda-files to inbox-file + (setq org-agenda-files (list inbox-file schedule-file)) + (let ((new-files + (append + (cj/org-roam-list-notes-by-tag "Project")))) + (dolist (file new-files) + (unless (member file org-agenda-files) + (setq org-agenda-files (cons file org-agenda-files))))) + + (cj/add-files-to-org-agenda-files projects-dir) + (cj/add-files-to-org-agenda-files code-dir)) + + ;; build org-agenda-list for the first time once emacs init is complete. + (add-hook 'emacs-startup-hook 'cj/build-org-agenda-list) ;; ------------------------ Org Agenda Display Functions ----------------------- diff --git a/modules/org-config.el b/modules/org-config.el index 6a177d30..0094cc9d 100644 --- a/modules/org-config.el +++ b/modules/org-config.el @@ -54,7 +54,6 @@ (:map org-mode-map ("C-c ?" . hydra-general/body) ;; was org-table-field-info ("C-c I" . org-table-field-info) ;; was C-c ? - ("C-c w" . cj/org-refile-in-file) ("C-\\" . org-match-sparse-tree) ("C-c t" . org-set-tags-command) ("C-c l" . org-store-link) diff --git a/modules/org-refile-config.el b/modules/org-refile-config.el index 8c058d66..3f71d91d 100644 --- a/modules/org-refile-config.el +++ b/modules/org-refile-config.el @@ -5,58 +5,77 @@ ;;; Code: -(with-eval-after-load 'org-roam-config - (require 'org-refile) +(use-package org-refile + :ensure nil ;; built-in + :defer .5 + :bind + (:map org-mode-map + ("C-c C-w" . cj/org-refile) + ("C-c w" . cj/org-refile-in-file)) + :config ;; ----------------------------- Org Refile Targets ---------------------------- ;; sets refile targets ;; - adds project files in org-roam to the refile targets ;; - adds todo.org files in subdirectories of the code and project directories - (defun cj/add-files-to-org-refile-targets (directory) - "Recursively searches for all files named 'todo.org' in DIRECTORY and adds them to org-project-files." - (interactive "D") - (let ((files (directory-files-recursively directory "^[Tt][Oo][Dd][Oo]\\.[Oo][Rr][Gg]$" t))) - (dolist (file files) - (add-to-list 'org-refile-targets `(,file . (:level . 1)))))) - (defun cj/build-org-refile-targets() - "Build org-refile-targets. -Starts with the schedule file, then adds the Emacs task list, -and any task list in the code or projects directories." + "Build org-refile-targets." (interactive) - (let ((new-files - (append - (cj/org-roam-list-notes-by-tag "Project") - (cj/org-roam-list-notes-by-tag "Topic")))) - (dolist (file new-files) - (unless (member file org-agenda-files) - (setq org-agenda-files (cons file org-agenda-files)))) - ) - (setq org-refile-targets '((org-agenda-files :maxlevel . 1))) - (cj/add-files-to-org-refile-targets user-emacs-directory) - (cj/add-files-to-org-refile-targets code-dir) - (cj/add-files-to-org-refile-targets projects-dir)) - - ;; --------------------------------- Org-Refile ------------------------------- + (let (new-files) + ;; Start with the inbox and the schedule files. + (setq new-files `((,inbox-file . (:maxlevel . 1)) (,schedule-file . (:maxlevel . 1)))) + + ;; Extend new-files with the project and topic files. + (let ((project-and-topic-files (append (cj/org-roam-list-notes-by-tag "Project") + (cj/org-roam-list-notes-by-tag "Topic")))) + (let ((file-rule `(:level . 1))) + (dolist (file project-and-topic-files) + (unless (assoc file new-files) + (push `(,file . ,file-rule) new-files))))) + + ;; Extend new-files with todo.org files in the specified directories. + (dolist (dir (list user-emacs-directory code-dir projects-dir)) + (let ((todo-files (directory-files-recursively dir "^[Tt][Oo][Dd][Oo]\\.[Oo][Rr][Gg]$"))) + (let ((file-rule `(:level . 1))) + (dolist (file todo-files) + (unless (assoc file new-files) + (push `(,file . ,file-rule) new-files)))))) + + ;; Set org-refile-targets. + (setq org-refile-targets (nreverse new-files)))) + + ;; -------------------------------- Org-Refile ------------------------------- + ;; used in place of org-refile to ensure the refile targets are rebuilt. + + (defun cj/org-refile (&optional ARG DEFAULT-BUFFER RFLOC MSG) + "Simply rebuilds the refile targets before calling org-refile. +ARG DEFAULT-BUFFER RFLOC and MSG parameters passed to org-refile." + (interactive "P") + (cj/build-org-refile-targets) + (org-refile ARG DEFAULT-BUFFER RFLOC MSG)) + + ;; ----------------------------- Org Refile In File ---------------------------- ;; convenience function for scoping the refile candidates to the current buffer. (defun cj/org-refile-in-file () "Refile to a target within the current file and save the buffer." - (interactive) - (let ((org-refile-targets `(((,(buffer-file-name)) :maxlevel . 6)))) + (interactive) + (let ((org-refile-targets `(((,(buffer-file-name)) :maxlevel . 6)))) (call-interactively 'org-refile) (save-buffer))) - ;; ----------------------- Save Org Files After Refile ----------------------- - ;; advice that saves all open org buffers after a refile is complete + ) ; end use-package statement + + +;; ----------------------- Save Org Files After Refile ----------------------- +;; advice that saves all open org buffers after a refile is complete - (advice-add 'org-refile :after - (lambda (&rest _) - (org-save-all-org-buffers))) +(advice-add 'org-refile :after + (lambda (&rest _) + (org-save-all-org-buffers))) - ) ;; end with eval-after-load 'org-roam (provide 'org-refile-config) ;;; org-refile-config.el ends here. |
