3

I have started using org-babel for a larger project, and have found the readthedocs to be a great resource. I have been using tangling to generate code from documentation, however setting the export filename using :tangle is gettting cumbersome, since for each block I need to set all of the relative paths and whatnot.

I know that setting the :dir header argument allows you to choose what directory code blocks will be executed in, but it does not set the tangle directory. Ideally I would like to have something like this:

#+STARTUP: showall
#+PROPERTY: header-args :dir "/home/user/project/path1/path2/path3"

* Test

** myfile.h
:PROPERTIES:
:header-args: :tangle filename1.cpp :no-expand t
:END:
#+BEGIN_SRC C++

#+END_SRC
** myotherfile.cpp
:PROPERTIES:
:header-args: :tangle filename2.cpp :no-expand t
:END:
#+BEGIN_SRC C++

#+END_SRC

Rather than:

#+STARTUP: showall

* Test

** myfile.h
:PROPERTIES:
:header-args: :tangle ../../path2/path3 :no-expand t
:END:
#+BEGIN_SRC C++

#+END_SRC
** myotherfile.cpp
:PROPERTIES:
:header-args: :tangle ../../filename2.cpp :no-expand t
:END:
#+BEGIN_SRC C++

#+END_SRC

Imagine how frustrating this could get if another person takes over the project, or one needs to change the directory layout? I have poked around various sources but haven't found a way to do this. This question is related, but doesn't solve my issue

2
  • I could be wrong but a quick perusal of the documentation and the org-babel-tangle code did not uncover a method for doing this. You may be able to do what you want with a function added to org-babel-post-tangle-hook. Or you can submit an RFE to the org-mode mailing list.
    – NickD
    Jun 2, 2018 at 14:56
  • On second thought, submit an RFE: the post-tangle hook method gets very hairy very fast.
    – NickD
    Jun 2, 2018 at 15:10

1 Answer 1

2

I had this problem and I solved by executing elisp code in tangle setting

* Project Header
:PROPERTIES:
:PRJ-DIR: ~/prj/dir/
:END:

#+BEGIN_SRC js :tangle (concat (org-entry-get nil "PRJ-DIR" t) "filename.js")
  var a = 2;
#+END_SRC

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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