From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yuri Niyazov Subject: Recurse through a directory tree in org-agenda Date: Fri, 1 May 2015 21:22:20 -0700 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YoOx3-0002FQ-W3 for emacs-orgmode@gnu.org; Sat, 02 May 2015 00:22:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YoOx3-0008T4-0C for emacs-orgmode@gnu.org; Sat, 02 May 2015 00:22:53 -0400 Received: from mail-la0-x22e.google.com ([2a00:1450:4010:c03::22e]:35495) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YoOx2-0008Sy-O5 for emacs-orgmode@gnu.org; Sat, 02 May 2015 00:22:52 -0400 Received: by labbd9 with SMTP id bd9so74732599lab.2 for ; Fri, 01 May 2015 21:22:51 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org 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.