[O] How to let Org Agenda search all files in a directory *recursively* ?

2013-06-27 Thread chris
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


signature.asc
Description: Digital signature


Re: [O] How to let Org Agenda search all files in a directory *recursively* ?

2013-06-27 Thread J. David Boyd
chris numbch...@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




Re: [O] How to let Org Agenda search all files in a directory *recursively* ?

2013-06-27 Thread Nick Dokos
da...@adboyd.com (J. David Boyd) writes:

 chris numbch...@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




Re: [O] How to let Org Agenda search all files in a directory *recursively* ?

2013-06-27 Thread Nicolas Richard
chris numbch...@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.



Re: [O] How to let Org Agenda search all files in a directory *recursively* ?

2013-06-27 Thread J. David Boyd
Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 chris numbch...@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




Re: [O] How to let Org Agenda search all files in a directory *recursively* ?

2013-06-27 Thread Nicolas Richard
da...@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.



Re: [O] How to let Org Agenda search all files in a directory *recursively* ?

2013-06-27 Thread J. David Boyd
Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 da...@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




Re: [O] How to let Org Agenda search all files in a directory *recursively* ?

2013-06-27 Thread Suvayu Ali
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.