summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2011-06-17 16:41:50 -0700
committerEric Schulte <schulte.eric@gmail.com>2011-06-17 16:41:50 -0700
commite4204fc3feebf25fc60c82b3d0d7fb3b6b3adea5 (patch)
tree0594c55ff237eeee9cb6c5ac116f5bd340aa9c17
parentdb1c3f6a3ea5d9cb25c8fad5aae434fc1d424152 (diff)
downloadorg-mode-e4204fc3feebf25fc60c82b3d0d7fb3b6b3adea5.tar.gz
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.
-rw-r--r--lisp/ob-tangle.el17
1 files changed, 13 insertions, 4 deletions
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index fe4075a..7b089f6 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'.