GNU bug report logs - #78264
[PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode

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: Stefan Monnier <monnier@HIDDEN>; Keywords: patch; dated Mon, 5 May 2025 16:03:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

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


Received: (at 78264) by debbugs.gnu.org; 10 May 2025 09:43:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 10 05:43:11 2025
Received: from localhost ([127.0.0.1]:43999 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uDgje-00064H-Rt
	for submit <at> debbugs.gnu.org; Sat, 10 May 2025 05:43:11 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:6897)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1uDgjY-00063N-Iz
 for 78264 <at> debbugs.gnu.org; Sat, 10 May 2025 05:43:05 -0400
Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 408448087F;
 Sat, 10 May 2025 05:42:59 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1746870178;
 bh=0k1cLANc9vLnZ9pY+j4DIXgdkqUZTmJIQ5Ft0vs42Rk=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=MwLPKVhLVsEqxfRVEhMsI//cUEaALP3zUiUyNLGDQBBJNB8DqiL0awXMY/Kkaa4AN
 +u3cpYoYE11AV8M7q76jp9XvVPEqMnrhhfN2NzwpD/2dOaxjZBZi1H+gRmpEzrSq5/
 zh9Hm4ID+ZYYhHBGGjEbve9OTJFepKmcMTRT+Ac+quqh4QXb33gjRcxZBJ5CSy1BKa
 yIdWo+cXt0H3VjDVKPWmlsrxU9Hbr+5aFifM0MQE1+HeDElx+3AYMiS+YXBRR0LFFJ
 qG21oNwQQ4pAujKUm6mo+QHDS89puHtoWf3vvGgjOv+6Rs8Hua0COG9bPNoGkiTMVi
 V8SiAyT0z71mQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 7DE19805C1;
 Sat, 10 May 2025 05:42:58 -0400 (EDT)
Received: from pastel (104-195-232-56.cpe.teksavvy.com [104.195.232.56])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 4F0B91204D2;
 Sat, 10 May 2025 05:42:58 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Sean Whitton <spwhitton@HIDDEN>
Subject: Re: bug#78264: [PATCH] simple.el (delete-trailing-whitespace-mode):
 New minor mode
In-Reply-To: <874ixsx3am.fsf@HIDDEN>
Message-ID: <jwvikm8ls4b.fsf-monnier+emacs@HIDDEN>
References: <jwv5xif11yl.fsf@HIDDEN>
 <874ixsx3am.fsf@HIDDEN>
Date: Sat, 10 May 2025 05:42:57 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.075 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78264
Cc: 78264 <at> debbugs.gnu.org, EditorConfig Team <editorconfig@HIDDEN>
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: -3.3 (---)

> Seems reasonable, though can we make sure Emacs will let you enable it
> from .dir-locals.el for a repository without generating warnings?
> I.e. set whatever is needed to trust it as a minor mode enabled from
> there (which may be nothing).

AFAIK this is already the case for all minor modes.

I didn't check with `.dir-locals.el` but I did check with
`.editorconfig`, which should show the same behavior.



        Sefan





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

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


Received: (at 78264) by debbugs.gnu.org; 10 May 2025 09:10:44 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 10 05:10:44 2025
Received: from localhost ([127.0.0.1]:43708 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uDgEG-00045X-9p
	for submit <at> debbugs.gnu.org; Sat, 10 May 2025 05:10:44 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:35996)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1uDgEC-00045J-Ti
 for 78264 <at> debbugs.gnu.org; Sat, 10 May 2025 05:10:42 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1uDgE6-0007RX-Hx; Sat, 10 May 2025 05:10:34 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=9AOlK7awY114OhCfxmPpg53fo/u/vhVPKbPK9kmnYOc=; b=UfS1uyW9Q24h
 XYHcRCg7xPV98dTBzWN2+67hW7Wn9TetXsdeOOGbZ3Q1u1UJUrfcThVkJjHDrZXQ8eiGFypbDNBs1
 EkPCj24g9hB3Qs/8yPuW8er+cP34tukHwGXJQQYyEATn4HNVn/L7GquO6i0Esy2nK52qLfDA9oU2I
 5mGta0yxAMu5fL9IIeXFY+Q9SIstBuxQ4kFfDVABClTQGvFuOqNiTIdgaZNY+um+nNnoZDMfDdF0q
 jPyFOSIU/Xl1XkrkfOdwWGWTthdSVNpMA8NniQu9uFmb4llggdMSYlHWZhLsy3CIIc+Sz910MceFL
 phgNqCE4Ul/1I/2f1127qg==;
Date: Sat, 10 May 2025 12:10:31 +0300
Message-Id: <86tt5sbzlk.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Sean Whitton <spwhitton@HIDDEN>
In-Reply-To: <874ixsx3am.fsf@HIDDEN> (message from Sean
 Whitton on Sat, 10 May 2025 09:45:05 +0100)
Subject: Re: bug#78264: [PATCH] simple.el (delete-trailing-whitespace-mode):
 New minor mode
References: <jwv5xif11yl.fsf@HIDDEN>
 <874ixsx3am.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78264
Cc: 78264 <at> debbugs.gnu.org, monnier@HIDDEN,
 editorconfig@HIDDEN
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: -3.3 (---)

> Cc: Stefan Monnier <monnier@HIDDEN>,
>  EditorConfig Team <editorconfig@HIDDEN>
> From: Sean Whitton <spwhitton@HIDDEN>
> Date: Sat, 10 May 2025 09:45:05 +0100
> 
> Seems reasonable, though can we make sure Emacs will let you enable it
> from .dir-locals.el for a repository without generating warnings?
> I.e. set whatever is needed to trust it as a minor mode enabled from
> there (which may be nothing).

Is this really useful to turn on for _every_ file in a directory?
What about files where trailing whitespace is significant (patches,
for example)?




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

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


Received: (at 78264) by debbugs.gnu.org; 10 May 2025 08:45:17 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 10 04:45:17 2025
Received: from localhost ([127.0.0.1]:43617 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uDfpd-0002c5-1W
	for submit <at> debbugs.gnu.org; Sat, 10 May 2025 04:45:17 -0400
Received: from sendmail.purelymail.com ([34.202.193.197]:43344)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <spwhitton@HIDDEN>)
 id 1uDfpZ-0002Y7-Tq
 for 78264 <at> debbugs.gnu.org; Sat, 10 May 2025 04:45:15 -0400
DKIM-Signature: a=rsa-sha256;
 b=LRue49H6dn1mHWs2cq0WTv6LiY4zWfxEMQEzlBBvu19VY9sL9whAZcs5cNDQnCdsYn2hOX6uhIsWadR3DwdnPsK823ZAiwjI2QLrzn6h+k7Ch0BJftTbOBDtbgyHDGQ9TOlD5GDjNA+x1N4LMFp8IixFg9FGG+RP5of1vstIbL6wU0ttP6iP/faUbYtLos65GKlmL1JZUum1FLR/o+TOw21lb/nwG3K91dTZS43fA62o152s66eopKY1VvM7w0zzllHDlhSdnYZR3iuRuviRAgKrMdK8oba0mrRgDMO/c70QYciM30Y9ZhBrNHPtN7S252QVHMWOH88zIs6rqPbtcw==;
 s=purelymail3; d=spwhitton.name; v=1;
 bh=7bSDIcT0me2PPCAF4vwl+p1Y429RLlnYfXPoBjQbCxg=;
 h=Received:Received:From:To:Subject:Date; 
DKIM-Signature: a=rsa-sha256;
 b=nl25g1jZioLVIFX5p44sGXKJd1mFbA9AY5F0vfnafF5CC4pn8MRgLfkJtbGEJQWyoHZc8Gl7J8721Njy2aU3hQBH/BLNdRuTdbQQ3OkkEspG0OeK1rMOS9So3wExA9AMjke8ZU8i4xJIAHIOcd0JEhq4X0xt/122hahEW6MrzaG5oH2vn2Wf1mmYlnSfKBOXbrpQoORreqOK1LMU8ssUpaZd6lidQv0PKrkz4lLJTDdWRVPk5LwVSLxhJbGIL0RwXSVhYpUUQFwexFCIlsfNkplQoWp3vsozcCVCt8eORR9svWhIlGtNDYS9jltwA4gswCbpKZCvPOCsPQqVLgLIfA==;
 s=purelymail3; d=purelymail.com; v=1;
 bh=7bSDIcT0me2PPCAF4vwl+p1Y429RLlnYfXPoBjQbCxg=;
 h=Feedback-ID:Received:Received:From:To:Subject:Date; 
Feedback-ID: 20115:3760:null:purelymail
X-Pm-Original-To: 78264 <at> debbugs.gnu.org
Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 1487001187; 
 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384);
 Sat, 10 May 2025 08:45:07 +0000 (UTC)
