Is there a way to define a default language for org-mode code blocks in the docuement header? Usually, within one org document, I only use one programming language, so it's getting tiresome to always write

#+BEGIN_SRC python

It would be nice to be able to do something like

#+PROPERTY: header-args :session *mysession* :tangle yes :results silent :language python



Is there any way to achieve this?

  • 2
    This does not answer the question on how to set the default language, but it will definitely save you a lot of typing. Typing <s followed by the TAB key will auto expand into the source code block structure and then you simply need to type python, go to the next line and fill in the code. – Kaushal Modi Feb 17 '15 at 13:46
  • Check out orgmode.org/manual/… . Seems like the language spec is required. Did you post on the org list? If you didn't, I will, this is an interesting and probably common desire. – grettke Feb 17 '15 at 19:36
  • There are two replies already. lists.gnu.org/archive/html/emacs-orgmode/2015-02/msg00604.html – grettke Feb 18 '15 at 2:27
  • Thanks, @grettke, for taking the initiative to post to the mailing list. – andreas-h Feb 19 '15 at 11:30
  • The hint from the mailing list above (if one is looking for a solution that does not involve having #+BEGIN_SRC python in the .org file) is Probably you would have to modify org-babel-get-src-block-info so that it returns a default when there is nothing after #+BEGIN_SRC – ShreevatsaR Jun 11 '18 at 17:25

This answer provides a workable workaround.

The easiest way to do this would be using easy templates. Add your templates to the org-structure-template-alist:

(add-to-list 'org-structure-template-alist
         '("py" "#+BEGIN_SRC python :results output\n?\n#+END_SRC" ""))

The question mark indicates the cursor position. Insert the code block with <py TAB in this case.

  • 2
    Your answer is how to add new templates for expansion, not to default the language for a source block. – grettke Feb 17 '15 at 19:35
  • While this solves the problem of making it easy to enter such blocks, it doesn't solve the "problem" that the source file still contains #+BEGIN_SRC python instead of just #+BEGIN_SRC -- this makes the source file a bit harder to read, for example. – ShreevatsaR Jun 11 '18 at 17:22

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.