12

I found an org tutorial where it is explained how to load org files from a folder, using

(setq org-agenda-files (list "~/org/work.org"
                             "~/org/school.org" 
                             "~/org/home.org"))

Question

Is there a way to tell emacs to load all the org files on a given folder to the agenda?

Dox
  • 497
  • 4
  • 14

2 Answers2

12

Inspired on the answer given by Aaron, I change my configuration to

(setq org-agenda-files (list "~/org"))

and the problem was solved.

Dox
  • 497
  • 4
  • 14
7

Using the Org mode included with Emacs 24.3, from C-h v org-agenda-files RET:

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.

And from C-h v org-agenda-file-regexp RET:

org-agenda-file-regexp is a variable defined in 'org.el'.
Its value is "\\`[^.].*\\.org\\'"
[...]
You can customize this variable.

So, in short: evaluate (add-to-list 'org-agenda-files (expand-file-name "~/org")) and, if your org-agenda-file-regexp is at the default value, Org mode will read agenda items from any file in ~/org whose name ends in .org. (If your org-agenda-file-regexp isn't at the default value, or if you need it to match more than just files whose names end in .org, then customize it to your needs via M-x customize-variable RET org-agenda-file-regexp RET.)

Aaron Miller
  • 9,782
  • 24
  • 39
  • Thank you for the response @aaron-miller. I'm using GNU Emacs 23.4.1 with Org-mode version 8.0.7. I found the `org-agenda-files` command, and `C-h v org-agenda-file-regexp` is defined as you mention. However I get a warning after adding the code line you suggest. Any thoughts? Should I still left my previous line or delete it? – Dox Aug 19 '13 at 17:27
  • I solved it! Thx for your help. My solution was to include the line `(setq org-agenda-files (list "~/org/"))` into my `.emacs` file. Cheers. – Dox Aug 19 '13 at 17:37
  • 2
    @Dox That's only half a solution, though, in that it will add to `org-agenda-files` only those files present in `~/org` at the time the expression is evaluated -- that is, if you add a new file during your Emacs session, it won't be automatically picked up as a source of agenda items until the next time you start Emacs. Of course, if that suffices for your needs, then go for it, but it's worth mentioning that `org-agenda-file-regexp`, and the special handling of directories in `org-agenda-files`, exist for a reason. :) – Aaron Miller Aug 19 '13 at 18:05
  • Could you provide an example of the solution? I check and the `org-agenda-file-regexp` is set to the default value, but you are right about the loading. – Dox Aug 19 '13 at 18:16
  • 2
    @Dox That's good! Assuming that all your Org files are in `~/org` and end in `.org`, all you need to do is add `(add-to-list 'org-agenda-files (expand-file-name "~/org"))` to your init file somewhere, and new Emacs sessions will automatically scan all your Org files for agenda items. (You can get the same effect in your existing Emacs session by doing `C-x C-e` while point is on the closing paren of the expression; then, to see the effect, do e.g. `M-x org-agenda RET t`.) – Aaron Miller Aug 19 '13 at 20:06
  • 1
    @Dox BTW `expand-file-name` canonicalizes its argument, in this case by expanding the `~` to your full home directory path; not every Emacs Lisp function which takes a path argument does its own canonicalization, so it's useful to do so by hand. `C-x C-e` does `eval-last-sexp`, which evaluates the Lisp form immediately behind point -- useful when you're editing init files, for example, to test the effect of a change and to get the benefit without having to restart Emacs or `M-x eval-buffer`. – Aaron Miller Aug 19 '13 at 20:08
  • let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/10210/discussion-between-dox-and-aaron-miller) – Dox Aug 19 '13 at 20:20