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.


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 '17 at 15:46

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.