7

I have a problem with org-mode's agenda view. While I've set org-agenda-files to '("~/org/") invariably when I finally spin up M-x org-agenda I find that org-agenda-files just points to one org-file. Obviously something is deciding just to include the last org-file I viewed but I'm having trouble working out what. Is there any way to trap when this variable is changed and display or log some sort of backtrace?

5
  • From the org-agenda-files docstring, "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." By default, that regexp matches all files with .org extension in that directory. Can you tell how you have your .org files organized? Do they belong in the ~/org/ folder directly? Or are they in sub-directories under that? Commented Sep 26, 2014 at 12:28
  • ageneda -> agenda Commented Sep 26, 2014 at 13:14
  • @kaushalmodi: yeah, my ~/org/ is full of org files each with a bunch of TODOs in them (I have one per "topic" with an index.org).
    – stsquad
    Commented Sep 26, 2014 at 13:25
  • What version of org are you using? Also could you do the following to test: Run emacs -q then in scratch point to your installation of Org (add-to-list 'load-path "path/to/org") if from ELPA or Git, if using built-in you can disregard. Then in scratch (require 'org) (setq org-agenda-files "~/org/") (org-agenda nil "t"). See if your TODOs all show up. Commented Sep 26, 2014 at 14:25
  • @JonathanLeech-Pepin: Latest org for the org ELPA archive (current 8.2.7c on this box).
    – stsquad
    Commented Sep 28, 2014 at 18:22

4 Answers 4

6

In this situation, I find that the best way to figure out what's going on into is to visit my ~/.emacs.d/ and run rgrep.

Searching your configs

The following snippet, taken from here, makes sure that rgrep doesn't go into the elpa/ subdir (since you're sure to find dozens of useless hits in there).

(eval-after-load 'grep
  '(progn
     (add-to-list 'grep-find-ignored-directories "auto")
     (add-to-list 'grep-find-ignored-directories "elpa")))

Then I just run

M-x rgrep RET org-agenda-files RET *.el RET ~/.emacs.d/

which will find any reference to org-agenda-files in my configuration. If it's a problem with my configs, this will find it.

Searching Elsewhere

If the above doesn't find anything, it means there's an Elpa package causing trouble. So I do

M-x rgrep RET org-agenda-files RET *.el RET ~/.emacs.d/elpa/

This will usually yield a lot of results, but there are ways to go through them quickly. For instance, it's very unlikely that org-mode itself is causing this problem. So it's safe to ignore all hits that come from inside org-modes installation directory.

2
  • 1
    Sadly the only place I find it referenced (apart from my config set-up) is in the ELPA version of org. Hence wondering if there was a better way to trap when org updated it.
    – stsquad
    Commented Sep 26, 2014 at 13:29
  • Mystery solved! In the end I found the offending line in ~/.emacs.d/my-custom.el which is what custom-file points at. As this is loaded at the end of my init.el it was over-writing what my-org.el had set up. Also as my elisp files are in a sub-dir why I didn't find it earlier.
    – stsquad
    Commented Oct 29, 2014 at 14:53
3

Another option you have is to track the value of this variable throughout the execution of org-agenda, that has to tell you where the problem is.

  1. Evaluate the following code:

    (global-set-key [f1] (lambda () (interactive) (message "%s" org-agenda-files)))
    
  2. Visit the function with M-x find-function RET org-agenda.

  3. Edebug it with C-u C-M-x.
  4. Call the function, M-x org-agenda.
  5. Gradually step through it by pressing n, and monitor the value of the variable by hitting F1.

At some point inside the org-agenda function, you'll hit F1 and the value of org-agenda-files will have changed. That will tell you where to look.

1
  • 1
    You could also redefine the function with a bunch of messages, if you don't want to Edebug.
    – Malabarba
    Commented Sep 26, 2014 at 22:46
3

Since 26.1, you can use add-variable-watcher to track the variable where and how be changed.

 Function: add-variable-watcher symbol watch-function

Because the watch-function will be called with 4 arguments: symbol, newval, operation, and where, you can simply add a watcher in your init.el, for example,

(add-variable-watcher 'tab-width (lambda (&rest x) (message "Oops! tab-width changed: %S" x)))

which gives you some messages like

Oops! tab-width changed: (tab-width 2 set #<buffer xxx.el>)
2

Are you ever using C-c [ (org-agenda-file-to-front) or C-c ] (org-remove-file) while in an org file?

These overwrite the current org-agenda-files with a hardcoded list of files that will no longer use your defined ~/org/ as a source.

Also if you are setting it to ~/org/ please ensure that the agenda files you want are in that folder with .org for the extension. Otherwise they will not be detected.

2
  • I'd like to add that if you don't expect the list of agenda files to change very frequently, it's better to add that list of files to something like ~/org/agenda.files and set org-agenda-files to ~/org/agenda.files. Commented Sep 26, 2014 at 12:38
  • Not consciously. Indeed they are not mapped to useful keys for me.
    – stsquad
    Commented Oct 16, 2014 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.