unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#58082: recent whitespace-mode regression for read-only buffers
@ 2022-09-25 23:17 Kyle Meyer
  2022-09-26 10:56 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2022-09-25 23:17 UTC (permalink / raw)
  To: 58082; +Cc: rhansen, larsi, mip

Before f47a5324f44 (whitespace: Redo BoB/EoB empty line highlighting,
2022-09-11, bug#37467), this snippet runs without an issue:

  (let ((b (generate-new-buffer "ws-read-only-test")))
    (with-current-buffer b
      (insert " ")
      (setq buffer-read-only t)
      (whitespace-mode 1))
    (pop-to-buffer b))

After that commit, activating whitespace mode fails:

  whitespace--update-bob-eob: Buffer is read-only: #<buffer ws-read-only-test>

Perhaps some of the additions in f47a5324f44 should let-bind
inhibit-read-only?





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#58082: recent whitespace-mode regression for read-only buffers
  2022-09-25 23:17 bug#58082: recent whitespace-mode regression for read-only buffers Kyle Meyer
@ 2022-09-26 10:56 ` Lars Ingebrigtsen
  2022-09-26 23:21   ` Richard Hansen
  0 siblings, 1 reply; 4+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-26 10:56 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: 58082, mip, rhansen

Kyle Meyer <kyle@kyleam.com> writes:

> Before f47a5324f44 (whitespace: Redo BoB/EoB empty line highlighting,
> 2022-09-11, bug#37467), this snippet runs without an issue:
>
>   (let ((b (generate-new-buffer "ws-read-only-test")))
>     (with-current-buffer b
>       (insert " ")
>       (setq buffer-read-only t)
>       (whitespace-mode 1))
>     (pop-to-buffer b))
>
> After that commit, activating whitespace mode fails:
>
>   whitespace--update-bob-eob: Buffer is read-only: #<buffer ws-read-only-test>
>
> Perhaps some of the additions in f47a5324f44 should let-bind
> inhibit-read-only?

Yup.  I've now done this in Emacs 29.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#58082: recent whitespace-mode regression for read-only buffers
  2022-09-26 10:56 ` Lars Ingebrigtsen
@ 2022-09-26 23:21   ` Richard Hansen
  2022-09-27 11:44     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Hansen @ 2022-09-26 23:21 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Kyle Meyer; +Cc: 58082, mip


[-- Attachment #1.1.1: Type: text/plain, Size: 108 bytes --]

Good catch Kyle, and thank you for the fix Lars.

Attached are a couple of patches that add a test case.

[-- Attachment #1.1.2: 0001-ert-x-Improve-realism-of-ert-with-test-buffer-select.patch --]
[-- Type: text/x-patch, Size: 1592 bytes --]

From eb8e5828d3fb6917943b4f81a20a1584d3c784d9 Mon Sep 17 00:00:00 2001
From: Richard Hansen <rhansen@rhansen.org>
Date: Mon, 26 Sep 2022 17:07:52 -0400
Subject: [PATCH 1/2] ert-x: Improve realism of `ert-with-test-buffer-selected'

* lisp/emacs-lisp/ert-x.el (ert-with-test-buffer-selected): Set
`inhibit-read-only' and `buffer-read-only' to nil when executing the
body to provide a more realistic test environment.
---
 lisp/emacs-lisp/ert-x.el | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/ert-x.el b/lisp/emacs-lisp/ert-x.el
index f00f1b33d7..bfd796586d 100644
--- a/lisp/emacs-lisp/ert-x.el
+++ b/lisp/emacs-lisp/ert-x.el
@@ -126,7 +126,15 @@ ert-with-test-buffer-selected
                  (body-function
                   . ,(lambda (window)
                        (select-window window t)
-                       (let ((inhibit-modification-hooks nil))
+                       ;; body-function is intended to initialize the
+                       ;; contents of a temporary read-only buffer, so
+                       ;; it is executed with some convenience
+                       ;; changes.  Undo those changes so that the
+                       ;; test buffer behaves more like an ordinary
+                       ;; buffer while the body executes.
+                       (let ((inhibit-modification-hooks nil)
+                             (inhibit-read-only nil)
+                             (buffer-read-only nil))
                          (setq ,ret (progn ,@body))))))
              nil))
          ,ret))))
-- 
2.37.3


[-- Attachment #1.1.3: 0002-whitespace-Add-test-case-for-read-only-buffers-bug-5.patch --]
[-- Type: text/x-patch, Size: 2170 bytes --]

From 69b39ff80b227ab2f4d37ec292a30b11bd367243 Mon Sep 17 00:00:00 2001
From: Richard Hansen <rhansen@rhansen.org>
Date: Mon, 26 Sep 2022 02:12:41 -0400
Subject: [PATCH 2/2] ; whitespace: Add test case for read-only buffers
 (bug#58082)

---
 test/lisp/whitespace-tests.el | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/test/lisp/whitespace-tests.el b/test/lisp/whitespace-tests.el
index 97c30c4d62..fb53543c9e 100644
--- a/test/lisp/whitespace-tests.el
+++ b/test/lisp/whitespace-tests.el
@@ -27,7 +27,8 @@
 (defmacro whitespace-tests--with-test-buffer (style &rest body)
   "Run BODY in a buffer with `whitespace-mode' style STYLE.
 The buffer is displayed in `selected-window', and
-`noninteractive' is set to nil even in batch mode."
+`noninteractive' is set to nil even in batch mode.  If STYLE is
+nil, `whitespace-mode' is left disabled."
   (declare (debug ((style form) def-body))
            (indent 1))
   `(ert-with-test-buffer-selected ()
@@ -37,7 +38,8 @@ whitespace-tests--with-test-buffer
      (let ((noninteractive nil)
            (whitespace-style ,style))
        (font-lock-mode 1)
-       (whitespace-mode 1)
+       ,(when style
+          '(whitespace-mode 1))
        ,@body)))
 
 (defun whitespace-tests--faceup (&rest lines)
@@ -310,6 +312,21 @@ whitespace-tests--empty-eob
                                       "\t\n"
                                       " »"))))
 
+(ert-deftest whitespace-tests--empty-bob-eob-read-only-buffer ()
+  (whitespace-tests--with-test-buffer '()
+    (insert "\nx\n\n")
+    (should (equal (buffer-string) "\nx\n\n"))
+    (setq-local buffer-read-only t)
+    (goto-char 2)
+    (should (equal (line-number-at-pos) 2))
+    (should (equal (- (point) (line-beginning-position)) 0))
+    (let ((whitespace-style '(face empty)))
+      (whitespace-mode 1)
+      (should (whitespace-tests--faceup "«:whitespace-empty:\n"
+                                        "»x\n"
+                                        "«:whitespace-empty:\n"
+                                        "»")))))
+
 (provide 'whitespace-tests)
 
 ;;; whitespace-tests.el ends here
-- 
2.37.3


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#58082: recent whitespace-mode regression for read-only buffers
  2022-09-26 23:21   ` Richard Hansen
@ 2022-09-27 11:44     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-27 11:44 UTC (permalink / raw)
  To: Richard Hansen; +Cc: 58082, mip, Kyle Meyer

Richard Hansen <rhansen@rhansen.org> writes:

> Good catch Kyle, and thank you for the fix Lars.
>
> Attached are a couple of patches that add a test case.

Thanks; pushed to Emacs 29.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-27 11:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-25 23:17 bug#58082: recent whitespace-mode regression for read-only buffers Kyle Meyer
2022-09-26 10:56 ` Lars Ingebrigtsen
2022-09-26 23:21   ` Richard Hansen
2022-09-27 11:44     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).