From unknown Sat Jun 14 03:56:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78264: [PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, editorconfig@googlegroups.com, bug-gnu-emacs@gnu.org Resent-Date: Mon, 05 May 2025 16:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 78264 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 78264@debbugs.gnu.org Cc: , EditorConfig Team X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: , EditorConfig Team Received: via spool by submit@debbugs.gnu.org id=B.17464609367342 (code B ref -1); Mon, 05 May 2025 16:03:02 +0000 Received: (at submit) by debbugs.gnu.org; 5 May 2025 16:02:16 +0000 Received: from localhost ([127.0.0.1]:41982 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uByGk-0001uL-Tl for submit@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 ) id 1uByGf-0001tr-9P for submit@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 ) id 1uByGZ-0001G6-2N for bug-gnu-emacs@gnu.org; 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 ) id 1uByGV-0004sT-Ez for bug-gnu-emacs@gnu.org; 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 ; 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 ; 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 ; Mon, 5 May 2025 12:01:51 -0400 (EDT) From: Stefan Monnier Date: Mon, 05 May 2025 12:01:22 -0400 Message-ID: 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@iro.umontreal.ca; 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 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 --=-=-=-- From unknown Sat Jun 14 03:56:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78264: [PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode Resent-From: Sean Whitton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 May 2025 08:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78264 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 78264@debbugs.gnu.org Cc: Stefan Monnier , EditorConfig Team Received: via spool by 78264-submit@debbugs.gnu.org id=B78264.174686671710053 (code B ref 78264); Sat, 10 May 2025 08:46:02 +0000 Received: (at 78264) by debbugs.gnu.org; 10 May 2025 08:45:17 +0000 Received: from localhost ([127.0.0.1]:43617 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uDfpd-0002c5-1W for submit@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 ) id 1uDfpZ-0002Y7-Tq for 78264@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@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 In-Reply-To: References: Date: Sat, 10 May 2025 09:45:05 +0100 Message-ID: <874ixsx3am.fsf@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Sat Jun 14 03:56:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78264: [PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 May 2025 09:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78264 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Sean Whitton Cc: 78264@debbugs.gnu.org, monnier@iro.umontreal.ca, editorconfig@googlegroups.com Received: via spool by 78264-submit@debbugs.gnu.org id=B78264.174686824415724 (code B ref 78264); Sat, 10 May 2025 09:11:02 +0000 Received: (at 78264) by debbugs.gnu.org; 10 May 2025 09:10:44 +0000 Received: from localhost ([127.0.0.1]:43708 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uDgEG-00045X-9p for submit@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 ) id 1uDgEC-00045J-Ti for 78264@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 ) 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@gnu.org> From: Eli Zaretskii In-Reply-To: <874ixsx3am.fsf@zephyr.silentflame.com> (message from Sean Whitton on Sat, 10 May 2025 09:45:05 +0100) References: <874ixsx3am.fsf@zephyr.silentflame.com> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: Stefan Monnier , > EditorConfig Team > From: Sean Whitton > 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)? From unknown Sat Jun 14 03:56:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78264: [PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 May 2025 09:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78264 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Sean Whitton Cc: 78264@debbugs.gnu.org, EditorConfig Team Received: via spool by 78264-submit@debbugs.gnu.org id=B78264.174687019123333 (code B ref 78264); Sat, 10 May 2025 09:44:02 +0000 Received: (at 78264) by debbugs.gnu.org; 10 May 2025 09:43:11 +0000 Received: from localhost ([127.0.0.1]:43999 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uDgje-00064H-Rt for submit@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 ) id 1uDgjY-00063N-Iz for 78264@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 In-Reply-To: <874ixsx3am.fsf@zephyr.silentflame.com> Message-ID: References: <874ixsx3am.fsf@zephyr.silentflame.com> 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Sat Jun 14 03:56:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78264: [PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode Resent-From: Sean Whitton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 May 2025 11:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78264 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii Cc: 78264@debbugs.gnu.org, monnier@iro.umontreal.ca, editorconfig@googlegroups.com Received: via spool by 78264-submit@debbugs.gnu.org id=B78264.174687481320317 (code B ref 78264); Sat, 10 May 2025 11:01:02 +0000 Received: (at 78264) by debbugs.gnu.org; 10 May 2025 11:00:13 +0000 Received: from localhost ([127.0.0.1]:44475 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uDhwD-0005Hb-8K for submit@debbugs.gnu.org; Sat, 10 May 2025 07:00:13 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:59766) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uDhw8-0005A8-Pb for 78264@debbugs.gnu.org; Sat, 10 May 2025 07:00:11 -0400 DKIM-Signature: a=rsa-sha256; b=RXBm35bB+URqiQAhUtpTI+mWa7jxzfGlIyQMDAjLBsDXJh01Q8ZaS48+M8jfEYLMztwilJaRFkw7WXBuWZ9Kn8SboD8bFJTrdEXoxpjCzOv53PR7BnxIeJiLK/q0bd3f2XkA6Z0aqYdVzs3IY2YBO6i1NCTa7unwws9uTvMcZ5TX0OdN3Eh1xc1rklk9YBQTl9Upfzmdue/Bure7fwUuiaEYFV/sVfI6gpYl+2DOVbCULSCPsb3hzG65L9lBvtlU5GjBg2yriGBqeLp6cMuVbYiKQab3T4LI3q/P31PgM/vizRY2hZghleXsPCeCjDl6E6cUur5iHT0f6oKj+SGhUg==; s=purelymail3; d=spwhitton.name; v=1; bh=UVOq+zIOhdLmSLHO/A0I7p0GqOXBLOgEHLXR4H2seGU=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=Se4bYazyG8plSXcltjheZa8HVz8ByWdJCUFEVnwrczRmA19CC1LErOy9WKIG3PWWKkBIS+LWSw7Qo++wAforaEd1EmV5koh9E93LKspwgVqzRN/tKfyvCHnfGv+Q6qTnm7mwriskbLXVveQDn8x/z8U8YAWU820d6wIRv0xn+ohUJT77ogDFO0qerc1vh2EdkMIaY9HVaA5B1Q3FkgYz3BBk/oPh9a9M0PbpB/mX8luP4KdUldY3LZHyPryDq1OQy/bo7lOM8yS/LDeD90d/5qlDGAVbe/WWgcd82OyBjpsdrcrfj6FhDb30gH0qJo7DVqLl3Nje7UMCitDxZ4kKDg==; s=purelymail3; d=purelymail.com; v=1; bh=UVOq+zIOhdLmSLHO/A0I7p0GqOXBLOgEHLXR4H2seGU=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 78264@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 439056939; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sat, 10 May 2025 11:00:00 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id AAD069412A0; Sat, 10 May 2025 11:59:59 +0100 (BST) From: Sean Whitton In-Reply-To: <86tt5sbzlk.fsf@gnu.org> References: <874ixsx3am.fsf@zephyr.silentflame.com> <86tt5sbzlk.fsf@gnu.org> Date: Sat, 10 May 2025 11:59:59 +0100 Message-ID: <87msbkvihc.fsf@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello, On Sat 10 May 2025 at 12:10pm +03, Eli Zaretskii wrote: >> Cc: Stefan Monnier , >> EditorConfig Team >> From: Sean Whitton >> 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)? True, it will probably be enabled by major mode, which .dir-locals.el supports. -- Sean Whitton From unknown Sat Jun 14 03:56:29 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Stefan Monnier Subject: bug#78264: closed (Re: bug#78264: [PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode) Message-ID: References: X-Gnu-PR-Message: they-closed 78264 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 78264@debbugs.gnu.org Date: Mon, 12 May 2025 16:42:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1747068122-20098-1" This is a multi-part message in MIME format... ------------=_1747068122-20098-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #78264: [PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 78264@debbugs.gnu.org. --=20 78264: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D78264 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1747068122-20098-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 78264-done) by debbugs.gnu.org; 12 May 2025 16:41:53 +0000 Received: from localhost ([127.0.0.1]:54383 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uEWDx-0005Dg-Ae for submit@debbugs.gnu.org; Mon, 12 May 2025 12:41:53 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:7631) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uEWDv-0005DL-AL for 78264-done@debbugs.gnu.org; Mon, 12 May 2025 12:41:52 -0400 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 290E310013E; Mon, 12 May 2025 12:41:45 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1747068100; bh=yLKyWSMz6vgZVDjFU20oV0Ms12uN0a/r83QSPiUpYqc=; h=From:To:Subject:In-Reply-To:References:Date:From; b=os4q2z4HKAUEueGSOn4XErSzZGR3BqRPXvM9dSRB3sA7Sqdp/wIV+Iq9AVZPMo197 SKjNOWzXoIYlS8skyyxSz8NWetdDysfTwUXpDZd6d7z7b/A0eVU7Bc+AJLkuP3bQuJ pi9loTc9pDkqNSr6Ktkflbew7a3nbvMm5JhfpH4j6pyEoC8YlKMsEDcqAvrnhtalB6 WYNEHxRhJOlfnXFXDdT/NAJhroa8RdB4FgzAg/LjGPV1/3Rrrb5Fd/wZmCLqaW07+Z bttEzOCRLEvLck7KhqRtBFxGKg3zao/BvbyX2urbFGus9xETGH2VxnGRwAfHAYS/Zf R2lv38E3p9YKA== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 24E80100029; Mon, 12 May 2025 12:41:40 -0400 (EDT) Received: from alfajor (bras-base-mtrlpq42zf4-grc-13-70-24-234-232.dsl.bell.ca [70.24.234.232]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id F003D1203BF; Mon, 12 May 2025 12:41:39 -0400 (EDT) From: Stefan Monnier To: 78264-done@debbugs.gnu.org Subject: Re: bug#78264: [PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode In-Reply-To: Message-ID: References: Date: Mon, 12 May 2025 12:41:39 -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.417 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-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Pushed to `master`, closing, Stefan ------------=_1747068122-20098-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 5 May 2025 16:02:16 +0000 Received: from localhost ([127.0.0.1]:41982 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uByGk-0001uL-Tl for submit@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 ) id 1uByGf-0001tr-9P for submit@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 ) id 1uByGZ-0001G6-2N for bug-gnu-emacs@gnu.org; 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 ) id 1uByGV-0004sT-Ez for bug-gnu-emacs@gnu.org; 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 ; 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 ; 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 ; Mon, 5 May 2025 12:01:51 -0400 (EDT) From: Stefan Monnier To: bug-gnu-emacs@gnu.org Subject: [PATCH] simple.el (delete-trailing-whitespace-mode): New minor mode X-Debbugs-Cc: , EditorConfig Team Date: Mon, 05 May 2025 12:01:22 -0400 Message-ID: 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@iro.umontreal.ca; 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 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 --=-=-=-- ------------=_1747068122-20098-1--