6

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)
Picaud Vincent
  • 1,158
  • 8
  • 20
  • elisp tag doesn't apply here. https://emacs.stackexchange.com/tags/elisp/info – Muihlinn May 21 '20 at 06:51
  • @Muihlinn you are right, sorry I removed it – Picaud Vincent May 21 '20 at 06:55
  • 2
    Does this answer your question? [How to include other .org files programmatically (ie not from main .org file)?](https://emacs.stackexchange.com/questions/7438/how-to-include-other-org-files-programmatically-ie-not-from-main-org-file) – erikstokes May 21 '20 at 15:52
  • @erikstokes I do not think the question/answer are the same, on my side I wanted to **define my setup file path** programmatically, but the other question/answer deals with **inserting some code** programmatically. These are close but not similar approaches. I have updated my question title with "path" to make this difference more visible. – Picaud Vincent May 25 '20 at 16:48

1 Answers1

5

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...
Picaud Vincent
  • 1,158
  • 8
  • 20