diff options
| author | Daniel MartÃn | 2023-01-03 22:08:13 +0100 |
|---|---|---|
| committer | Yuan Fu | 2023-01-04 00:04:32 -0700 |
| commit | c786afcbb9f5c4edf845beae08bdaa11d168a42f (patch) | |
| tree | 7d95e9dd42b6c176b61411ab6648a1259afe03c3 | |
| parent | 0d98fac6bbc19c7728d42d6196adf4d392ba3132 (diff) | |
| download | emacs-c786afcbb9f5c4edf845beae08bdaa11d168a42f.tar.gz emacs-c786afcbb9f5c4edf845beae08bdaa11d168a42f.zip | |
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.
| -rw-r--r-- | lisp/progmodes/c-ts-mode.el | 12 |
1 files changed, 11 insertions, 1 deletions
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'." | |||
| 430 | ((or "function_declarator" "array_declarator" "init_declarator") | 430 | ((or "function_declarator" "array_declarator" "init_declarator") |
| 431 | (c-ts-mode--declarator-identifier | 431 | (c-ts-mode--declarator-identifier |
| 432 | (treesit-node-child-by-field-name node "declarator"))) | 432 | (treesit-node-child-by-field-name node "declarator"))) |
| 433 | ("qualified_identifier" | ||
| 434 | (c-ts-mode--declarator-identifier | ||
| 435 | (treesit-node-child-by-field-name node "name"))) | ||
| 433 | ;; Terminal case. | 436 | ;; Terminal case. |
| 434 | ((or "identifier" "field_identifier") | 437 | ((or "identifier" "field_identifier") |
| 435 | node))) | 438 | node))) |
| @@ -439,7 +442,14 @@ MODE is either `c' or `cpp'." | |||
| 439 | For NODE, OVERRIDE, START, END, and ARGS, see | 442 | For NODE, OVERRIDE, START, END, and ARGS, see |
| 440 | `treesit-font-lock-rules'." | 443 | `treesit-font-lock-rules'." |
| 441 | (let* ((identifier (c-ts-mode--declarator-identifier node)) | 444 | (let* ((identifier (c-ts-mode--declarator-identifier node)) |
| 442 | (face (pcase (treesit-node-type (treesit-node-parent identifier)) | 445 | (qualified-root |
| 446 | (treesit-parent-while (treesit-node-parent identifier) | ||
| 447 | (lambda (node) | ||
| 448 | (equal (treesit-node-type node) | ||
| 449 | "qualified_identifier")))) | ||
| 450 | (face (pcase (treesit-node-type (treesit-node-parent | ||
| 451 | (or qualified-root | ||
| 452 | identifier))) | ||
| 443 | ("function_declarator" 'font-lock-function-name-face) | 453 | ("function_declarator" 'font-lock-function-name-face) |
| 444 | (_ 'font-lock-variable-name-face)))) | 454 | (_ 'font-lock-variable-name-face)))) |
| 445 | (treesit-fontify-with-override | 455 | (treesit-fontify-with-override |