From 731ad886d0cfbf795572c6323e011986250e9708 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 21 Sep 2024 13:41:21 +0300 Subject: [PATCH] Fix 'whitespace-mode' with 'missing-newline-at-eof' * lisp/whitespace.el (whitespace-post-command-hook): Refontify when point moves if 'missing-newline-at-eof' is in 'whitespace-active-style'. (Bug#73332) (cherry picked from commit 01ebe6de8954b2381bfba31038a0bd0669e33910) --- lisp/whitespace.el | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lisp/whitespace.el b/lisp/whitespace.el index 28d131b054c..d1b1f84f923 100644 --- a/lisp/whitespace.el +++ b/lisp/whitespace.el @@ -2333,10 +2333,22 @@ Also refontify when necessary." (font-lock-flush whitespace-eob-marker (1+ (buffer-size))))) (setq-local whitespace-buffer-changed nil) (setq whitespace-point (point)) ; current point position - (let ((refontify (and (eolp) ; It is at end of line ... - ;; ... with trailing SPACE or TAB - (or (memq (preceding-char) '(?\s ?\t))) - (line-beginning-position))) + (let ((refontify (or (and (eolp) ; It is at end of line ... + ;; ... with trailing SPACE or TAB + (or (memq (preceding-char) '(?\s ?\t))) + (line-beginning-position)) + (and (memq 'missing-newline-at-eof + ;; If user requested to highlight + ;; EOB without a newline... + whitespace-active-style) + ;; ...and the buffer is not empty... + (not (= (point-min) (point-max))) + (= (point-max) (without-restriction (point-max))) + ;; ...and no newline at EOB... + (not (eq (char-before (point-max)) ?\n)) + ;; ...then refontify the last character in + ;; the buffer + (max (1- (point-max)) (point-min))))) (ostart (overlay-start whitespace-point--used))) (cond ((not refontify) -- 2.39.5