I want to execute selected source blocks in the active buffer. For example for the following org-mode file,

#+NAME: snippet1
#+BEGIN_SRC emacs-lisp
    (message "snippet 1")

#+NAME: snippet2
#+BEGIN_SRC emacs-lisp
    (message "snippet 2")

I can use


to execute both blocks from elisp, but how can I execute snippet1 without executing snippet2?

I found the following related functions that might help.


Any pointers to relevant documentation is very much appreciated.

2 Answers 2


The documentation for org-babel is available at http://org-babel.readthedocs.io/en/latest/. And the snippet to interactively select and execute a named block in the current buffer:

    (completing-read "Code Block: " (org-babel-src-block-names))))
  • I just replaced "(completing-read "Code Block: " (org-babel-src-block-names))))" with "my-block-name" since I didn't need the interactive part. Thanks for the snippet it works great now :).
    – user14419
    May 14, 2017 at 15:46

Much easier than the AA: Using the built-in function (org-sbe ...:

* Example using (org-sbe):
#+NAME: snippet1
#+BEGIN_SRC emacs-lisp :var txt="snippet1 was called"
    (message txt)

If you want to run the above SCB, you could just place
the curson on the closing bracket ")" of “(org-sbe "snippet1")”,
and just run that with CTRL-x CTRL-e , and here once
more “(org-sbe "snippet1" (txt $"otherMessage"))” with parameters.
Documentation e.g. here:

Your Answer

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

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