unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Gregory Heytings <gregory@heytings.org>
To: 56848@debbugs.gnu.org
Subject: bug#56848: CC Mode fontification bug
Date: Sun, 31 Jul 2022 00:16:37 +0000	[thread overview]
Message-ID: <8c7321f2f31d5790f916@heytings.org> (raw)

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


Recipe:

emacs -Q
C-x C-f src/xdisp.c RET
M-g c 28 RET
;; take note of the word there: "window"
M-: (get-char-property 28 'fontified) RET
;; observe that this returns t
M-g g 800 RET
C-v
M-: (get-char-property 28 'fontified) RET
;; observe that this returns nil, because "struct window" is now visible

This is a BUG.

When font locking has put a fontified property and one of the 
font-lock-*-faces on characters in the buffer, a mode should not undo that 
unless it has a very good reason to do so.  Otherwise scrolling again 
through an already fontified buffer calls fontification functions again 
without reason.

Patch attached.

With the patch, scrolling again through an already fontified buffer is 
~25% faster.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Be-conservative-with-occurrences-of-newly-found-types.patch --]
[-- Type: text/x-diff; name=Be-conservative-with-occurrences-of-newly-found-types.patch, Size: 1803 bytes --]

From 4f017e72850a19fa6bfba33663652b8c638bb825 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Sun, 31 Jul 2022 00:04:07 +0000
Subject: [PATCH] Be conservative with occurrences of newly found types.

* lisp/progmodes/cc-fonts.el (c-fontify-new-found-type): Remove the
fontified property on occurrences of newly found types only when
they do not yet have a face property.
---
 lisp/progmodes/cc-fonts.el | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 625010b04b..75936574a1 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -2284,16 +2284,17 @@ c-fontify-new-found-type
 	  (widen)
 	  (goto-char (point-min))
 	  (while (re-search-forward target-re nil t)
-	    (put-text-property (match-beginning 0) (match-end 0)
-			       'fontified nil)
-	    (dolist (win-boundary window-boundaries)
-	      (when (and (< (match-beginning 0) (cdr win-boundary))
-			 (> (match-end 0) (car win-boundary))
-			 (not c-re-redisplay-timer))
-		(setq c-re-redisplay-timer
-		      (run-with-timer 0 nil #'c-force-redisplay
-				      (current-buffer)
-				      (match-beginning 0) (match-end 0)))))))))))
+	    (unless (get-char-property (match-beginning 0) 'face)
+	      (put-text-property (match-beginning 0) (match-end 0)
+				 'fontified nil)
+	      (dolist (win-boundary window-boundaries)
+		(when (and (< (match-beginning 0) (cdr win-boundary))
+			   (> (match-end 0) (car win-boundary))
+			   (not c-re-redisplay-timer))
+		  (setq c-re-redisplay-timer
+			(run-with-timer 0 nil #'c-force-redisplay
+					(current-buffer)
+					(match-beginning 0) (match-end 0))))))))))))
 
 \f
 ;;; C.
-- 
2.35.1


             reply	other threads:[~2022-07-31  0:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-31  0:16 Gregory Heytings [this message]
2022-07-31  5:47 ` bug#56848: CC Mode fontification bug Eli Zaretskii
2022-07-31  8:08   ` Gregory Heytings
2023-01-14 21:28 ` Gregory Heytings
2023-01-15 12:32   ` Alan Mackenzie
2023-01-15 12:52     ` Gregory Heytings

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c7321f2f31d5790f916@heytings.org \
    --to=gregory@heytings.org \
    --cc=56848@debbugs.gnu.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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).