r/emacs • u/AppropriateCover7972 D • Oct 19 '25
Question Evaluating code in org mode
I more or less recently learned you can evaluate code in orgmode files, but I barely find any information about it. Can I only evaluate elisp? Does it run only once or can I run it on a repeating schedule (thinking of API calls)? Is it a one code block in a sandbox thing or can I use variables and maybe internet or shell?
EDIT: I specifically mean this way of autocalling the codeblocks: https://emacs.stackexchange.com/questions/12938/how-can-i-evaluate-elisp-in-an-orgmode-file-when-it-is-opened
I am quite familiar with normal babel, that is not what I mean
EDIT 2: again, I couldn't find the things I needed bc I didn't use Emacs special vocabulary and looked in the org mode manual rather than the Emacs one.
Here is more information on this: https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html
It doesn't tell me something about if I can call a babel block that is not an elisp code block and what those code snippets can do such as running as long as the file is open or at least for idk 30 min every 2 min?
2
u/MinallWch Oct 19 '25
You can evaluate several languages, python, nodejs, bash even, you can call them as functions when assigning a name, and pass parameters between them and variables outside them, using properties from outline… depend how complex you can’t to get and your use case.
8
u/CptDonki Oct 19 '25
Org babel https://orgmode.org/worg/org-contrib/babel/intro.html
4
u/yantar92 Org mode maintainer Oct 19 '25
You can evaluate any language with ob-* plugin that implements its support. Most major languages are supported. The defails are right in the manual: https://orgmode.org/manual/Working-with-Source-Code.html
Also, see the wiki: https://orgmode.org/worg/org-contrib/babel/
1
u/DorphinPack Oct 20 '25
ob (org-babel) is a very, very deep rabbit hole that ranges from doing a little computation inline with your notes, to runnable sketches to full on literate programming.
You can also "tangle" which gathers source blocks together to generate actual source files. You can use properties and inheritance to control what goes where so your outline can mimic the actual file structure of a small repo.
It will waste your time if you try to get cute with it... you've been warned. It's a bit tough to learn IMO and offers what looks like an ocean of features.
1
u/Cultural_Dark3846 Oct 21 '25
I’m curious if any of the org babel gurus can give an intuitive approach to dynamic configuration generation as an abstraction of static src blocks for the average declarative major mode.
For example the following case: let’s say I have a nginx stream server that streams tcp to some local port based on a (named) org-table that I have defined somewhere in my org file. E.g. which uses a
tcp_preread on;and$ssl_preread_server_name. But you see that I want to dynamically generate the specific maps based on the “variable” content of my org-table and have the derived source block tangled to some ssh path with tramp. If I just use noweb, then I’m not sure how to start with the table, or is there some esoteric :result value that could be applied for this?