Rework agenda files code

This commit is contained in:
Kiana Sheibani 2024-03-07 01:43:29 -05:00
parent 70d411a4c8
commit 7a020bfd68
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -2807,39 +2807,31 @@ The ~org-agenda~ dispatcher is occasionally useful, but most of the time when I
*** Agenda Files *** Agenda Files
I have a lot of different subdirectories and groupings in my org directory, but unfortunately directories listed in ~org-agenda-files~ aren't checked recursively! I haven't yet found out how to solve this problem directly, so instead I'm going to mitigate it somewhat by recursively adding every subdirectory of my org directory to ~org-agenda-files~. I have a lot of different subdirectories and groupings in my org directory, but unfortunately directories listed in ~org-agenda-files~ aren't checked recursively! We can solve this by creating a function ~org-agenda-files-function~ to return the agenda files, then advising Org to call that function before getting the agenda files.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun directory-dirs (dirs) (defun directory-dirs (dir)
"Recursively find all subdirectories of DIRS, ignoring dotfiles." "Recursively find all subdirectories of DIR, ignoring dotfiles."
(when dirs (let* ((dir (directory-file-name dir))
(let (result) (files (directory-files dir nil nil t))
(dolist (dir dirs) (dirs (list dir)))
(let ((dir (directory-file-name dir)) (dolist (file files)
(files (directory-files dir nil nil t))) (unless (= (aref file 0) ?.)
(dolist (file files) (let ((file (concat dir "/" file)))
(unless (= (aref file 0) ?.) (when (file-directory-p file)
(let ((file (concat dir "/" file))) (appendq! dirs (directory-dirs file))))))
(when (file-directory-p file) dirs))
(setq result (cons file result))))))))
(append dirs (directory-dirs result))))) (defun org-agenda-files-function ()
(directory-dirs org-directory))
(defvar org-agenda-files-function #'org-agenda-files-function (defvar org-agenda-files-function #'org-agenda-files-function
"The function to determine the org agenda files.") "The function to determine the org agenda files.")
(defun org-agenda-files-function (get-dirs) (defadvice! ~/org-agenda-files (&rest _)
(funcall get-dirs (list org-directory))) "Set `org-agenda-files' before Org fetches them."
:before #'org-agenda-files
(defun ~/org-agenda-files-update (&optional fn) (setq org-agenda-files (funcall org-agenda-files-function)))
"Populate `org-agenda-files' with the result of calling FN, or
`org-agenda-files-function' by default."
(interactive)
(unless fn
(setq fn org-agenda-files-function))
(setq org-agenda-files (funcall fn #'directory-dirs)))
(after! org (~/org-agenda-files-update))
#+end_src #+end_src
** Citations ** Citations