4

I have a project under git which allows this

#+BEGIN_SRC emacs-lisp 
(expand-file-name (car (project-roots (project-current))))
#+END_SRC

to find my project root automatically.

Now I want to use this path to automatically define my setup file location at the beginning of my regular org mode files.

The idea is:

#+SETUPFILE: (concat (expand-file-name (car (project-roots (project-current)))) "setup/setup.org")
#+TITLE: example
...

Unfortunately, this does not work as the expression (concat ...) is not interpreted as an emacs-lisp expression...

Is it possible to make it work?


update: to be sure to be able to run the provided example, please add

(require 'project)
4

I finally use this solution

src_emacs-lisp[:results raw]{(concat "#+SETUPFILE: " (expand-file-name (car (project-roots (project-current)))) "setup/setup.org")}
#+TITLE: My test

* Test...

An alternative that also works is to use a regular code block (you can define elsewhere and load with org-babel-lob-ingest in your Emacs init.el file, Config, examples and use cases of Library Of Babel )

#+NAME: Setup
#+BEGIN_SRC emacs-lisp :results drawer
(concat "#+SETUPFILE: " (expand-file-name (car (project-roots (project-current)))) "setup/setup.org")
#+END_SRC

Then in your documents, use:

#+CALL: Setup()
#+TITLE: My test

* Test...

You can check it with C-c C-e O O or equivalently by calling M-x org-org-export-as-org

You get:

# Created 2020-05-21 Thu 21:04
#+TITLE: My test
#+AUTHOR: picaud
#+SETUPFILE: /home/picaud/GitHub/Project/setup/setup.org

* Test...
| improve this answer | |
  • This is really great - I never thought to add code blocks "before" the header. Thank you for the idea! – gregoryg May 21 at 20:28
  • @gregoryg thank you! – Picaud Vincent May 21 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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