emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to let Org Agenda search all files in a directory *recursively* ?
@ 2013-06-27  7:53 chris
  2013-06-27 13:20 ` J. David Boyd
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: chris @ 2013-06-27  7:53 UTC (permalink / raw)
  To: Emacs Org-mode

[-- Attachment #1: Type: text/plain, Size: 419 bytes --]

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* ?

-- 
E M A C S
s e l o h
c t t n i
p a   t f
a     r t
e     o
      l

[ stardiviner ] ^^&^^ {I hate all of you !  Leave me alone}
IRC(freenode): stardiviner     \\ Twitter:  @numbchild \\
GnuPG Key fingerprint
    >>> 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to let Org Agenda search all files in a directory *recursively* ?
  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 23:40 ` Suvayu Ali
  2 siblings, 1 reply; 8+ messages in thread
From: J. David Boyd @ 2013-06-27 13:20 UTC (permalink / raw)
  To: emacs-orgmode

chris <numbchild@gmail.com> writes:

> 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* ?

It's in the doc help for org-agenda-files:

   The files to be used for agenda display.
   Entries may be added to this list with M-x org-agenda-file-to-front and removed with
   M-x org-remove-file.  You can also use customize to edit the list.
   
   If an entry is a directory, all files in that directory that are matched by
   `org-agenda-file-regexp' will be part of the file list.
   
   If the value of the variable is not a list but a single file name, then
   the list of agenda files is actually stored and maintained in that file, one
   agenda file per line.  In this file paths can be given relative to
   `org-directory'.  Tilde expansion and environment variable substitution
   are also made.

So just set it to be a directory, as I do.

Dave

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to let Org Agenda search all files in a directory *recursively* ?
  2013-06-27 13:20 ` J. David Boyd
@ 2013-06-27 13:57   ` Nick Dokos
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Dokos @ 2013-06-27 13:57 UTC (permalink / raw)
  To: emacs-orgmode

david@adboyd.com (J. David Boyd) writes:

> chris <numbchild@gmail.com> writes:
>
>> How to Let [C-c a] to search over all files in a directory *recursively* ?
>
> It's in the doc help for org-agenda-files:
>
>    ...
>    If an entry is a directory, all files in that directory that are matched by
>    `org-agenda-file-regexp' will be part of the file list.
>    ...
>    
> So just set it to be a directory, as I do.
>

That's not going to work *recursively*, unless all the subdirectory names
match org-agenda-file-regexp as well (and I'm not sure it is going to
work even if that is the case - haven't tried it).

-- 
Nick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to let Org Agenda search all files in a directory *recursively* ?
  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 14:32 ` Nicolas Richard
  2013-06-27 17:53   ` J. David Boyd
  2013-06-27 23:40 ` Suvayu Ali
  2 siblings, 1 reply; 8+ messages in thread
From: Nicolas Richard @ 2013-06-27 14:32 UTC (permalink / raw)
  To: Emacs Org-mode

chris <numbchild@gmail.com> writes:

> How to Let [C-c a] to search over all files in a directory *recursively* ?

AFAIK, there's no built in way.

Applying the following patch to the function org-agenda-files gets you
there, but it's not clean at all, and certainly very unefficient :

	Modified   lisp/org.el
diff --git a/lisp/org.el b/lisp/org.el
index 7fd1576..0068c49 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17797,8 +17797,7 @@ used by the agenda files.  If ARCHIVE is `ifmode', do this only if
     (setq files (apply 'append
 		       (mapcar (lambda (f)
 				 (if (file-directory-p f)
-				     (directory-files
-				      f t org-agenda-file-regexp)
+				     (find-lisp-find-files f org-agenda-file-regexp)
 				   (list f)))
 			       files)))
     (when org-agenda-skip-unavailable-files

Also it might be faster to rely on an external "find" tool but that requires
modifying the regexp (-regex applies to whole path).

HTH,

-- 
N.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: How to let Org Agenda search all files in a directory *recursively* ?
  2013-06-27 14:32 ` Nicolas Richard
@ 2013-06-27 17:53   ` J. David Boyd
  2013-06-27 19:03     ` Nicolas Richard
  0 siblings, 1 reply; 8+ messages in thread
