# Remove Every Source Block Results

Sometimes you accidentally evaluate your entire Org-Mode document resulting in result blocks everywhere. Maybe you can’t easily revert the change so you are stuck with a ton of code you don’t need. Here is a function to remove all of your result blocks. It is pretty good for documents that you probably never wanted to evaluate in the first place:

(defconst help/org-special-pre "^\s*#[+]")
(defun help/org-2every-src-block (fn)
"Visit every Source-Block and evaluate FN'."
(interactive)
(save-excursion
(goto-char (point-min))
(let ((case-fold-search t))
(while (re-search-forward (concat help/org-special-pre "BEGIN_SRC") nil t)
(let ((element (org-element-at-point)))
(when (eq (org-element-type element) 'src-block)
(funcall fn element)))))
(save-buffer)))
(define-key org-mode-map (kbd "s-]") (lambda () (interactive)
(help/org-2every-src-block
'org-babel-remove-result)))
`

## 4 thoughts on “Remove Every Source Block Results”

1. Hello,

did you know that something similar (or exactly the same is in the core)?
It is org-babel-remove-result-one-or-many

The missing one is removing all results bodies while retaining the result placeholder.
C-u org-babel-remove-result operates only on one block.

1. Grant says:

I didn’t know that. Thank you for pointing it out.