From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner Newsgroups: gmane.emacs.devel Subject: Re: [IDEA] Add function clean-buffer Date: Thu, 07 Sep 2023 21:55:23 -0700 Message-ID: <878r9hw9cp.fsf@breatheoutbreathe.in> References: <87il8qx50p.fsf@breatheoutbreathe.in> <87ledm6i68.fsf@posteo.net> <87a5u0tmwd.fsf@breatheoutbreathe.in> <83cyyv342w.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21748"; mail-complaints-to="usenet@ciao.gmane.io" Cc: philipk@posteo.net, emacs-devel@gnu.org, mail+gh@daniel-mendler.de To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 08 07:34:15 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qeU8E-0005OI-JQ for ged-emacs-devel@m.gmane-mx.org; Fri, 08 Sep 2023 07:34:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeU7D-0007FY-Ld; Fri, 08 Sep 2023 01:33:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeTYV-0007BF-DI for emacs-devel@gnu.org; Fri, 08 Sep 2023 00:57:20 -0400 Original-Received: from out-216.mta1.migadu.com ([95.215.58.216]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeTYS-0000u0-It for emacs-devel@gnu.org; Fri, 08 Sep 2023 00:57:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1694149033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FleQB7peOuC0L1WqT0wNtiLR1LFGXVeEzugbO1qY6ZE=; b=Tcrg1+F0UmXfaiWLyLANUCwwVXgpUKI1hmk5nvTE1ygtEukGB+IAlZw8AXpoFrUTjuv8Ln uXrqgk6B7+z2XZzvzWwy1kcO8GShm/sC9nPcRx2UEl5sf1R8SumfX14W57W4KA/JuATvtD nz6rHDnWZayvf3ih8JD9xLOOARIU1ko= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <83cyyv342w.fsf@gnu.org> X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=95.215.58.216; envelope-from=joseph@breatheoutbreathe.in; helo=out-216.mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 08 Sep 2023 01:33:07 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:310304 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Joseph Turner >> Cc: Emacs Devel Mailing List , 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. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-new-function-clean-buffer.patch >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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-Refactor-clean-mode-to-use-clean-buffer.patch >From a909cf811e0eb10fca8df4080454bb310e0d510d Mon Sep 17 00:00:00 2001 From: Joseph Turner 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 --=-=-=--