From: Daniel Martín Date: Tue, 3 Jan 2023 21:08:13 +0000 (+0100) Subject: Fontify C++ function definitions in c-ts-mode (bug#60529) X-Git-Tag: emacs-29.0.90~843 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c786afcbb9f5c4edf845beae08bdaa11d168a42f;p=emacs.git 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. --- diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 1f2a195bf64..ffc15e681f7 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