]> git.eshelyaron.com Git - emacs.git/commitdiff
Fontify C++ function definitions in c-ts-mode (bug#60529)
authorDaniel Martín <mardani29@yahoo.es>
Tue, 3 Jan 2023 21:08:13 +0000 (22:08 +0100)
committerYuan Fu <casouri@gmail.com>
Wed, 4 Jan 2023 07:04:32 +0000 (00:04 -0700)
* 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

index 1f2a195bf64a5d1069c57e8ddad1dc2960093d37..ffc15e681f7c82072c2daa16ddcfe2d3849a002c 100644 (file)
@@ -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