GNU bug report logs - #81256
31.0.90; [PATCH] New option: `delete-trailing-whitespace-in-current-line'

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Simen Heggestøyl <simenheg@HIDDEN>; Keywords: patch; dated Wed, 17 Jun 2026 12:54:04 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 81256 <at> debbugs.gnu.org:


Received: (at 81256) by debbugs.gnu.org; 22 Jun 2026 11:57:35 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jun 22 07:57:35 2026
Received: from localhost ([127.0.0.1]:54384 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1wbdHS-0004h8-Q7
	for submit <at> debbugs.gnu.org; Mon, 22 Jun 2026 07:57:35 -0400
Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]:58343)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <spwhitton@HIDDEN>)
 id 1wbdHQ-0004gq-0i
 for 81256 <at> debbugs.gnu.org; Mon, 22 Jun 2026 07:57:33 -0400
Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42])
 by mailfhigh.phl.internal (Postfix) with ESMTP id BE60614001B6;
 Mon, 22 Jun 2026 07:57:26 -0400 (EDT)
Received: from phl-frontend-04 ([10.202.2.163])
 by phl-compute-02.internal (MEProxy); Mon, 22 Jun 2026 07:57:26 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=spwhitton.name;
 h=cc:content-transfer-encoding:content-type:content-type:date
 :date:from:from:in-reply-to:in-reply-to:message-id:mime-version
 :references:reply-to:subject:subject:to:to; s=fm3; t=1782129446;
 x=1782215846; bh=HYKMem46krcpwSB+7hBJ8tGKLBY9Zo70QAERKvzlGxY=; b=
 Q2GC5KXcRJPZ53y7U0D1NEfZIv5F1LV9AFb22LOTJcmIu7KO0PMcB83SGCj8P3ut
 MqbAfAKSqbNWfFMrHD0NeD6Ned993hyOD75xozJMX7Q6fbA5YAAQOnBr8LIfDEJB
 uWmj+EaQFyD4vFFEquvPg5ZVp89feQGR7gW/eY15xYiavUU+Z3NM5hLYkiOCkf//
 svWXPsXscCEFsRGQYz0a7PMlmbP1+hnCXyR+K/j+DiOnuen4Y7p9fWP0IRwos2uF
 cwPDubw3lzhMJOn38r/g/7Ky8MZKYeCd2Ad8k+bHOgfigeSAHsytYXcrdAHcKhma
 Hjsr99M1LSVQ2cesY5Fw+A==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:content-transfer-encoding:content-type
 :content-type:date:date:feedback-id:feedback-id:from:from
 :in-reply-to:in-reply-to:message-id:mime-version:references
 :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender
 :x-me-sender:x-sasl-enc; s=fm1; t=1782129446; x=1782215846; bh=H
 YKMem46krcpwSB+7hBJ8tGKLBY9Zo70QAERKvzlGxY=; b=eKrFx73hp8g6VwJFs
 V/i8uAy3VrutXjufqKuDKy4+3rXFlyL240HDGxIieGLbiRy84V2I9bxrsakmSMn/
 wDatCvWH+hAyIZLves5Gkxbc9dL3RXb6ol8WPwzh8n0L3eWI7WXh8Cdq3JwVGJVw
 k24wyyL2dlX/4t8djUCpSPBaL1KE0w7Ajit5wl3T3POsMLM9h9h70U8WAZiAivWE
 SwvNC+3lvPfht8SlbjZA54E5qlVXgClmFazVbn8Yr/onR/+5N8JZ/Cjr0dii3z5X
 mGgtkARqZMAVhSdoWKnxmieeYfZF0n8eviQ4/lQISfB0j6dBmgt4gzwFaxeZKmPf
 WojoA==
X-ME-Sender: <xms:JiM5aidfjR4mQeEz6Sohjos6-5AdM_pw4XGSEJ6HV1dlDUUyCsTsGg>
 <xme:JiM5aiMtNmjgns2c2ljNkC6GGLfubSOjhg2EWzy2S89wneNNQPGjgwE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yHIRUkkareNOZJ146bR_9bJ9O25knouK2FpiU_R4w>
 <xmx:JiM5aowuOMlDh183zQqAgLTd2s_tqK0S-Zl9aqNcgktZltowWB7xEZz7>
Feedback-ID: i62564b17:Fastmail
Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon,
 22 Jun 2026 07:57:26 -0400 (EDT)
Received: by melete.silentflame.com (Postfix, from userid 1000)
 id 9D5F47E760B; Mon, 22 Jun 2026 12:57:25 +0100 (BST)
From: Sean Whitton <spwhitton@HIDDEN>
To: Simen =?utf-8?Q?Heggest=C3=B8yl?= <simenheg@HIDDEN>,
 81256 <at> debbugs.gnu.org
Subject: Re: bug#81256: 31.0.90; [PATCH] New option:
 `delete-trailing-whitespace-in-current-line'
