GNU bug report logs - #61215
29.0.60; font-lock broken in diff-mode with long lines

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Wed, 1 Feb 2023 18:21:01 UTC

Severity: normal

Found in version 29.0.60

Full log


View this message in rfc822 format

From: Juri Linkov <juri <at> linkov.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61215 <at> debbugs.gnu.org
Subject: bug#61215: 29.0.60; font-lock broken in diff-mode with long lines
Date: Mon, 06 Feb 2023 19:15:49 +0200
>> If you think the problem is in diff-syntax-fontify-hunk,
>> then I could try to find a working workaround local to diff-mode.
>
> Yes, now this is something for diff-mode to solve: it shouldn't assume
> that it will always be able to go to the beginning and the end of a
> hunk, because narrowing could interfere with that.  Diff-mode should
> have some fallback plan for these cases.

After debugging I discovered that the problem is not caused by font-lock
in diff-mode.  The problem is in easy-mmode-define-navigation.
diff-mode uses it to navigate diff hunks.  It supports such a feature
that when the user narrowed the diff buffer, it puts narrowing back
after moving to the next hunk.  But this fails when the diff buffer
is narrowed automatically by long-line-optimizations.  If there is
no way to distinguish whether the narrowing is automatic by long-lines
or manual by the user, this patch fixes the problem.  It works without
errors, and even highlights first 250000 characters of the long line:

diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 5721470ad0d..d9176061434 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -782,7 +782,10 @@ easy-mmode-define-navigation
          (when-narrowed
           (lambda (body)
             (if (null narrowfun) body
-              `(let ((was-narrowed (prog1 (buffer-narrowed-p) (widen))))
+              `(let ((was-narrowed
+                      (prog1 (unless (long-line-optimizations-p)
+                               (buffer-narrowed-p))
+                        (widen))))
                  ,body
                  (when was-narrowed (funcall #',narrowfun)))))))
     (unless name (setq name base-name))




This bug report was last modified 2 years and 76 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.