summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2011-07-29 10:31:56 -0600
committerEric Schulte <schulte.eric@gmail.com>2011-07-29 10:31:56 -0600
commit72817926d72cd78efbb114169d61136b8b00c73e (patch)
tree68682b1bb4a0fbd4d7261b9e7f485eefc83a442b
parent36974045b6001c6b7dc248881bbef3325c4e5872 (diff)
downloadorg-mode-72817926d72cd78efbb114169d61136b8b00c73e.tar.gz
new interactive function for removing code block results
* lisp/ob-keys.el (org-babel-key-bindings): Bound to C-c C-v k. * lisp/ob.el (org-babel-map-regexp): New generic mapping macro. (org-babel-map-inline-src-blocks): Rewritten to use new macro. (org-babel-kill-results): Remove some or all results in the current file. * lisp/ob-lob.el (org-babel-map-call-lines): Map over all lob call lines in the current file. * doc/orgcard.tex: Document new keybinding.
-rw-r--r--doc/orgcard.tex1
-rw-r--r--lisp/ob-keys.el2
-rw-r--r--lisp/ob-lob.el9
-rw-r--r--lisp/ob.el30
4 files changed, 36 insertions, 6 deletions
diff --git a/doc/orgcard.tex b/doc/orgcard.tex
index e4d5c62..be8cbef 100644
--- a/doc/orgcard.tex
+++ b/doc/orgcard.tex
@@ -447,6 +447,7 @@ formula, \kbd{:=} a field formula.
\key{check code block at point for errors}{C-c C-v c}
\key{view expanded body of code block at point}{C-c C-v v}
\key{view information about code block at point}{C-c C-v I}
+\key{delete some or all results in current buffer}{C-c C-v k}
\key{go to named code block}{C-c C-v g}
\key{go to named result}{C-c C-v r}
\key{go to the head of the current code block}{C-c C-v u}
diff --git a/lisp/ob-keys.el b/lisp/ob-keys.el
index b559135..c36c190 100644
--- a/lisp/ob-keys.el
+++ b/lisp/ob-keys.el
@@ -63,6 +63,8 @@ functions which are assigned key bindings, and see
("g" . org-babel-goto-named-src-block)
("r" . org-babel-goto-named-result)
("\C-r" . org-babel-goto-named-result)
+ ("k" . org-babel-kill-results)
+ ("\C-k" . org-babel-kill-results)
("\C-b" . org-babel-execute-buffer)
("b" . org-babel-execute-buffer)
("\C-s" . org-babel-execute-subtree)
diff --git a/lisp/ob-lob.el b/lisp/ob-lob.el
index 5c4894d..b224622 100644
--- a/lisp/ob-lob.el
+++ b/lisp/ob-lob.el
@@ -87,7 +87,14 @@ If you change the value of this variable then your files may
"\\|" org-babel-inline-lob-one-liner-regexp "\\)")
"Regexp to match calls to predefined source block functions.")
-;; functions for executing lob one-liners
+;;;###autoload
+(defmacro org-babel-map-call-lines (file &rest body)
+ "Evaluate BODY forms on each #+call line in FILE.
+If FILE is nil evaluate BODY forms on source blocks in current
+buffer."
+ (declare (indent 1))
+ `(org-babel-map-regexp ,org-babel-block-lob-one-liner-regexp ,file ,@body))
+
;;;###autoload
(defun org-babel-lob-execute-maybe ()
"Execute a Library of Babel source block, if appropriate.
diff --git a/lisp/ob.el b/lisp/ob.el
index 0de0aa6..a47b8be 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -65,6 +65,7 @@
(declare-function orgtbl-to-orgtbl "org-table" (table params))
(declare-function org-babel-tangle-comment-links "ob-tangle" (&optional info))
(declare-function org-babel-lob-get-info "ob-lob" nil)
+(declare-function org-babel-map-call-lines "ob-lob" (file &rest body))
(declare-function org-babel-ref-split-args "ob-ref" (arg-string))
(declare-function org-babel-ref-parse "ob-ref" (assignment))
(declare-function org-babel-ref-resolve "ob-ref" (ref))
@@ -721,12 +722,11 @@ end-body --------- point at the end of the body"
(unless visited-p (kill-buffer to-be-removed))
(goto-char point))))
-;;;###autoload
-(defmacro org-babel-map-inline-src-blocks (file &rest body)
- "Evaluate BODY forms on each inline source-block in FILE.
+(defmacro org-babel-map-regexp (regexp file &rest body)
+ "Evaluate BODY forms on each match of REGEXP in FILE.
If FILE is nil evaluate BODY forms on source blocks in current
buffer."
- (declare (indent 1))
+ (declare (indent 2))
(let ((tempvar (make-symbol "file")))
`(let* ((,tempvar ,file)
(visited-p (or (null ,tempvar)
@@ -736,7 +736,7 @@ buffer."
(when ,tempvar (find-file ,tempvar))
(setq to-be-removed (current-buffer))
(goto-char (point-min))
- (while (re-search-forward org-babel-inline-src-block-regexp nil t)
+ (while (re-search-forward ,regexp nil t)
(goto-char (match-beginning 1))
(save-match-data ,@body)
(goto-char (match-end 0))))
@@ -744,6 +744,14 @@ buffer."
(goto-char point))))
;;;###autoload
+(defmacro org-babel-map-inline-src-blocks (file &rest body)
+ "Evaluate BODY forms on each inline source-block in FILE.
+If FILE is nil evaluate BODY forms on source blocks in current
+buffer."
+ (declare (indent 1))
+ `(org-babel-map-regexp ,org-babel-inline-src-block-regexp ,file ,@body))
+
+;;;###autoload
(defun org-babel-execute-buffer (&optional arg)
"Execute source code blocks in a buffer.
Call `org-babel-execute-src-block' on every source block in
@@ -1325,6 +1333,7 @@ With optional prefix argument ARG, jump backward ARG many source blocks."
(goto-char (match-beginning 5))))
(org-babel-where-is-src-block-head)))
+;;;###autoload
(defun org-babel-demarcate-block (&optional arg)
"Wrap or split the code in the region or on the point.
When called from inside of a code block the current block is
@@ -1367,6 +1376,17 @@ region is not active then the point is demarcated."
"#+end_src\n"))
(goto-char start) (move-end-of-line 1)))))
+;;;###autoload
+(defun org-babel-kill-results (arg)
+ "Remove the results from the current code block or call line.
+When called with prefix argument remove all results in the current file."
+ (interactive "P")
+ (if (null arg)
+ (org-babel-remove-result)
+ (org-babel-map-call-lines nil (org-babel-remove-result))
+ (org-babel-map-src-blocks nil (org-babel-remove-result))
+ (org-babel-map-inline-src-blocks nil (org-babel-remove-result))))
+
(defvar org-babel-lob-one-liner-regexp)
(defvar org-babel-inline-lob-one-liner-regexp)
(defun org-babel-where-is-src-block-result (&optional insert info hash indent)