Reputation: 507
In .emacs I have
(org-agenda-files (quote ("d:/GTD/a.org" "d:/GTD/b.org" "d:/GTD/c.org")))
In this three file I can have links to other org files. Is it possible (on the fly, using current buffers) scan a.org, b.org, c.org and add links to org-agenda-files?
Update 1.
There is one possibility. Linked files are in several well-defined folders. On How to add .org files under org-directory to agenda is instructions on how to add all file. Is there any way to add to the org-agenda-files only those that are linked in a.org, b.org, c.org?.
Update 2.
I don't know why, but function became visible in emacs after the addition of (interactive). Full code of that function:
(defun add-links-to-org-agenda-files ()
(interactive)
(org-element-map
(org-element-parse-buffer)
'link
(lambda (x)
(if (equal (org-element-property :type x) "file")
(add-to-list 'org-agenda-files (org-element-property :path x))))))
Regards
Krzysiek
Upvotes: 2
Views: 597
Reputation: 6422
There is nothing like this built into org AFAIK. However, you should be able to write a lisp function that does this. The bare minimum would look like this:
(org-element-map
(org-element-parse-buffer)
'link
(lambda (x) (message (org-element-property :path x))))
That selects all link elements from the parse tree of the current buffer and applies a function to each one. The function selects the path property of each link and prints it out in the echo area. You'd want to add code to select links of type "file" only and you'd want the function to add them to org-agenda-list, if they are not there already. Here's a function that does this much - note that you would have to apply this function to each file of your org-agenda-files list, which is left as an exercise:
(defun add-links-to-org-agenda-files ()
(org-element-map
(org-element-parse-buffer)
'link
(lambda (x)
(if (equal (org-element-property :type x) "file")
(add-to-list 'org-agenda-files (org-element-property :path x))))))
See the org-element API page for more information.
Upvotes: 3