Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to org-babel-tangle only one code block?

I'm generating multiple files in one .org file, with multiple source code blocks. For example:

#+begin_src rst :tangle file1.rst :noweb yes
<<file1>>
#+end_src

#+begin_src rst :tangle file2.rst :noweb yes
<<file2>>
#+end_src

Is there any way to only tangle one specific code block without changing the header options?

I'm generating these files for Sphinx and to reduce the compilation time I want to tangle only the file I'm currently working on.

It would be great if there is a command such as org-babel-tangle-current-block - is there any way to do this?

(This is a related question to Orgmode: how to filter the blocks to be tangle?)

like image 918
joon Avatar asked Feb 25 '15 18:02

joon


2 Answers

That is possible by calling org-babel-tangle with a prefix argument.

So C-u C-c C-v t should do what you want.

From the docstring:

With one universal prefix argument, only tangle the block at point. When two universal prefix arguments, only tangle blocks for the tangle file of the block at point.

like image 163
Andreas Avatar answered Dec 14 '22 02:12

Andreas


Just in case that someone is interested in binding a key to this - my init file includes the following:

(defun org-babel-tangle-block()
  (interactive)
  (let ((current-prefix-arg '(4)))
     (call-interactively 'org-babel-tangle)
))

(eval-after-load "org"
  '(progn
     (define-key org-mode-map (kbd "C-c b") 'org-babel-tangle-block)
))

and I can tangle the code block under the cursor with C-c b.

like image 22
joon Avatar answered Dec 14 '22 02:12

joon