From: Joseph Turner <joseph@breatheoutbreathe.in>
To: Eli Zaretskii <eliz@gnu.org>
Cc: philipk@posteo.net, emacs-devel@gnu.org, mail+gh@daniel-mendler.de
Subject: Re: [IDEA] Add function clean-buffer
Date: Thu, 07 Sep 2023 21:55:23 -0700 [thread overview]
Message-ID: <878r9hw9cp.fsf@breatheoutbreathe.in> (raw)
In-Reply-To: <83cyyv342w.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1732 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Joseph Turner <joseph@breatheoutbreathe.in>
>> Cc: Emacs Devel Mailing List <emacs-devel@gnu.org>, mail+gh@daniel-mendler.de
>> Date: Tue, 05 Sep 2023 12:37:30 -0700
>>
>> +(defun clean-buffer (&optional buffer)
>> + "Remove all local variables, overlays, and text properties in BUFFER.
>> + When BUFFER is nil, act on current buffer."
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Our usual style is to say
>
> BUFFER defaults to the current buffer.
>
> or
>
> If BUFFER is omitted or nil, it 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))))
>
>> (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 yank-excluded-properties t)))
>> + "Mode removing all local variables, overlays, and text properties.
>
> Why not the original "Mode that removes"?
>
>> +This mode is intended for debugging purposes. For non-interactive
> ^^
> Two spaces between sentences, please.
>
> Also, why "For non-interactive use"? The opposite of "debugging
> purposes" is something like "for other purposes".
Thanks for the corrections. See patches.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-new-function-clean-buffer.patch --]
[-- Type: text/x-diff, Size: 1284 bytes --]
From 1f19e97545f858067b2ac345b92fcc27165b3bc1 Mon Sep 17 00:00:00 2001
From: Joseph Turner <joseph@breatheoutbreathe.in>
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Refactor-clean-mode-to-use-clean-buffer.patch --]
[-- Type: text/x-diff, Size: 1306 bytes --]
From a909cf811e0eb10fca8df4080454bb310e0d510d Mon Sep 17 00:00:00 2001
From: Joseph Turner <joseph@breatheoutbreathe.in>
Date: Tue, 5 Sep 2023 12:34:23 -0700
Subject: [PATCH 2/2] Refactor clean-mode to use clean-buffer
* lisp/simple.el (clean-mode):
Use clean-mode internally. Clarify docstring.
---
lisp/simple.el | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index 05a3c4b93d6..d61a88223ad 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -546,13 +546,11 @@ Other major modes are defined by comparison with this one."
(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 yank-excluded-properties t)))
+ "Mode removing all local variables, overlays, and text properties.
+This mode is intended for debugging purposes. For other purposes,
+see `clean-buffer'."
+ (clean-buffer)
+ (setq-local yank-excluded-properties t))
;; Special major modes to view specially formatted data rather than files.
--
2.41.0
next prev parent reply other threads:[~2023-09-08 4:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-03 22:18 [IDEA] Add function clean-buffer Joseph Turner
2023-09-04 16:02 ` Philip Kaludercic
2023-09-05 19:37 ` Joseph Turner
2023-09-06 11:59 ` Eli Zaretskii
2023-09-08 4:55 ` Joseph Turner [this message]
2023-09-08 9:13 ` David Ponce
2023-09-08 17:21 ` Joseph Turner
2023-09-09 0:38 ` Richard Stallman
2023-09-09 0:59 ` Joseph Turner
2023-09-09 7:00 ` Eli Zaretskii
2023-09-10 8:19 ` Stefan Kangas
2023-09-12 0:29 ` Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878r9hw9cp.fsf@breatheoutbreathe.in \
--to=joseph@breatheoutbreathe.in \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=mail+gh@daniel-mendler.de \
--cc=philipk@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).