emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Recurse through a directory tree in org-agenda
@ 2015-05-02  4:22 Yuri Niyazov
  0 siblings, 0 replies; only message in thread
From: Yuri Niyazov @ 2015-05-02  4:22 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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
agenda.

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)))))))
    (append
     (find-lisp-find-files-internal
      directory
      (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
org-directory)))

(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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-05-02  4:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-02  4:22 Recurse through a directory tree in org-agenda Yuri Niyazov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).