]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new major mode 'clean-mode'
authorLars Ingebrigtsen <larsi@gnus.org>
Wed, 6 Oct 2021 10:55:17 +0000 (12:55 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 6 Oct 2021 10:55:21 +0000 (12:55 +0200)
* doc/lispref/modes.texi (Major Modes): Document it.

* lisp/simple.el (clean-mode): New major mode.

doc/lispref/modes.texi
etc/NEWS
lisp/simple.el

index ee55f982d0292c43d790c38af30bfb3b86f382c8..d55df7db4b66c72703de6fd44dea4dcfb25d74f0 100644 (file)
@@ -266,6 +266,18 @@ This function restores the major mode recorded by
 function calls @code{normal-mode} (@pxref{Auto Major Mode,
 normal-mode}), but tries to force it not to choose any modes in
 @var{avoided-modes}, if that argument is non-@code{nil}.
+@end defun
+
+@defun clean-mode
+Changing the major mode clears out most local variables, but it
+doesn't remove all artefacts in the buffer (like text properties and
+overlays).  It's rare to change a buffer from one major mode to
+another (except from @code{fundamental-mode} to everything else), so
+this is usually not a concern.  It can sometimes be convenient (mostly
+when debugging a problem in a buffer) to do a ``full reset'' of the
+buffer, and that's what the @code{clean-mode} major mode offers.  It
+will kill all local variables (even the permanently local ones), and
+also removes all overlays and text properties.
 @end defun
 
   The easiest way to write a major mode is to use the macro
index 7360bb79852b1d66b92261846e49f67395d201f1..7b218aaf6da57fe85be8e8f4045cadcc3914f15a 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -125,6 +125,11 @@ with recent versions of Firefox.
 \f
 * Lisp Changes in Emacs 29.1
 
++++
+** New major mode 'clean-mode'.
+This is a new major mode meant for debugging.  It kills absolutely all
+local variables and removes overlays and text properties.
+
 +++
 ** 'kill-all-local-variables' can now kill all local variables.
 If given the new optional KILL-PERMANENT argument, also kill permanent
index 5c6adcf490747a8746af70b31bb882bb37b25b89..042715449b210347db4ed2042633eb232eb26ac9 100644 (file)
@@ -527,6 +527,18 @@ Other major modes are defined by comparison with this one."
   (kill-all-local-variables)
   (run-mode-hooks))
 
+(define-derived-mode clean-mode fundamental-mode "Clean"
+  "A mode that removes all overlays and text properties."
+  (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)
+    (setq-local after-change-functions
+                (list
+                 (lambda (begin end _length)
+                   (set-text-properties begin end nil))))))
+
 ;; Special major modes to view specially formatted data rather than files.
 
 (defvar-keymap special-mode-map