1

I would like to have a link that runs a Babel source-code block. Does Org-mode support running something from the library of babel in a link, or a source block via a file+blockname reference? A Hyperbole button would also be acceptable.

3

You can easily define your own link type that runs source blocks:

(org-link-set-parameters
 "run"
 :follow
 (lambda (path)
   (save-excursion
     (org-babel-goto-named-src-block path)
     (org-babel-execute-src-block-maybe)))
 )

Afterwards a click on run:hello executes the source block in the following Orgmode file.

#+name: hello
#+begin_src emacs-lisp
(message "Hello")
#+end_src

#+RESULTS: hello
: Hello

run:hello
1

The usual way to do this is like this:

#+name: mysum
#+BEGIN_SRC emacs-lisp
(+ 5 5)
#+END_SRC


#+call: mysum()

#+RESULTS:
: 10

I am not sure what the point of doing this in a link would be, where would the results go for example?

You can make a link like this: [[elisp:(progn (org-babel-goto-named-src-block "mysum") (org-babel-execute-src-block-maybe))]]

which will jump to that block and run it.

  • My goal is to create a dashboard for phone SSH sessions. Clicking on links makes it easier. – Matthew Piziak Jun 13 at 0:27

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.