Received: by zephyr.silentflame.com (Postfix, from userid 1000)
 id 4ADE9941353; Sat, 10 May 2025 09:45:05 +0100 (BST)
From: Sean Whitton <spwhitton@HIDDEN>
To: 78264 <at> debbugs.gnu.org
Subject: Re: bug#78264: [PATCH] simple.el (delete-trailing-whitespace-mode):
 New minor mode
In-Reply-To: <jwv5xif11yl.fsf@HIDDEN>
References: <jwv5xif11yl.fsf@HIDDEN>
Date: Sat, 10 May 2025 09:45:05 +0100
Message-ID: <874ixsx3am.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 78264
Cc: Stefan Monnier <monnier@HIDDEN>,
 EditorConfig Team <editorconfig@HIDDEN>
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.0 (-)

Hello,

Seems reasonable, though can we make sure Emacs will let you enable it
from .dir-locals.el for a repository without generating warnings?
I.e. set whatever is needed to trust it as a minor mode enabled from
there (which may be nothing).

-- 
Sean Whitton




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

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


Received: (at submit) by debbugs.gnu.org; 5 May 2025 16:02:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon May 05 12:02:16 2025
Received: from localhost ([127.0.0.1]:41982 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uByGk-0001uL-Tl
	for submit <at> debbugs.gnu.org; Mon, 05 May 2025 12:02:16 -0400
Received: from lists.gnu.org ([2001:470:142::17]:49054)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1uByGf-0001tr-9P
 for submit <at> debbugs.gnu.org; Mon, 05 May 2025 12:02:13 -0400
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 <monnier@HIDDEN>)
 id 1uByGZ-0001G6-2N
 for bug-gnu-emacs@HIDDEN; Mon, 05 May 2025 12:02:03 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@HIDDEN>)
 id 1uByGV-0004sT-Ez
 for bug-gnu-emacs@HIDDEN; Mon, 05 May 2025 12:02:02 -0400
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 74E1C10013E
 for <bug-gnu-emacs@HIDDEN>; Mon,  5 May 2025 12:01:57 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1746460912;
 bh=wSs0eaJpUGnBfCoYMv/i4+KQhcfJO5YbNhtVPue+vBY=;
 h=From:To:Subject:Date:From;
 b=Zsg9D1W8/6W+i2S5gh3yJ5XP+1TrxRJfveRP8ImToCMAwIA4af6ZjZSEU0cDVuNKE
 nZmUrS0cR+M0pFcPYXusUl7pzOs+4KkSqXeteEryiWvPJTm5MRrWqWPcdhgkrYdUun
 ubBeOK9Ab125KW99KDECWdLZ/bKwbPHa0rexL3TgBIr+UADAD7LwzBc5n0L8OIbg6X
 53uY72yLXmiS/NBpFVgdZ3glM+9SOB6OZkRsMCS6AHEw2+eWqJIvS11rCEtfUG0wrR
 Qr4RtJBXnTPbbdv85Ijmk6H7OCfuHVxuhROVD/sMySusK5NuT02TDYX4qTt5DY/mgt
 PbOb3Uktb7GaQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 1C14A100029
 for <bug-gnu-emacs@HIDDEN>; Mon,  5 May 2025 12:01:52 -0400 (EDT)
