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?
4 Answers
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.
-
1Sadly 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.– stsquadCommented 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.– stsquadCommented Oct 29, 2014 at 14:53
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.
Evaluate the following code:
(global-set-key [f1] (lambda () (interactive) (message "%s" org-agenda-files)))
Visit the function with
M-x find-function RET org-agenda
.- Edebug it with
C-u C-M-x
. - Call the function,
M-x org-agenda
. - Gradually step through it by pressing
n
, and monitor the value of the variable by hittingF1
.
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.
-
1You could also redefine the function with a bunch of messages, if you don't want to Edebug. Commented Sep 26, 2014 at 22:46
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>)
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.
-
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 setorg-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.– stsquadCommented Oct 16, 2014 at 11:57
org-agenda-files
docstring, "If an entry is a directory, all files in that directory that are matched byorg-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?org
are you using? Also could you do the following to test: Runemacs -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.