From: Suvayu Ali <fatkasuvayu+linux@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: How to let Org Agenda search all files in a directory *recursively* ?
Date: Fri, 28 Jun 2013 01:40:26 +0200 [thread overview]
Message-ID: <20130627234026.GD17935@kuru.dyndns-at-home.com> (raw)
In-Reply-To: <20130627075135.GA4761@stardiviner>
On Thu, Jun 27, 2013 at 03:53:53PM +0800, chris wrote:
> I want to set up Org-mode variable "org-agenda-files".
>
> How to Let [C-c a] to search over all files in a directory *recursively* ?
You can try this function:
;; recursively find .org files in provided directory
;; modified from an Emacs Lisp Intro example
(defun find-org-file-recursively (directory &optional filext)
"Return .org and .org_archive files recursively from DIRECTORY.
If FILEXT is provided, return files with extension FILEXT instead."
(interactive "DDirectory name: ")
(let* (org-file-list
(case-fold-search t) ; filesystems are case sensitive
(fileregex (if filext (format "^[^.#].*\\.\\(%s$\\)" filext)
"^[^.#].*\\.\\(org$\\|org_archive$\\)"))
(cur-dir-list (directory-files directory t "^[^.#].*"))) ; exclude .*
;; loop over directory listing
(dolist (file-or-dir cur-dir-list org-file-list) ; returns org-file-list
(cond
((file-regular-p file-or-dir) ; regular files
(if (string-match fileregex file-or-dir) ; org files
(add-to-list 'org-file-list file-or-dir)))
((file-directory-p file-or-dir)
(dolist (org-file (find-org-file-recursively file-or-dir filext)
org-file-list) ; add files found to result
(add-to-list 'org-file-list org-file)))))))
I'm pretty sure there are a few bugs, so test well.
--
Suvayu
Open source is the future. It sets us free.
prev parent reply other threads:[~2013-06-27 23:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-27 7:53 How to let Org Agenda search all files in a directory *recursively* ? chris
2013-06-27 13:20 ` J. David Boyd
2013-06-27 13:57 ` Nick Dokos
2013-06-27 14:32 ` Nicolas Richard
2013-06-27 17:53 ` J. David Boyd
2013-06-27 19:03 ` Nicolas Richard
2013-06-27 21:22 ` J. David Boyd
2013-06-27 23:40 ` Suvayu Ali [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130627234026.GD17935@kuru.dyndns-at-home.com \
--to=fatkasuvayu+linux@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.