In-Reply-To: <877bnxz5u2.fsf@HIDDEN>
References: <877bnxz5u2.fsf@HIDDEN>
Date: Mon, 22 Jun 2026 12:57:25 +0100
Message-ID: <87cxxirdne.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 81256
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Simen Heggest=C3=B8yl via "Bug reports for GNU Emacs, the Swiss army knife =
of text editors" [17/Jun  2:53pm +02] wrote:
> The attached patch adds a new option
> `delete-trailing-whitespace-in-current-line' which controls whether
> `delete-trailing-whitespace' should delete whitespace from the current
> line.
>
> It is set to t by default to keep the old behavior of deleting
> whitespace from the current line as well, but by setting it to nil, the
> current line is not touched when `delete-trailing-whitespace' is called.
>
> I find that behavior especially nice when `delete-trailing-whitespace'
> is bound to be called on buffer save, so that point doesn't get thrown
> around.

I think we discussed something like this a few months back and decided
not to add it, but I can't find it now.

The ws-butler package (which I maintain but did not author) maintains
the position of point but it saves the file with the trailing space
stripped.  That seems like the more useful behaviour?

--=20
Sean Whitton




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#81256; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 17 Jun 2026 12:54:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jun 17 08:54:01 2026
Received: from localhost ([127.0.0.1]:56350 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1wZpmI-0003s0-JP
	for submit <at> debbugs.gnu.org; Wed, 17 Jun 2026 08:54:00 -0400
Received: from lists1p.gnu.org ([2001:470:142::17]:48434)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <simenheg@HIDDEN>)
 id 1wZpmE-0003rH-Sh
 for submit <at> debbugs.gnu.org; Wed, 17 Jun 2026 08:53:56 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <simenheg@HIDDEN>)
 id 1wZpm4-0001Rw-R8
 for bug-gnu-emacs@HIDDEN; Wed, 17 Jun 2026 08:53:45 -0400
Received: from mailtransmit05.runbox.com ([2a0c:5a00:149::26])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <simenheg@HIDDEN>)
 id 1wZpm1-0003a0-Sg
 for bug-gnu-emacs@HIDDEN; Wed, 17 Jun 2026 08:53:44 -0400
Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com)
 by mailtransmit05.runbox.com with esmtps (TLS1.2) tls
 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93)
 (envelope-from <simenheg@HIDDEN>) id 1wZplt-003Dfi-AI
 for bug-gnu-emacs@HIDDEN; Wed, 17 Jun 2026 14:53:33 +0200
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; 
 s=selector2;
 h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From; 
 bh=Vkx6KrQm4EHIVWS6Of+TmC03koB/tJuznb2yJfmeJKg=; b=PH9oFRNmGEqR+uR24Pj6v1AGM
 mqi4W1BSe/Ly/R/dGeAEV4j2ojhY0azKAj7SA5OBNBBVJnMDDS0Fb6wvc6yDb/AfqKynu6l7Y49Fa
 JXXE5DgzNgV0aSANC8R/yB/IwzlG3MFqavNjW9qcBnYPvabSJ05vbbjabsclOLkiUmQAuAvLuRjJt
 O3pfdysOvpRgUfgX2v9QEi1uNQAeqUdQ7ZRwoazBM/d/8cX8/acUOfB5LR9CVex3oRgoWZh4uqPXD
 zUhUanLhPPiX6gOoQ90/VsVEiSBn5Tm0cNKGb9NLDyCKTHd4lygE4YpcSad6RpGjSzBcVSvLMcvMJ
 fyux7mJqg==;
Received: from [10.9.9.72] (helo=submission01.runbox)
 by mailtransmit03.runbox with esmtp (Exim 4.86_2)
 (envelope-from <simenheg@HIDDEN>) id 1wZpls-0004i8-Rd
 for bug-gnu-emacs@HIDDEN; Wed, 17 Jun 2026 14:53:33 +0200
Received: by submission01.runbox with esmtpsa [Authenticated ID (963757)]
 (TLS1.2:ECDHE_SECP256R1__RSA_SHA256__AES_256_GCM:256) (Exim 4.95)
 id 1wZplW-000oSX-2O for bug-gnu-emacs@HIDDEN;
 Wed, 17 Jun 2026 14:53:10 +0200
