summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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