From: J. David Boyd @ 2013-06-27 17:53 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:

> chris <numbchild@gmail.com> writes:
>
>> How to Let [C-c a] to search over all files in a directory *recursively* ?
>
> AFAIK, there's no built in way.
>
> Applying the following patch to the function org-agenda-files gets you
> there, but it's not clean at all, and certainly very unefficient :
>
> 	Modified   lisp/org.el
> diff --git a/lisp/org.el b/lisp/org.el
> index 7fd1576..0068c49 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -17797,8 +17797,7 @@ used by the agenda files.  If ARCHIVE is `ifmode', do this only if
>      (setq files (apply 'append
>  		       (mapcar (lambda (f)
>  				 (if (file-directory-p f)
> -				     (directory-files
> -				      f t org-agenda-file-regexp)
> +				     (find-lisp-find-files f org-agenda-file-regexp)
>  				   (list f)))
>  			       files)))
>      (when org-agenda-skip-unavailable-files
>
> Also it might be faster to rely on an external "find" tool but that requires
> modifying the regexp (-regex applies to whole path).
>
> HTH,

Huh, when I set my org-agenda-files to ~/org/, and have TODO files in
~/org/home and ~/org/work, and press C-c a a, it loads all the todo file,
recursed down to all the subdirectories.

However, and this is strange, after it loads them all up, it changes
org-agenda-files to discrete filepaths, and not just the directory anymore.

That seems like a bug to me....

Dave

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to let Org Agenda search all files in a directory *recursively* ?
  2013-06-27 17:53   ` J. David Boyd
@ 2013-06-27 19:03     ` Nicolas Richard
  2013-06-27 21:22       ` J. David Boyd
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Richard @ 2013-06-27 19:03 UTC (permalink / raw)
  To: J. David Boyd; +Cc: emacs-orgmode

david@adboyd.com (J. David Boyd) writes:
> Huh, when I set my org-agenda-files to ~/org/, and have TODO files in
> ~/org/home and ~/org/work, and press C-c a a, it loads all the todo file,
> recursed down to all the subdirectories.
>
> However, and this is strange, after it loads them all up, it changes
> org-agenda-files to discrete filepaths, and not just the directory anymore.

It's what happens for me too, but I specifically wrote some elisp to do
that in my .emacs. Can you reproduce from -Q ?

-- 
N.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to let Org Agenda search all files in a directory *recursively* ?
  2013-06-27 19:03     ` Nicolas Richard
@ 2013-06-27 21:22       ` J. David Boyd
  0 siblings, 0 replies; 8+ messages in thread
From: J. David Boyd @ 2013-06-27 21:22 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:

> david@adboyd.com (J. David Boyd) writes:
>> Huh, when I set my org-agenda-files to ~/org/, and have TODO files in
>> ~/org/home and ~/org/work, and press C-c a a, it loads all the todo file,
>> recursed down to all the subdirectories.
>>
>> However, and this is strange, after it loads them all up, it changes
>> org-agenda-files to discrete filepaths, and not just the directory anymore.
>
> It's what happens for me too, but I specifically wrote some elisp to do
> that in my .emacs. Can you reproduce from -Q ?

emacs -Q didn't work at all, so I went digging into my config file.

Here's what recursively loads .org files for me.  I don't remember when I
added this, but it's been a while...

In my emacs-init.org file, I have:


(add-hook 'org-agenda-mode-hook
    (lambda ()
        (setq org-agenda-files
            (find-lisp-find-files "~/org" "\.org$")
        )
    )
)



So no matter what I might type into the org-agenda-files in customize, this is
what really runs.   And it works fine too.  I think I got this code from Sacha
Chua, but I'm not certain.

Dave

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to let Org Agenda search all files in a directory *recursively* ?
  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 14:32 ` Nicolas Richard
@ 2013-06-27 23:40 ` Suvayu Ali
  2 siblings, 0 replies; 8+ messages in thread
From: Suvayu Ali @ 2013-06-27 23:40 UTC (permalink / raw)
  To: emacs-orgmode

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-06-27 23:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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