emacs-diffs
[Top][All Lists]
Advanced

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

emacs-29 c786afcbb9 1/2: Fontify C++ function definitions in c-ts-mode (


From: Yuan Fu
Subject: emacs-29 c786afcbb9 1/2: Fontify C++ function definitions in c-ts-mode (bug#60529)
Date: Wed, 4 Jan 2023 02:04:45 -0500 (EST)

branch: emacs-29
commit c786afcbb9f5c4edf845beae08bdaa11d168a42f
Author: Daniel Martín <mardani29@yahoo.es>
Commit: Yuan Fu <casouri@gmail.com>

    Fontify C++ function definitions in c-ts-mode (bug#60529)
    
    * lisp/progmodes/c-ts-mode.el (c-ts-mode--declarator-identifier):
    Teach the code how to extract the declarator of a node of type
    "qualified_identifier".
    (c-ts-mode--fontify-declarator): Consider the case where the
    identifier in a function declarator is buried inside
    "qualifier_identifier" nodes.
---
 lisp/progmodes/c-ts-mode.el | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 1f2a195bf6..ffc15e681f 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -430,6 +430,9 @@ MODE is either `c' or `cpp'."
     ((or "function_declarator" "array_declarator" "init_declarator")
      (c-ts-mode--declarator-identifier
       (treesit-node-child-by-field-name node "declarator")))
+    ("qualified_identifier"
+     (c-ts-mode--declarator-identifier
+      (treesit-node-child-by-field-name node "name")))
     ;; Terminal case.
     ((or "identifier" "field_identifier")
      node)))
@@ -439,7 +442,14 @@ MODE is either `c' or `cpp'."
 For NODE, OVERRIDE, START, END, and ARGS, see
 `treesit-font-lock-rules'."
   (let* ((identifier (c-ts-mode--declarator-identifier node))
-         (face (pcase (treesit-node-type (treesit-node-parent identifier))
+         (qualified-root
+          (treesit-parent-while (treesit-node-parent identifier)
+                                (lambda (node)
+                                  (equal (treesit-node-type node)
+                                         "qualified_identifier"))))
+         (face (pcase (treesit-node-type (treesit-node-parent
+                                          (or qualified-root
+                                              identifier)))
                  ("function_declarator" 'font-lock-function-name-face)
                  (_ 'font-lock-variable-name-face))))
     (treesit-fontify-with-override



reply via email to

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