]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix whitespace-mode in read-only buffers
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 26 Sep 2022 10:56:07 +0000 (12:56 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 26 Sep 2022 10:56:07 +0000 (12:56 +0200)
* lisp/whitespace.el (whitespace--update-bob-eob): Don't bug out
in read-only buffers (bug#58082).

lisp/whitespace.el

index ae4d8ae3f06e6cfcfe23207c0e1018864077771e..d7b83ef34a5042d131275a69fb0eead727601aad 100644 (file)
@@ -2385,38 +2385,39 @@ purposes)."
     (save-excursion
       (save-restriction
         (widen)
-        (when (or (null beg)
-                  (<= beg (save-excursion
-                            (goto-char whitespace-bob-marker)
-                            ;; Any change in the first non-`empty'
-                            ;; line, even if it's not the first
-                            ;; character in the line, can potentially
-                            ;; cause subsequent lines to become
-                            ;; classified as `empty' (e.g., delete the
-                            ;; "x" from " x").
-                            (forward-line 1)
-                            (point))))
-          (goto-char 1)
-          (set-marker whitespace-bob-marker (point))
-          (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))))
-        (when (or (null end)
-                  (>= end (save-excursion
-                            (goto-char whitespace-eob-marker)
-                            ;; See above comment for the BoB case.
-                            (forward-line -1)
-                            (point))))
-          (goto-char (1+ (buffer-size)))
-          (set-marker whitespace-eob-marker (point))
-          (save-match-data
-            (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))))))))
+        (let ((inhibit-read-only t))
+          (when (or (null beg)
+                    (<= beg (save-excursion
+                              (goto-char whitespace-bob-marker)
+                              ;; Any change in the first non-`empty'
+                              ;; line, even if it's not the first
+                              ;; character in the line, can potentially
+                              ;; cause subsequent lines to become
+                              ;; classified as `empty' (e.g., delete the
+                              ;; "x" from " x").
+                              (forward-line 1)
+                              (point))))
+            (goto-char 1)
+            (set-marker whitespace-bob-marker (point))
+            (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))))
+          (when (or (null end)
+                    (>= end (save-excursion
+                              (goto-char whitespace-eob-marker)
+                              ;; See above comment for the BoB case.
+                              (forward-line -1)
+                              (point))))
+            (goto-char (1+ (buffer-size)))
+            (set-marker whitespace-eob-marker (point))
+            (save-match-data
+              (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)))))))))
 
 \f
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;