From: =?utf-8?Q?Simen_Heggest=C3=B8yl?= <simenheg@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 31.0.90; [PATCH] New option:
 `delete-trailing-whitespace-in-current-line'
Date: Wed, 17 Jun 2026 14:53:09 +0200
Message-ID: <877bnxz5u2.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=2a0c:5a00:149::26;
 envelope-from=simenheg@HIDDEN; helo=mailtransmit05.runbox.com
X-Spam_score_int: -23
X-Spam_score: -2.4
X-Spam_bar: --
X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1,
 DKIM_SIGNED=0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7,
 SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.7 (+)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview: The attached patch adds a new option
 `delete-trailing-whitespace-in-current-line'
 which controls whether `delete-trailing-whitespace' should delete whitespace
 from the current line. It is set to t by default to keep the old behavior
 of deleting whitespace from the current line as well, but by setting it to
 nil, the current line is not touched when `delete-trailing-whitespace' is
 [...] Content analysis details:   (1.7 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/,
 no trust [2001:470:142:0:0:0:0:17 listed in] [list.dnswl.org]
 0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail
 provider (simenheg[at]runbox.com)
 -0.0 SPF_HELO_PASS          SPF: HELO matches SPF record
 0.9 SPF_FAIL               SPF: sender does not match SPF record (fail)
 [SPF failed: Please see http://www.openspf.org/Why?s=mfrom;
 id=simenheg%40runbox.com; ip=2001%3A470%3A142%3A%3A17; r=debbugs.gnu.org]
 0.7 SPOOFED_FREEMAIL       No description available.
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.1 (/)

--=-=-=
Content-Type: text/plain

The attached patch adds a new option
`delete-trailing-whitespace-in-current-line' which controls whether
`delete-trailing-whitespace' should delete whitespace from the current
line.

It is set to t by default to keep the old behavior of deleting
whitespace from the current line as well, but by setting it to nil, the
current line is not touched when `delete-trailing-whitespace' is called.

I find that behavior especially nice when `delete-trailing-whitespace'
is bound to be called on buffer save, so that point doesn't get thrown
around.


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-New-option-delete-trailing-whitespace-in-current-lin.patch

From 97da91692e2ca8f84eb271f5360135b7a4e3fdb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@HIDDEN>
Date: Wed, 17 Jun 2026 13:01:16 +0200
Subject: [PATCH] New option: `delete-trailing-whitespace-in-current-line'

* lisp/simple.el (delete-trailing-whitespace-in-current-line)
(delete-trailing-whitespace): Only delete trailing whitespace in the
current line when the new option
`delete-trailing-whitespace-in-current-line' is non-nil (it is t by
default to keep previous behavior).
---
 lisp/simple.el | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index fd9ba28c762..06b3c3cc3dd 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -858,6 +858,14 @@ delete-trailing-lines
   :group 'editing
   :version "24.3")
 
+(defcustom delete-trailing-whitespace-in-current-line t
+  "If non-nil, \\[delete-trailing-whitespace] deletes from current line.
+Trailing whitespace in the current line is kept when
+`delete-trailing-whitespace-in-current-line' is nil."
+  :type 'boolean
+  :group 'editing
+  :version "32.1")
+
 (defun region-modifiable-p (start end)
   "Return non-nil if the region contains no read-only text."
   (and (not (get-text-property start 'read-only))
@@ -884,7 +892,8 @@ delete-trailing-whitespace
                    (list nil nil))))
   (save-match-data
     (save-excursion
-      (let ((end-marker (and end (copy-marker end))))
+      (let ((end-marker (and end (copy-marker end)))
+            (current-line (line-number-at-pos)))
         (goto-char (or start (point-min)))
         (with-syntax-table (make-syntax-table (syntax-table))
           ;; Don't delete formfeeds, even if they are considered whitespace.
@@ -892,7 +901,9 @@ delete-trailing-whitespace
           (while (re-search-forward "\\s-$" end-marker t)
             (skip-syntax-backward "-" (line-beginning-position))
             (let ((b (point)) (e (match-end 0)))
-              (if (region-modifiable-p b e)
+              (if (and (region-modifiable-p b e)
+                       (or delete-trailing-whitespace-in-current-line
+                           (/= (line-number-at-pos) current-line)))
                   (delete-region b e)
                 (goto-char e)))))
         (if end
-- 
2.53.0


--=-=-=--




Acknowledgement sent to Simen Heggestøyl <simenheg@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#81256; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 22 Jun 2026 12:00:03 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.