all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Richard Hansen <rhansen@rhansen.org>,
	73332@debbugs.gnu.org, Jordan Ellis Coppard <jc+o.emacs@wz.ht>
Subject: bug#73332: 31.0.50; Whitespace-mode breaking font-locking
Date: Thu, 19 Sep 2024 11:50:26 -0400	[thread overview]
Message-ID: <jwved5f4ptr.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <86y13o7z7q.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 19 Sep 2024 12:46:33 +0300")

[-- Attachment #1: Type: text/plain, Size: 1208 bytes --]

> Stefan, is there a way of avoiding this effect, perhaps by using a
> function in whitespace-font-lock-keywords?

We could of course replace the regexp with a function and thus do
"whatever we want", as in:

       ,@(when (memq 'missing-newline-at-eof whitespace-active-style)
           ;; Show missing newline.
           `(,(lambda (limit)
                (when (and (re-search-forward ".\\'" nil t)
                           ;; Don't mark the end of the buffer if point is
                           ;; there -- it probably means that the user is
                           ;; typing something at the end of the buffer.
                           (/= whitespace-point (point-max)))
                  (put-text-property (match-beginning 0)
                                     (match-end 0)
                                     'face 'whitespace-missing-newline-at-eof)
                  nil))))

But personally I think the root cause is the use of OVERRIDE and I'd
replace it with `prepend` as in the patch below, but whitespace uses
OVERRIDE "everywhere", whereas my argument would suggest it should use
`prepend` at all those places, which is likely beyond the scope of `emacs-30`.


        Stefan

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: whitespace.patch --]
[-- Type: text/x-diff, Size: 1759 bytes --]

diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 28d131b054c..3693125ec7b 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -739,7 +739,7 @@ whitespace-space-before-tab-regexp
 
 (defcustom whitespace-indentation-regexp
   '("^\t*\\(\\( \\{%d\\}\\)+\\)[^\n\t]"
-    . "^ *\\(\t+\\)[^\n]")
+    . "^ *\\(\t+\\).")
   "Regexps to match indentation whitespace that should be visualized.
 
 The value should be a cons whose car specifies the regexp to match
@@ -1752,7 +1752,7 @@ whitespace-report-region
                        ((eq (car option) 'space-after-tab::space)
                         (whitespace-space-after-tab-regexp 'space))
                        ((eq (car option) 'missing-newline-at-eof)
-                        "[^\n]\\'")
+                        ".\\'")
                        (t
                         (cdr option)))))
                  (when (re-search-forward regexp rend t)
@@ -2188,14 +2188,14 @@ whitespace-color-on
               1 whitespace-space-after-tab t)))
        ,@(when (memq 'missing-newline-at-eof whitespace-active-style)
            ;; Show missing newline.
-           `(("[^\n]\\'" 0
-              ;; Don't mark the end of the buffer is point is there --
+           `((".\\'" 0
+              ;; Don't mark the end of the buffer if point is there --
               ;; it probably means that the user is typing something
               ;; at the end of the buffer.
               (and (/= whitespace-point (point-max))
                    'whitespace-missing-newline-at-eof)
-              t)))))
-    (font-lock-add-keywords nil whitespace-font-lock-keywords t)
+              prepend)))))
+    (font-lock-add-keywords nil whitespace-font-lock-keywords 'append)
     (font-lock-flush)))
 
 

  reply	other threads:[~2024-09-19 15:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-18 12:44 bug#73332: 31.0.50; Whitespace-mode breaking font-locking Jordan Ellis Coppard via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-19  9:46 ` Eli Zaretskii
2024-09-19 15:50   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-09-21 10:49     ` Eli Zaretskii
2024-09-21 14:13       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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=jwved5f4ptr.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=73332@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=jc+o.emacs@wz.ht \
    --cc=monnier@iro.umontreal.ca \
    --cc=rhansen@rhansen.org \
    /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.