0

Trying to add default headers to org-babel blocks, but can't seem to get any of them to work.

Trying this with a shell block

(setq org-babel-default-header-args:shell
             '((:results . "verbatim")
                           ))

I tried both sh and shell (what's the difference between the two?;), but nothing happens, so try this at top level

    (add-to-list 'org-babel-default-header-args
                 '((:AUTHOR . "Your Name")
                   (:EMAIL . "[email protected]")))

Still nothing gets added to the header.

I wonder what's the process here, cause I think I'm using another method to actually create the source blocks, like this:

(add-to-list 'org-structure-template-alist '("sl" . "src elisp\n"))

I guess I can just append it to this line, but what then is the use of the org-babel-default-header-args ?;)

1 Answer 1

1

The org-babel-default-header-args define the default header args when evaluating a code block, i.e. they define the arg(s) used when not setting the header arg for the source block by passing (typing it in the header) it explicitly.

You can see that it works by trying with:

(setq org-babel-default-header-args:shell
      '((:results . "raw")))

where you will find that the result gets printed without the colon (:) in front of it. Of course to see that setting the verbatim also works, you should try an example where verbatim causes the result to get printed differently than the default.

The difference between the sh and shell is explained in the answer here.

There probably exist several solutions for inserting custom (org) templates, one of it is to use yasnippet.

Alternatively, I have been working on some transient to provide such functionality. The code can be found here. After loading the code, the transient can be invoked using M-x ob-transient. With transient, it is possible to save settings using C-x s. It is already usable for simple 'demarcations'. And of course, the code can be extended to provide more functionalities (would be especially nice to extend it with 'presets').

1
  • One way to check the header args that are in effect (through default settings, property settings in the buffer, property settings in the section, or explicitly added to the source block) is to evaluate (org-babel-get-src-block-info).
    – NickD
    Commented Feb 12, 2023 at 18:16

Your Answer

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

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