emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 597b6de 2/2: Add new major mode 'clean-mode'


From: Lars Ingebrigtsen
Subject: master 597b6de 2/2: Add new major mode 'clean-mode'
Date: Wed, 6 Oct 2021 06:55:27 -0400 (EDT)

branch: master
commit 597b6deb294ace9178c8927f83ec08b92597b347
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new major mode 'clean-mode'
    
    * doc/lispref/modes.texi (Major Modes): Document it.
    
    * lisp/simple.el (clean-mode): New major mode.
---
 doc/lispref/modes.texi | 12 ++++++++++++
 etc/NEWS               |  5 +++++
 lisp/simple.el         | 12 ++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index ee55f98..d55df7d 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -268,6 +268,18 @@ 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
 @code{define-derived-mode}, which sets up the new mode as a variant of
 an existing major mode.  @xref{Derived Modes}.  We recommend using
diff --git a/etc/NEWS b/etc/NEWS
index 7360bb7..7b218aa 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -126,6 +126,11 @@ with recent versions of Firefox.
 * 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
 local variables.
diff --git a/lisp/simple.el b/lisp/simple.el
index 5c6adcf..0427154 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]