2

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")
#+END_SRC

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

I can use

(org-babel-execute-buffer)

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

I found the following related functions that might help.

org-babel-get-src-block-info
org-babel-execute-src-block

Any pointers to relevant documentation is very much appreciated.

3

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:

(save-excursion
  (goto-char
   (org-babel-find-named-block
    (completing-read "Code Block: " (org-babel-src-block-names))))
  (org-babel-execute-src-block-maybe))
  • 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.