* doc/lispref/modes.texi (Major Modes): Document it.
* lisp/simple.el (clean-mode): New major mode.
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
\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
(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