24

I'm tying to set default header arguments to the code blocks within my org file, like this:

#+PROPERTY: header-args  :session *my_python_session*
#+PROPERTY: header-args  :results silent
#+PROPERTY: header-args  :tangle yes

My code blocks look like this:

#+BEGIN_SRC python
  import pandas as pd
#+END_SRC

However, when I call org-babel-tangle from this buffer, I get Tangled 0 code blocks from filename.org. When I add :tangle yes to the end of the #+BEGIN_SRC line, the code block is exported when I call org-babel-tangle.

I would expect that I don't need to set :tangle yes on each code block. What am I doing wrong?

andreas-h
  • 1,559
  • 13
  • 22

2 Answers2

35

You should have every header argument in one line:

#+PROPERTY: header-args :session *my_python_session* :results silent :tangle yes

Having several #+PROPERTY lines is accepted, but not in the way you're trying to do it.

From the Org manual (7.1 Property syntax):

If you want to add to the value of an existing property, append a ‘+’ to the property name. The following results in the property ‘var’ having the value “foo=1 bar=2”.

#+PROPERTY: var  foo=1
#+PROPERTY: var+ bar=2

So, since header-args is the property and :session, :results and :tangle are its values, it should be:

#+PROPERTY: header-args :session *my_python_session*
#+PROPERTY: header-args+ :results silent
#+PROPERTY: header-args+ :tangle yes

But it's easier to have just one line IMO.

Aaron Hall
  • 419
  • 1
  • 6
  • 20
undostres
  • 1,793
  • 12
  • 15
  • 7
    to append org-babel headers for a specific language, the plus goes after the language name e.g., `:header-args:shell+: :dir /workdir` – jfs Sep 06 '19 at 04:35
  • 1
    Use C-c C-c to evaluate the #+PROPERTY: entries for the current file if you've just typed those lines. – spazm Mar 31 '21 at 03:51
3

Been hit by this a few times, so here is my workings:

Some text before the properties, this should according to
the manual, prevent properties from working...
- Seems to work fine - which I like.

# These work for 'shell' only, not 'sh'.
#+PROPERTY: header-args:shell :var propC_headArgsCshell_0="1st"
#+PROPERTY: header-args:shell+ :var propC_headArgsCshellY_1="dc=example,dc=com"
#+PROPERTY: header-args:shell+ :var propC_headArgsCshellY_2="cn=Manager"
#
# While these apply to all:
#+PROPERTY: header-args  :var propC_headArgs_Cvar_1="dc0example,dc=com"
#+PROPERTY: header-args+ :var propC_headArgsY_Cvar_2="cn=Manager"
#
# Following does not work, yes that is as shown in the guide!
#+PROPERTY: var  propC_var_1="dc=example,dc=com"
#+PROPERTY: var+ propC_varY_2="cn=Manager"
#

#+begin_quote
Properties can be inserted on buffer level. That means they apply
before the propC_headArgsCshell_0 headline and can be inherited by all entries in a
file. Property blocks defined before propC_headArgsCshell_0 headline needs to be
located at the top of the buffer, allowing only comments above.
#+end_quote
- source [[https://orgmode.org/manual/Property-Syntax.html][Property Syntax (The Org Manual)]]


Using org-mode version
#+begin_src emacs-lisp
(org-version)
#+end_src

#+results:
: 9.4.4

* Example for shell
#+begin_src shell :var Cvar_local0='dc=example,dc=net' Cvar_local1="cn=Manager,$Cvar_local0"
echo Predict Arg Value
echo value propC_headArgsCshell_0 $propC_headArgsCshell_0
echo value Cvar_local0 $Cvar_local0
echo value Cvar_local1 $Cvar_local1
echo value! propC_var_1 $propC_var_1
echo value! propC_varY_2 $propC_varY_2
echo value propC_headArgsCshellY_1 $propC_headArgsCshellY_1
echo value propC_headArgsCshellY_2 $propC_headArgsCshellY_2
echo value propC_headArgs_Cvar_1 $propC_headArgs_Cvar_1
echo value propC_headArgsY_Cvar_2 $propC_headArgsY_Cvar_2
#+end_src

#+results:
| Predict | Arg                     | Value                   |
| value   | propC_headArgsCshell_0  | 1st                     |
| value   | Cvar_local0             | dc=example              |
| value   | Cvar_local1             | cn=Manager,$Cvar_local0 |
| value!  | propC_var_1             |                         |
| value!  | propC_varY_2            |                         |
| value   | propC_headArgsCshellY_1 | dc=example,dc=com       |
| value   | propC_headArgsCshellY_2 | cn=Manager              |
| value   | propC_headArgs_Cvar_1   | dc0example,dc=com       |
| value   | propC_headArgsY_Cvar_2  | cn=Manager              |


* Example of sh
using ~sh~ rather than shell, they are different:
#+begin_src sh  :var Cvar_local0='dc=example,dc=net' Cvar_local1="cn=Manager,$Cvar_local0"
echo predict arg value
echo blank propC_headArgsCshell_0 $propC_headArgsCshell_0
echo value Cvar_local0 $Cvar_local0
echo value Cvar_local1 $Cvar_local1
echo value! propC_var_1 $propC_var_1
echo value! propC_varY_2 $propC_varY_2
echo blank propC_headArgsCshellY_1 $propC_headArgsCshellY_1
echo blank propC_headArgsCshellY_2 $propC_headArgsCshellY_2
echo value propC_headArgs_Cvar_1 $propC_headArgs_Cvar_1
echo value propC_headArgsY_Cvar_2 $propC_headArgsY_Cvar_2
#+end_src

#+results:
| predict | arg                     | value                   |
| blank   | propC_headArgsCshell_0  |                         |
| value   | Cvar_local0             | dc=example              |
| value   | Cvar_local1             | cn=Manager,$Cvar_local0 |
| value!  | propC_var_1             |                         |
| value!  | propC_varY_2            |                         |
| blank   | propC_headArgsCshellY_1 |                         |
| blank   | propC_headArgsCshellY_2 |                         |
| value   | propC_headArgs_Cvar_1   | dc0example,dc=com       |
| value   | propC_headArgsY_Cvar_2  | cn=Manager              |

Glad to get that down.

alls0rts
  • 346
  • 3
  • 9