Babel supports a growing number of programming languages; more than ten dozen languages currently have some Babel support. Babel support for more than three dozen widely used languages is distributed with Emacs, and the various Emacs Lisp Package Archives include support for more than four dozen languages. In addition, for various historical reasons, Babel support for more than two dozen languages is distributed in the Org-contrib package.
This page provides pointers to sources of Babel language support, instructions to activate a supported language, and a brief guide to developing support for a language in case you'd like to use a new language with Babel or contribute to existing Babel language support.
Language Support Distributed with Emacs
Table 1 lists the Babel language support distributed with Emacs. The table provides a link to a web page with information about the language, indicates how the language is identified in Babel, provides a link to existing documentation, and indicates the generosity of your colleagues who have volunteered to maintain a bit of Babel language support.
Note that there are some inconsistencies among supported languages.
Language Support Distributed with Org-contrib
Once upon a time, Babel language support that was not released under the GPL was kept in Org-contrib. Later, with the goal of easing the burden of Org-mode maintenance, lesser-known languages distributed with Emacs were also moved to Org-contrib. Table 2 includes pointers to these languages and some documentation of their Babel integration.
Language Support Distributed via an Emacs Lisp Package Archive
Most language support is distributed through an Emacs Lisp Package
Archive. You can find the Babel language support available on your
M-x list-packages. In theory, it ought to be possible to
identify all the Babel language support packages with a keyword search
M-x package-menu-filter, but this method is unreliable because
package developers do not subscribe to a keyword authority list. In
practice, you can search for package names that start with
go from there.
Activate a Language
To add support for a particular language to your Babel installation
first make sure that the requirements of the language are met, then
org-babel-load-languages variable with the appropriate language identifier, <lang>, from Table 1 or Table 2, as follows:
(<lang> . t)
To remove support for a language, customize the
org-babel-load-languages variable, as follows:
(<lang> . nil)
Here is an example manual configuration of this variable, which
enables support for
R, and disables support for
;; active Babel languages (org-babel-do-load-languages 'org-babel-load-languages '((R . t) (emacs-lisp . nil)))
Develop Support for a Language
The core Babel functions (viewing, export, tangling, etc.) are language agnostic and will work even for languages that are not explicitly supported. Explicit language-specific support is required only for evaluation of code blocks in a language.
Babel is designed to be easily extended to support new languages. Language support is added by defining language-specific functions using a simple naming convention. The full suite of possible language specific functions need not be implemented all at once, but rather it is possible (and encouraged) to develop language-specific functionality in an incremental fashion—Babel will make use of those functions which are available, and will fail gracefully when functionality has not yet been implemented.
There is a short Emacs Lisp template (ob-template.el) which can be used as a starting point for implementing support for new languages. To fetch a copy of this file, please clone Worg:
~$ git clone https://git.sr.ht/~bzg/worg
You should find
Developers are encouraged to read the Org-mode contribution instructions in the hope that the language support can be added to the Org-mode core.
Some additional comments/development tips
Although most of the instructions in
ob-template.el should be
useful, and explain clearly how to use the code, some explanations for
more advanced functionalities could be a little outdated
(contributions are very welcome. The thread here may contain some
extra useful information, although most of the suggestions provided by
Eric should have been implemented). If some of the instructions seem
clear, then here are some suggestions to gain clarity:
- start with instrumenting see edebug the
org-babel-execute:templatefunction, and subsequently evaluate some test-code block. In this way you can easily figure out how Babel processes header arguments. Then in the end, the result printed by a code block simply consists of the output of that function.
- The trick is to process the
result-params, and the
org-babel-execute:templatefunction) and send the appropriate lines to some inferior process (or as an argument to some shell command). The inferior process can be created in the function
org-babel-template-initiate-session. The result returned by the inferior process (or by the shell command), should be returned by
org-babel-execute:template(of course you might further process it before you return it).
- Don't forget to read the comments in the ob-template file, e.g. for
sending/receiving output to/from an inferior process. The functions in
org-babel-comintmight also be useful.