2

Suppose our buffer reads:

* Test
#+BEGIN_SRC mathematica
Manipulate[Plot[{x^{a-1}, E^{-x}}, {x, 0, 10}], {a, 0, 10}]
#+END_SRC

#+BEGIN_SRC mathematica
2+2
#+END_SRC

#+BEGIN_SRC mathematica
E^{-2}
#+END_SRC

Is there a way to copy all of the source blocks so that something like the following gets copied to your clipboard?

Manipulate[Plot[{x^{a-1}, E^{-x}}, {x, 0, 10}], {a, 0, 10}]
2+2
E^{-2}
2

Not quite what you're asking for, but org-mode provides the function org-babel-tangle, which extracts all the source blocks in a file and saves them into a single file. That might get you what you need. If not, you could write a function to call org-babel-tangle, then copy the contents of the generated file into the clipboard.

1

Here is a function that will copy the contents of all the blocks in a subtree. You could also add some logic to only copy a certain kind, e.g.if you mix languages.

(defun org-copy-blocks ()
  (interactive)
  (let ((code ""))
    (save-restriction
      (org-narrow-to-subtree)
      (org-babel-map-src-blocks nil
    (setq code (concat code (org-no-properties body)))))
    (kill-new code)))

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.