emacs-devel
[Top][All Lists]
Advanced

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

Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter


From: Dmitry Gutov
Subject: Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
Date: Sat, 4 Feb 2023 19:32:11 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2

On 04/02/2023 16:49, Alan Mackenzie wrote:
Setting treesit-font-lock-level to 2 for c-ts-mode fontifies variable
definitions, but not parameter definitions.

The patch below seems to fix that (the functionality was basically implemented already). I suggest we install it on emacs-29, for consistency with other modes, among other things.

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 390f67a8e8c..7300074e5c6 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -440,11 +440,10 @@ c-ts-mode--font-lock-settings
       declarator: (_) @c-ts-mode--fontify-declarator)

      (function_definition
-      declarator: (_) @c-ts-mode--fontify-declarator))
+      declarator: (_) @c-ts-mode--fontify-declarator)

-   ;; Should we highlight identifiers in the parameter list?
-   ;; (parameter_declaration
-   ;;  declarator: (_) @c-ts-mode--fontify-declarator))
+     (parameter_declaration
+      declarator: (_) @c-ts-mode--fontify-declarator))

    :language mode
    :feature 'assignment
@@ -552,9 +551,10 @@ c-ts-mode--fontify-declarator
                                               identifier)))
                  ("function_declarator" 'font-lock-function-name-face)
                  (_ 'font-lock-variable-name-face))))
-    (treesit-fontify-with-override
-     (treesit-node-start identifier) (treesit-node-end identifier)
-     face override start end)))
+    (when identifier
+      (treesit-fontify-with-override
+       (treesit-node-start identifier) (treesit-node-end identifier)
+       face override start end))))

 (defun c-ts-mode--fontify-variable (node override start end &rest _)
   "Fontify an identifier node if it is a variable.



reply via email to

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