From 1f19e97545f858067b2ac345b92fcc27165b3bc1 Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Tue, 5 Sep 2023 12:28:49 -0700 Subject: [PATCH 1/2] Add new function clean-buffer * lisp/subr.el (clean-buffer): Removes all local variables, overlays, and text properties. --- lisp/subr.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lisp/subr.el b/lisp/subr.el index 34d87e83310..edf96124ec6 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -4694,6 +4694,16 @@ Normally, mouse motion is ignored." (declare (debug (def-body)) (indent 0)) `(internal--track-mouse (lambda () ,@body))) +(defun clean-buffer (&optional buffer) + "Remove all local variables, overlays, and text properties in BUFFER. +BUFFER defaults to the current buffer." + (with-current-buffer (or buffer (current-buffer)) + (kill-all-local-variables t) + (let ((inhibit-read-only t)) + (dolist (overlay (overlays-in (point-min) (point-max))) + (delete-overlay overlay)) + (set-text-properties (point-min) (point-max) nil)))) + (defmacro with-current-buffer (buffer-or-name &rest body) "Execute the forms in BODY with BUFFER-OR-NAME temporarily current. BUFFER-OR-NAME must be a buffer or the name of an existing buffer. -- 2.41.0