From 53af11a2812cef93f8867b5690f0e3a797e0e876 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 26 Sep 2022 12:56:07 +0200 Subject: [PATCH] Fix whitespace-mode in read-only buffers * lisp/whitespace.el (whitespace--update-bob-eob): Don't bug out in read-only buffers (bug#58082). --- lisp/whitespace.el | 65 +++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/lisp/whitespace.el b/lisp/whitespace.el index ae4d8ae3f06..d7b83ef34a5 100644 --- a/lisp/whitespace.el +++ b/lisp/whitespace.el @@ -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))))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -- 2.39.2