summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-04-23 00:35:15 -0400
committerKyle Meyer <kyle@kyleam.com>2015-04-23 00:35:15 -0400
commit5818e9cb237b36533643a0f612c23a54f51e3b38 (patch)
treed171897970c14afbcb87d3f8d3023601adc595b7
parent40d93ac02ca4ab238dedd85a4ac8823a99a76d92 (diff)
downloademacs.d-5818e9cb237b36533643a0f612c23a54f51e3b38.tar.gz
Org: Add org-babel-delete-all-results command
-rw-r--r--lisp/init-org.el25
1 files changed, 25 insertions, 0 deletions
diff --git a/lisp/init-org.el b/lisp/init-org.el
index af07450..6d234bf 100644
--- a/lisp/init-org.el
+++ b/lisp/init-org.el
@@ -709,6 +709,31 @@ beginning of the link."
(emacs-lisp . t)
(latex . t)))
+(defun km/org-babel-delete-all-results ()
+ "Delete Org babel result blocks."
+ (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (let ((res-regex (rx line-start "#+RESULTS"
+ (zero-or-one "[" (one-or-more alnum)
+ (zero-or-one "...") "]")
+ ":" line-end)))
+ (while (re-search-forward res-regex nil t)
+ (let ((res-beg (point-at-bol)))
+ (forward-line)
+ (cond
+ ((looking-at-p "^#\\+begin_example$")
+ (re-search-forward "^#\\+end_example$")
+ (delete-region res-beg (point)))
+ ((looking-at-p "^: ")
+ (re-search-forward "^[^:]")
+ (delete-region res-beg (point)))
+ (t
+ (forward-line -1)
+ (delete-region res-beg (point-at-eol)))))
+ (when (looking-at-p "^\\s-$")
+ (delete-blank-lines))))))
+
;;; Org Contacts