Loading all org files on a folder to agenda

8,900

Solution 1

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

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

and the problem was solved.

Solution 2

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

Share:
8,900

Related videos on Youtube

Dox
Author by

Dox

Updated on September 18, 2022

Comments

  • Dox
    Dox over 1 year

    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
    Dox over 10 years
    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
    Dox over 10 years
    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.
  • Aaron Miller
    Aaron Miller over 10 years
    @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. :)
  • Dox
    Dox over 10 years
    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.
  • Aaron Miller
    Aaron Miller over 10 years
    @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
    Aaron Miller over 10 years
    @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.
  • Dox
    Dox over 10 years