From e4204fc3feebf25fc60c82b3d0d7fb3b6b3adea5 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Fri, 17 Jun 2011 16:41:50 -0700 Subject: [PATCH] tangle: ob-tangle now tangles only the current block when called with a prefix argument * lisp/ob-tangle.el (org-babel-tangle-file): Use the new argument list to org-babel-tangle. (org-babel-tangle): Now when called with a prefix argument, only the current code block is tangled. --- lisp/ob-tangle.el | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index fe4075a19..7b089f66d 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -154,7 +154,7 @@ used to limit the exported source code blocks by language." (save-window-excursion (find-file file) (setq to-be-removed (current-buffer)) - (org-babel-tangle target-file lang)) + (org-babel-tangle nil target-file lang)) (unless visited-p (kill-buffer to-be-removed)))) @@ -163,15 +163,24 @@ used to limit the exported source code blocks by language." (mapc (lambda (el) (copy-file el pub-dir t)) (org-babel-tangle-file filename))) ;;;###autoload -(defun org-babel-tangle (&optional target-file lang) +(defun org-babel-tangle (&optional only-this-block target-file lang) "Write code blocks to source-specific files. Extract the bodies of all source code blocks from the current file into their own source-specific files. Optional argument TARGET-FILE can be used to specify a default export file for all source blocks. Optional argument LANG can be used to limit the exported source code blocks by language." - (interactive) + (interactive "P") (run-hooks 'org-babel-pre-tangle-hook) + ;; possibly restrict the buffer to the current code block + (save-restriction + (when only-this-block + (unless (org-babel-where-is-src-block-head) + (error "Point is not currently inside of a code block")) + (unless target-file + (setq target-file + (read-from-minibuffer "Tangle to: " (buffer-file-name)))) + (narrow-to-region (match-beginning 0) (match-end 0))) (save-excursion (let ((block-counter 0) (org-babel-default-header-args @@ -252,7 +261,7 @@ exported source code blocks by language." (org-babel-with-temp-filebuffer file (run-hooks 'org-babel-post-tangle-hook))) path-collector)) - path-collector))) + path-collector)))) (defun org-babel-tangle-clean () "Remove comments inserted by `org-babel-tangle'.