Now, I've checked many questions here to get an answer for what I want, but every question seems a bit different that that what I need. I use org-babel to create an init file. I often change my config and want to use it on multiple machines. Most path in the .org are relative to the home so no problem there, but some are not and some can't even deal with relative path since they are used in a shell script. So I want to define path-replacement variables at the the beginning.

Example: System 1:

(setq org-download-screenshot-file "Z:/Temp/screenshot.png")
(setq org-ditaa-jar-path "Z:/Tools/Ditaa/ditaa0_9.jar")

System 2:

(setq org-download-screenshot-file "C:/Temp/screenshot.png")
(setq org-ditaa-jar-path "C:/!Portable/Ditaa/ditaa0_9.jar")

What I need is something like:

(setq my-relative-path-one "Z:/Temp")
(setq my-relative-path-two "Z:/Tools/Ditaa")

So I can use the configuration below for both systems, just replacing the value of my-relative-path-xxx would be needed. I would then place the path matching variables in a different org file which is loaded before the main org configuration file. This would allow me to sync the main configuration file without paying attention to the path values.

(setq org-download-screenshot-file "my-relative-path-one/screenshot.png")
(setq org-ditaa-jar-path "my-relative-path-two/ditaa0_9.jar"

Thanks for any suggestion. With kind regards, Jens Lange

  • You could try (setenv "RELATIVE_PATH_ONE" "z:/Temp") followed by (setq org-download-screenshot (substitute-in-file-name "${RELATIVE_PATH_ONE}/screenshot.png")) if you want this variable also to be accessible to shell / other programs run from Emacs.
    – wvxvw
    Sep 28, 2017 at 13:05
  • What you are calling "path" is what Emacs calls the directory part of an absolute file name. In Emacs, a "path" is the kind of thing you see in environment variable PATH.
    – Drew
    Sep 28, 2017 at 14:02
  • Drew, although I use emacs now for 1,75 years I still seem to learn the lingua. Thanks for clarifying that.
    – Jens Lange
    Sep 30, 2017 at 1:04
  • Wvxvw, I'll keep that information for later, maybe I need it someday. Currently I would go with the solution below. The org-download-screenshot function excutes a shell script, which works with the solution below. Currently I don't need to execute scripts directly, but maybe later.
    – Jens Lange
    Sep 30, 2017 at 1:08

1 Answer 1


Why not just

(setq my-relative-path-one "Z:/Temp/")
(setq my-relative-path-two "Z:/Tools/Ditaa/")

(setq org-download-screenshot-file (concat my-relative-path-one "screenshot.png"))
(setq org-ditaa-jar-path (concat my-relative-path-two "ditaa0_9.jar"))

You can use format similarly - instead of concat, do:

(format "%s/screenshot.png" my-relative-path-one)
  • Thanks, that will help me a lot. The concat version worked. Tried the format version first but somehow emacs was not interested in formating. The value stayed at "~s/screenshot.png" Finally I can generate a generic configuration file that works on every machine I use.
    – Jens Lange
    Sep 30, 2017 at 0:59
  • Sorry about that - I've been using scheme a bit recently, which confused my answer. The special format character in emacs-lisp is %, not ~. Answer corrected.
    – dieggsy
    Oct 2, 2017 at 11:00

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.