Received: from alfajor (modemcable005.21-80-70.mc.videotron.ca [70.80.21.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 0328012026A
 for <bug-gnu-emacs@HIDDEN>; Mon,  5 May 2025 12:01:51 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: [PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode
X-Debbugs-Cc: <monnier@HIDDEN>, EditorConfig Team
 <editorconfig@HIDDEN>
Date: Mon, 05 May 2025 12:01:22 -0400
Message-ID: <jwv5xif11yl.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.245 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
Received-SPF: pass client-ip=132.204.25.50;
 envelope-from=monnier@HIDDEN; helo=mailscanner.iro.umontreal.ca
X-Spam_score_int: -42
X-Spam_score: -4.3
X-Spam_bar: ----
X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3,
 RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.0 (/)
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: -1.0 (-)

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

Tags: patch

While

    (add-hook 'before-save-hook #'delete-trailing-whitespace nil t)

is simple enough to put into one's init file, it's a bit rough around
the edges (e.g. for read-only buffers, or interaction with
editorconfig).  So I suggest we add a simple
`delete-trailing-whitespace-mode` minor mode.

Comments?  Objections?


        Stefan


 In GNU Emacs 31.0.50 (build 1, i686-pc-linux-gnu, GTK+ Version 3.24.49,
 cairo version 1.18.4) of 2025-05-01 built on alfajor
Repository revision: 3555aa795435c6c150e9291386cb776acd35e564
Repository branch: work
Windowing system distributor 'The X.Org Foundation', version 11.0.12101016
System Description: Debian GNU/Linux trixie/sid

Configured using:
 'configure -C --enable-checking --enable-check-lisp-object-type --with-modules --with-cairo --with-tiff=ifavailable
 'CFLAGS=-Wall -g3 -Og -Wno-pointer-sign'
 PKG_CONFIG_PATH=/home/monnier/lib/pkgconfig'


--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
 filename=0001-simple.el-delete-trailing-whitespace-mode-New-minor-.patch

From 5740c9b27883de86888df8d201e5daed97d7dd0b Mon Sep 17 00:00:00 2001
From: Stefan Monnier <monnier@HIDDEN>
Date: Mon, 5 May 2025 11:55:29 -0400
Subject: [PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode

Partly motivated by bug#78097.

* lisp/simple.el (delete-trailing-whitespace-if-possible): New function.
(delete-trailing-whitespace-mode): New minor mode.

* lisp/editorconfig.el (editorconfig-trim-whitespaces-mode):
Change default to `delete-trailing-whitespace-mode`.
(editorconfig--get-trailing-ws): Simplify accordingly.
(editorconfig--add-hook-safe-p): Delete function.  Don't touch
`safe-local-eval-function` any more.
---
 etc/NEWS             |  4 ++++
 lisp/editorconfig.el | 38 +++++++++++---------------------------
 lisp/simple.el       | 15 +++++++++++++++
 3 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 146cdedaa43..8efb6e6ae07 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2034,6 +2034,10 @@ the file name, using the minibuffer's "future history".
 
 * New Modes and Packages in Emacs 31.1
 
+** New minor mode 'delete-trailing-whitespace-mode'.
+A simple buffer-local mode that runs 'delete-trailing-whitespace'
+before saving the buffer.
+
 ** New major mode 'conf-npmrc-mode'.
 A major mode based on 'conf-mode' for editing ".npmrc" files.
 
diff --git a/lisp/editorconfig.el b/lisp/editorconfig.el
index 7cdd79fa3b0..bfc8ef46ed3 100644
--- a/lisp/editorconfig.el
+++ b/lisp/editorconfig.el
@@ -277,13 +277,13 @@ editorconfig-indentation-alist
   :version "30.1"
   :risky t)
 
-(defcustom editorconfig-trim-whitespaces-mode nil
+(defcustom editorconfig-trim-whitespaces-mode #'delete-trailing-whitespace-mode
   "Buffer local minor-mode to use to trim trailing whitespaces.
 
 If set, enable that mode when `trim_trailing_whitespace` is set to true.
 Otherwise, use `delete-trailing-whitespace'."
   :version "30.1"
-  :type 'symbol)
+  :type 'function)
 
 (defvar-local editorconfig-properties-hash nil
   "Hash object of EditorConfig properties that was enabled for current buffer.
@@ -542,33 +542,17 @@ editorconfig--delete-trailing-whitespace
   "Call `delete-trailing-whitespace' unless the buffer is read-only."
   (unless buffer-read-only (delete-trailing-whitespace)))
 
-;; Arrange for our (eval . (add-hook ...)) "local var" to be considered safe.
-(defun editorconfig--add-hook-safe-p (exp)
-  (equal exp '(add-hook 'before-save-hook
-                        #'editorconfig--delete-trailing-whitespace nil t)))
-(let ((predicates (get 'add-hook 'safe-local-eval-function)))
-  (when (functionp predicates)
-    (setq predicates (list predicates)))
-  (unless (memq #'editorconfig--add-hook-safe-p predicates)
-    (put 'add-hook 'safe-local-eval-function #'editorconfig--add-hook-safe-p)))
-
 (defun editorconfig--get-trailing-ws (props)
   "Get vars to trim of trailing whitespace according to PROPS."
-  (pcase (gethash 'trim_trailing_whitespace props)
-    ("true"
-     `((eval
-        . ,(if editorconfig-trim-whitespaces-mode
-               `(,editorconfig-trim-whitespaces-mode 1)
-             '(add-hook 'before-save-hook
-                        #'editorconfig--delete-trailing-whitespace nil t)))))
-    ("false"
-     ;; Just do it right away rather than return a (VAR . VAL), which
-     ;; would be probably more trouble than it's worth.
-     (when editorconfig-trim-whitespaces-mode
-       (funcall editorconfig-trim-whitespaces-mode 0))
-     (remove-hook 'before-save-hook
-                  #'editorconfig--delete-trailing-whitespace t)
-     nil)))
+  (let ((fun (or editorconfig-trim-whitespaces-mode
+                 #'delete-trailing-whitespace-mode)))
+    (pcase (gethash 'trim_trailing_whitespace props)
+      ("true" `((eval . (,fun 1))))
+      ("false"
+       ;; Just do it right away rather than return a (VAR . VAL), which
+       ;; would be probably more trouble than it's worth.
+       (funcall fun 0)
+       nil))))
 
 (defun editorconfig--get-line-length (props)
   "Get the max line length (`fill-column') to PROPS."
diff --git a/lisp/simple.el b/lisp/simple.el
index 486092de2c8..f686907ad68 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -888,6 +888,21 @@ delete-trailing-whitespace
   ;; Return nil for the benefit of `write-file-functions'.
   nil)
 
+(defun delete-trailing-whitespace-if-possible ()
+  "Call `delete-trailing-whitespace' unless the buffer is read-only."
+  (unless buffer-read-only (delete-trailing-whitespace)))
+
+(define-minor-mode delete-trailing-whitespace-mode
+  "Delete trailing whitespace before saving the current buffer."
+  :global nil
+  (cond
+   (delete-trailing-whitespace-mode
+    (add-hook 'before-save-hook
+              #'delete-trailing-whitespace-if-possible nil t))
+   (t
+    (remove-hook 'before-save-hook
+                 #'delete-trailing-whitespace-if-possible t))))
+
 (defun newline-and-indent (&optional arg)
   "Insert a newline, then indent according to major mode.
 Indentation is done using the value of `indent-line-function'.
-- 
2.47.2


--=-=-=--





Acknowledgement sent to Stefan Monnier <monnier@HIDDEN>:
New bug report received and forwarded. Copy sent to monnier@HIDDEN, editorconfig@HIDDEN, bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to monnier@HIDDEN, editorconfig@HIDDEN, bug-gnu-emacs@HIDDEN:
bug#78264; 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: Sat, 10 May 2025 09:45:01 UTC

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