I am writing an org file that org babel will tangle into "custom.el" as shown here and here.
My problem is that on one machine the path to my agenda files is C:/Users/Username/Dropbox/file.org
while on anther machine it is C:/Users/DifferentUserName/Dropbox/file.org
.
I can setq the org-directory to the the correct path on different machines with:
(setq org-directory
(car ;; with car returned value is type 'string' witout car returned type is 'cons'
(delq nil
(mapcar (lambda(x) (and (file-directory-p x) x))
'("c:/Users/marka/Dropbox/Apps/OrgMode"
"c:/Users/Mark/Dropbox/Apps/OrgMode"
"c:/Users/msmith/Dropbox/Apps/OrgMode")))))
With a single agenda file, using concat (concat org-directory "/gtd_work.org")
returns the desired path to the agenda file "c:/Users/Mark/Dropbox/Apps/OrgMode/gtd_work.org"
.
Unfortunately multiple uses of the concat
function when nested in the setq
appears to stop functioning:
> (setq org-agenda-files
> '((concat org-directory "/gtd_work.org")
> (concat org-directory "/gtd_proging.org")
> (concat org-directory "/gtd_home.org")
> (concat org-directory "/DailyRoutine.org")))
Using C-h v
to find the value of org-agenda-files
yields:
org-agenda-files is a variable defined in `org.el'.
Its value is ((concat org-directory "/gtd_work.org")
(concat org-directory "/gtd_proging.org")
(concat org-directory "/gtd_home.org")
(concat org-directory "/DailyRoutine.org"))
Additionally I have tried:
- Removing the single quote in the
setq
, this raises anInvalid function: (concat org-directory "/gtd_work.org")
exception. mapcar
andmapc
raiseWrong type argument: stringp, (concat org-directory "/gtd_work.org")
exceptions.- Using
~/file.org
without concat returns nil
I am doing this in scratch right now as config.org is w.i.p. Will org concat the path to the agenda files? Am I not using concat correctly? If I write out the full path for each file on each computer and use (mapcar (lambda (x) (and (file-exists-p x) x))
it will correctly select the machine specific path, however, this results in the first world problem of having to specify 20~40 paths rather than 8~12.
Solution by amitp below works for both the setq
and for the:
(setq org-agenda-files
(delq nil
(mapcar (lambda (x) (and (file-exists-p x) x))
Thanks everyone for the help.
(x-server-version)
and/or use other methods to distinguish the OS, etc. -- e.g.,system-type
;feature-p 'ns
, etc. That way, the paths will be programmatically adjusted depending upon which computer you are using. To synchronize, I usersync
instead of Dropbox and I do it manually as needed. I sync my whole installation to desktops and laptops, and to an iPhone (backup) and up to a shared web server (backup).,(concat ....)
Perhaps @amitp could update the answer with another example.… `(,(concat …) ,(concat …))
will be the same as(list (concat …) (concat …))
in this case. Backtick/comma is useful when you want to partially quote something, but some piece of it you want to evaluate without the quotes.