5

I want to specify a default output file for all my tangle exports. I'm using Org mode 8.x. (For Org mode ≥9.0, see How to tangle all code blocks to a common file)

This works:

#+BEGIN_SRC js :tangle "../js/out_file.js"
console.log("hello from org mode");
#+END_SRC
** 
#+BEGIN_SRC js :tangle "../js/out_file.js"
console.log("hello from org mode 2");
#+END_SRC

However, I don't want to keep repeating "../js/out_file.js" on each block.

I've looked at these following two links, which seem to be asking essentially the same question:

link 1

link 2

However, none of the recommendations work: If I just have a SRC block with no tangle arg, I get either "Tangled 0 code blocks from dummy.org" or "Wrote ./org/dummy.org" (which is the default file name)

Here's my final code. Currently, all the methods are uncommented, so it's possible they are interfering with each other, but I have tried each method in isolation to the same effect:

* Header

# method 1
:PROPERITES:
:tangle: "../out_file.js"
:END:

# method 2
#+TANGLE: "../js/out_file.js"

# method 3
#+BABEL: :tangle "../js/out_file.js" 

# method 4
#+PROPERTY: header-args+ :tangle  "../js/out_file.js" 

# method 5
#+PROPERTY: header-args :session *my_js_session* :results silent :tangle "../js/out_file.js" 

** some js source
#+BEGIN_SRC js
console.log("hello from org mode");
#+END_SRC
** 
#+BEGIN_SRC js 
console.log("hello from org mode 2");
#+END_SRC

Can anyone see what I'm doing wrong?

Do I have to somehow evaluate the properties before they take effect?

Are there any org commands I can issue to verify if the properties are properly set?

  • You've misspelled your first example, perhaps that it. I'm using a similiar method for my init.org, with :header-args:emacs-lisp: :tangle ../.emacs instead of :tangle:. – wasamasa Jun 16 '15 at 9:04
  • Use #+PROPERTY: tangle "~/.path/file.js". Put the cursor on it and C-c C-c it should give you Local setup has been refreshed message in minibuffer. Tangle a file with C-c C-v t (org-babel-tangle). It works for sure, because that is how I generate my dotfiles ;) – kmicu Jun 16 '15 at 17:06
  • Bingo. That's it. Thanks for mentioning the "C-c C-c" part. That might have been the part I was missing all along. Thank you so much. – vt5491 Jun 17 '15 at 1:40
  • Possible duplicate of How to tangle all code blocks to a common file – mankoff Mar 29 '18 at 5:52
  • @mankoff Not everyone is using the latest version, so this question is still relevant. It just needs to be clarified so people know which version it applies to. – Gilles 'SO- stop being evil' Mar 29 '18 at 20:36
6

To set ‘tangle file’ globally we should use #+PROPERTY: tangle "~/.path/to/file.extension".

Unfortunatelly, that change is not enough; we need to trigger a refresh. We put cursor on that line and press C-c C-c which gives Local setup has been refreshed message in a minibuffer (or in *Messages* buffer). We could also reopen file which applies new settings. C-c C-c is a binding for org-ctrl-c-ctrl-c — a ‘swiss knife’ org-mode function which

If the cursor is in one of the special #+KEYWORD lines, this triggers scanning the buffer for these lines and updating the information.

Now, when our changes are ready we can C-c C-v t (or C-c C-v C-t; or M-x org-babel-tangle) to tangle our file.

We can read more about specifying header arguments (not only at global level) at org manual page.

  • 6
    Note it does not work in org-mode v9 any more. Now it is #+PROPERTY: header-args :tangle "~/file/path" – RNA Mar 3 '17 at 1:10

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.