From: Richard Hansen <rhansen@rhansen.org>
To: Michael Heerdegen <michael_heerdegen@web.de>,
Eli Zaretskii <eliz@gnu.org>
Cc: 60066@debbugs.gnu.org, Bastian Beranek <bastian.beischer@gmail.com>
Subject: bug#60066: 30.0.50; whitespace-mode modifies buffer
Date: Sun, 18 Dec 2022 23:45:03 -0500 [thread overview]
Message-ID: <fba36312-e633-f415-8a6c-b7f9d358b845@rhansen.org> (raw)
In-Reply-To: <87len9tsmz.fsf@web.de>
[-- Attachment #1.1.1: Type: text/plain, Size: 67 bytes --]
Control: tags -1 patch
The attached patch should fix this bug.
[-- Attachment #1.1.2: 0001-whitespace-Fix-unintended-change-in-buffer-modificat.patch --]
[-- Type: text/x-patch, Size: 4733 bytes --]
From e23e8e7c7c6458dcaebed8d34bcaee9f818521ce Mon Sep 17 00:00:00 2001
From: Richard Hansen <rhansen@rhansen.org>
Date: Sun, 18 Dec 2022 23:04:00 -0500
Subject: [PATCH] whitespace: Fix unintended change in buffer modification
status
* lisp/whitespace.el (whitespace--empty-at-bob-matcher,
whitespace--empty-at-eob-matcher, whitespace--update-bob-eob):
Silently add the `font-lock-multiline' text property when highlighting
beginning-of-buffer and end-of-buffer empty lines to prevent Emacs
from running modification hooks or considering the buffer to be
modified (Bug#60066).
* test/lisp/whitespace-tests.el (whitespace-tests--empty-bob-eob-modified):
Add a regression test.
---
lisp/whitespace.el | 28 ++++++++++++++++------------
test/lisp/whitespace-tests.el | 11 +++++++++++
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 2c1520ec6a..558be1841a 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -2283,10 +2283,11 @@ whitespace--empty-at-bob-matcher
(save-excursion (goto-char whitespace-point)
(line-beginning-position)))))
(when (= p 1)
- ;; See the comment in `whitespace--update-bob-eob' for why this
- ;; text property is added here.
- (put-text-property 1 whitespace-bob-marker
- 'font-lock-multiline t))
+ (with-silent-modifications
+ ;; See the comment in `whitespace--update-bob-eob' for why
+ ;; this text property is added here.
+ (put-text-property 1 whitespace-bob-marker
+ 'font-lock-multiline t)))
(when (< p e)
(set-match-data (list p e))
(goto-char e))))
@@ -2307,10 +2308,11 @@ whitespace--empty-at-eob-matcher
empty lines will no longer be EoB empty lines. Highlighting
those lines can be distracting.)"
(when (= limit (1+ (buffer-size)))
- ;; See the comment in `whitespace--update-bob-eob' for why this
- ;; text property is added here.
- (put-text-property whitespace-eob-marker limit
- 'font-lock-multiline t))
+ (with-silent-modifications
+ ;; See the comment in `whitespace--update-bob-eob' for why this
+ ;; text property is added here.
+ (put-text-property whitespace-eob-marker limit
+ 'font-lock-multiline t)))
(let ((b (max (point) whitespace-eob-marker
whitespace-bob-marker ; See comment in the bob func.
(save-excursion (goto-char whitespace-point)
@@ -2452,8 +2454,9 @@ whitespace--update-bob-eob
(save-match-data
(when (looking-at whitespace-empty-at-bob-regexp)
(set-marker whitespace-bob-marker (match-end 1))
- (put-text-property (match-beginning 1) (match-end 1)
- 'font-lock-multiline t))))
+ (with-silent-modifications
+ (put-text-property (match-beginning 1) (match-end 1)
+ 'font-lock-multiline t)))))
(when (or (null end)
(>= end (save-excursion
(goto-char whitespace-eob-marker)
@@ -2466,8 +2469,9 @@ whitespace--update-bob-eob
(when (whitespace--looking-back
whitespace-empty-at-eob-regexp)
(set-marker whitespace-eob-marker (match-beginning 1))
- (put-text-property (match-beginning 1) (match-end 1)
- 'font-lock-multiline t)))))))))
+ (with-silent-modifications
+ (put-text-property (match-beginning 1) (match-end 1)
+ 'font-lock-multiline t))))))))))
\f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/test/lisp/whitespace-tests.el b/test/lisp/whitespace-tests.el
index 330fc335ea..7079c1ea5e 100644
--- a/test/lisp/whitespace-tests.el
+++ b/test/lisp/whitespace-tests.el
@@ -334,6 +334,17 @@ whitespace-tests--empty-bob-eob-read-only-buffer
"«:whitespace-empty:\n"
"»")))))
+(ert-deftest whitespace-tests--empty-bob-eob-modified ()
+ "Regression test for Bug#60066."
+ (whitespace-tests--with-test-buffer '()
+ (insert "\nx\n\n")
+ (goto-char 2)
+ (set-buffer-modified-p nil)
+ (let ((whitespace-style '(face empty)))
+ (whitespace-mode 1)
+ (should (not (buffer-modified-p))))))
+
+
(ert-deftest whitespace-tests--indirect-clone-breaks-base-markers ()
"Specific regression test for Bug#59618."
(whitespace-tests--with-test-buffer '(face empty)
--
2.39.0
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2022-12-19 4:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-14 14:26 bug#60066: 30.0.50; whitespace-mode modifies buffer Bastian Beranek
2022-12-14 16:14 ` Eli Zaretskii
2022-12-14 16:53 ` Bastian Beranek
2022-12-14 17:02 ` Eli Zaretskii
2022-12-15 0:31 ` Michael Heerdegen
2022-12-19 4:45 ` Richard Hansen [this message]
2022-12-19 10:13 ` Bastian Beranek
2022-12-19 13:46 ` Eli Zaretskii
2022-12-19 13:46 ` Eli Zaretskii
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fba36312-e633-f415-8a6c-b7f9d358b845@rhansen.org \
--to=rhansen@rhansen.org \
--cc=60066@debbugs.gnu.org \
--cc=bastian.beischer@gmail.com \
--cc=eliz@gnu.org \
--cc=michael_heerdegen@web.de \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.