emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 60a8583: C++ Mode: Fix incoorect background fontification of <


From: Alan Mackenzie
Subject: master 60a8583: C++ Mode: Fix incoorect background fontification of <
Date: Sat, 13 Nov 2021 07:00:44 -0500 (EST)

branch: master
commit 60a85834202dc4e117d3e5086ab210bcd293d659
Author: Alan Mackenzie <acm@muc.de>
Commit: Alan Mackenzie <acm@muc.de>

    C++ Mode: Fix incoorect background fontification of <
    
    Where c-record-found-types gets "bound" to itself, we postpone the calling 
of
    c-fontify-new-type on possible new found types until these are confirmed by
    the return from the function tentatively finding these types, for exmaple
    c-forward-<>-arglist.  We check this "binding" by testing the value of
    c-record-found-types.
    
    Correct the background fontification algorithm.
    
    * lisp/progmodes/cc-engine.el (c-record-found-types): Move the definition to
    earlier in the file.
    (c-add-type-1): Check additionally c-record-found-types is nil before 
calling
    c-fontify-new-found-type.
    (c-forward-<>-arglist, c-forward-type): On return from a function which
    collects found types in c-record-found-types, call c-fontify-new-found-types
    for each such type.
    
    * lisp/progmodes/c-fonts.el (c-force-redisplay): Actually fontify the new
    found type.
    (c-fontify-new-found-type): Test for font-lock-mode being enabled.  Remove 
the
    spurious condition on the `fontified' text property being nil before causing
    c-force-redisplay to get called.
---
 lisp/progmodes/cc-engine.el | 28 ++++++++++++++++++++++------
 lisp/progmodes/cc-fonts.el  |  6 ++++--
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index a4568bd..c7b01de 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -6812,6 +6812,13 @@ comment at the start of cc-engine.el for more info."
 (defvar c-found-types nil)
 (make-variable-buffer-local 'c-found-types)
 
+;; Dynamically bound variable that instructs `c-forward-type' to
+;; record the ranges of types that only are found.  Behaves otherwise
+;; like `c-record-type-identifiers'.  Also when this variable is non-nil,
+;; `c-fontify-new-found-type' doesn't get called (yet) for the purported
+;; type.
+(defvar c-record-found-types nil)
+
 (defsubst c-clear-found-types ()
   ;; Clears `c-found-types'.
   (setq c-found-types
@@ -6825,7 +6832,10 @@ comment at the start of cc-engine.el for more info."
   (let ((type (c-syntactic-content from to c-recognize-<>-arglists)))
     (unless (gethash type c-found-types)
       (puthash type t c-found-types)
-      (when (and (eq (string-match c-symbol-key type) 0)
+      (when (and (not c-record-found-types) ; Only call 
`c-fontify-new-fount-type'
+                                       ; when we haven't "bound" c-found-types
+                                       ; to itself in c-forward-<>-arglist.
+                (eq (string-match c-symbol-key type) 0)
                 (eq (match-end 0) (length type)))
        (c-fontify-new-found-type type)))))
 
@@ -8225,11 +8235,6 @@ multi-line strings (but not C++, for example)."
           (setq c-record-ref-identifiers
                 (cons range c-record-ref-identifiers))))))
 
-;; Dynamically bound variable that instructs `c-forward-type' to
-;; record the ranges of types that only are found.  Behaves otherwise
-;; like `c-record-type-identifiers'.
-(defvar c-record-found-types nil)
-
 (defmacro c-forward-keyword-prefixed-id (type)
   ;; Used internally in `c-forward-keyword-clause' to move forward
   ;; over a type (if TYPE is 'type) or a name (otherwise) which
@@ -8459,6 +8464,11 @@ multi-line strings (but not C++, for example)."
                (c-forward-<>-arglist-recur all-types)))
        (progn
          (when (consp c-record-found-types)
+           (let ((cur c-record-found-types))
+             (while (consp (car-safe cur))
+               (c-fontify-new-found-type
+                (buffer-substring-no-properties (caar cur) (cdar cur)))
+               (setq cur (cdr cur))))
            (setq c-record-type-identifiers
                  ;; `nconc' doesn't mind that the tail of
                  ;; `c-record-found-types' is t.
@@ -9184,6 +9194,12 @@ multi-line strings (but not C++, for example)."
 
                (when (and (eq res t)
                           (consp c-record-found-types))
+                 ;; Cause the confirmed types to get fontified.
+                 (let ((cur c-record-found-types))
+                   (while (consp (car-safe cur))
+                     (c-fontify-new-found-type
+                      (buffer-substring-no-properties (caar cur) (cdar cur)))
+                     (setq cur (cdr cur))))
                  ;; Merge in the ranges of any types found by the second
                  ;; `c-forward-type'.
                  (setq c-record-type-identifiers
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 9355409..967464a 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -101,6 +101,7 @@
 (cc-bytecomp-defun c-font-lock-objc-method)
 (cc-bytecomp-defun c-font-lock-invalid-string)
 (cc-bytecomp-defun c-before-context-fl-expand-region)
+(cc-bytecomp-defun c-font-lock-fontify-region)
 
 
 ;; Note that font-lock in XEmacs doesn't expand face names as
@@ -2428,6 +2429,7 @@ higher."
 (defun c-force-redisplay (start end)
   ;; Force redisplay immediately.  This assumes `font-lock-support-mode' is
   ;; 'jit-lock-mode.  Set the variable `c-re-redisplay-timer' to nil.
+  (save-excursion (c-font-lock-fontify-region start end))
   (jit-lock-force-redisplay (copy-marker start) (copy-marker end))
   (setq c-re-redisplay-timer nil))
 
@@ -2436,7 +2438,8 @@ higher."
   ;; buffer.  If TYPE is currently displayed in a window, cause redisplay to
   ;; happen "instantaneously".  These actions are done only when jit-lock-mode
   ;; is active.
-  (when (and (boundp 'font-lock-support-mode)
+  (when (and font-lock-mode
+            (boundp 'font-lock-support-mode)
             (eq font-lock-support-mode 'jit-lock-mode))
     (c-save-buffer-state
        ((window-boundaries
@@ -2455,7 +2458,6 @@ higher."
            (dolist (win-boundary window-boundaries)
              (when (and (< (match-beginning 0) (cdr win-boundary))
                         (> (match-end 0) (car win-boundary))
-                        (c-get-char-property (match-beginning 0) 'fontified)
                         (not c-re-redisplay-timer))
                (setq c-re-redisplay-timer
                      (run-with-timer 0 nil #'c-force-redisplay



reply via email to

[Prev in Thread] Current Thread [Next in Thread]