[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Recurse through a directory tree in org-agenda

From: Yuri Niyazov
Subject: [O] Recurse through a directory tree in org-agenda
Date: Fri, 1 May 2015 21:22:20 -0700

It is common to have something like this in an org configuration:

(customize-set-variable 'org-agenda-files '("~/org"))

This means that all the org files in ~/org (but not all the org files
in subdirectories of "~/org") will be automatically included in the

It seems like a common request on this mailing list is: what if I
created a fairly involved directory tree with org files throughout,
how do I include all those directories in org-agenda-files? And also,
what if I modify my filesystem and create a new directory somewhere
under "~/org" - do I have to restart Emacs or rerun the code that
configures org?

Here's a solution that seems to take care of everything automatically
for me (and also filters out things that I don't want to include, like
directories named "zz_old", ".git" and "zz_journal")

(require 'find-lisp)
(require 'cl)

(defun yn/recurse-subdirectories (directory)
  (let ((predicate
         (lambda (pred)
           (lexical-let ((p pred))
            (lambda (dir parent)
              (and (not (or (string= dir ".git")
                            (string= dir "zz_old")
                            (string= dir "zz_journal")))
                   (funcall p dir parent)))))))
      (funcall predicate 'find-lisp-file-predicate-is-directory)
      (funcall predicate 'find-lisp-default-directory-predicate))
     (cons directory nil))))

(defadvice org-agenda-files (before yn/org-agenda-files
                                    (&optional unrestricted archives))
  (customize-set-variable 'org-agenda-files (yn/recurse-subdirectories

(ad-activate 'org-agenda-files)

I don't have contributor papers signed with the FSF (yet) but
obviously the intent of this message is for everyone to use this.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]