unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
@ 2023-02-04 14:49 Alan Mackenzie
  2023-02-04 15:04 ` Eli Zaretskii
  2023-02-04 17:32 ` Dmitry Gutov
  0 siblings, 2 replies; 13+ messages in thread
From: Alan Mackenzie @ 2023-02-04 14:49 UTC (permalink / raw)
  To: emacs-devel

Hello, Emacs.

Setting treesit-font-lock-level to 2 for c-ts-mode fontifies variable
definitions, but not parameter definitions.

I have tried (treesit-font-lock-recompute-features '(definition) nil),
but this doesn't do what I want.

This is disappointing.  There appears to be no (documented) way to get
traditional C Mode fontification back.  Perhaps there should be.

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 14:49 c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names Alan Mackenzie
@ 2023-02-04 15:04 ` Eli Zaretskii
  2023-02-04 16:36   ` Alan Mackenzie
  2023-02-04 17:32 ` Dmitry Gutov
  1 sibling, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2023-02-04 15:04 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

> Date: Sat, 4 Feb 2023 14:49:15 +0000
> From: Alan Mackenzie <acm@muc.de>
> 
> Setting treesit-font-lock-level to 2 for c-ts-mode fontifies variable
> definitions, but not parameter definitions.

Thanks for the report, but please report this as a bug, and please
provide a reproducer (what are "parameter definitions"?).

> There appears to be no (documented) way to get traditional C Mode
> fontification back.  Perhaps there should be.

How can one know what are "traditional C Mode fontifications"?  Is
there any concise description of those, in terms of C language
grammar?  If there is such a description, can you point us to it?  And
if it doesn't exist, could you perhaps produce one?



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 15:04 ` Eli Zaretskii
@ 2023-02-04 16:36   ` Alan Mackenzie
  2023-02-04 16:59     ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Alan Mackenzie @ 2023-02-04 16:36 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Hello, Eli.

On Sat, Feb 04, 2023 at 17:04:33 +0200, Eli Zaretskii wrote:
> > Date: Sat, 4 Feb 2023 14:49:15 +0000
> > From: Alan Mackenzie <acm@muc.de>

> > Setting treesit-font-lock-level to 2 for c-ts-mode fontifies variable
> > definitions, but not parameter definitions.

> Thanks for the report, but please report this as a bug, and please
> provide a reproducer (what are "parameter definitions"?).

Done.

> > There appears to be no (documented) way to get traditional C Mode
> > fontification back.  Perhaps there should be.

> How can one know what are "traditional C Mode fontifications"?  Is
> there any concise description of those, in terms of C language
> grammar?  If there is such a description, can you point us to it?  And
> if it doesn't exist, could you perhaps produce one?

My saying "traditional C Mode fontification" was just a pompous way of
saying "parameters fontified as well as variables", but avoiding
repetition.  Sorry for the misunderstanding.

There is no such description, and I can't see that it would be very
helpful to anybody, particularly considering the time taken to write it.

It would be thoroughly unreasonable to expect c-ts-mode to fontify
identically to C Mode in every respect.  But I think having declarations
of both parameters and variables fontified, but not their uses, is a
worthwhile strategy.

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 16:36   ` Alan Mackenzie
@ 2023-02-04 16:59     ` Eli Zaretskii
  0 siblings, 0 replies; 13+ messages in thread
From: Eli Zaretskii @ 2023-02-04 16:59 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

> Date: Sat, 4 Feb 2023 16:36:25 +0000
> Cc: emacs-devel@gnu.org
> From: Alan Mackenzie <acm@muc.de>
> 
> There is no such description, and I can't see that it would be very
> helpful to anybody, particularly considering the time taken to write it.
> 
> It would be thoroughly unreasonable to expect c-ts-mode to fontify
> identically to C Mode in every respect.

Some users might be interested in having a close approximation, so if
someone could provide such a description, we could perhaps have a
recipe in NEWS, or maybe even a defcustom.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 14:49 c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names Alan Mackenzie
  2023-02-04 15:04 ` Eli Zaretskii
@ 2023-02-04 17:32 ` Dmitry Gutov
  2023-02-04 18:13   ` Eli Zaretskii
  2023-02-04 20:09   ` Alan Mackenzie
  1 sibling, 2 replies; 13+ messages in thread
From: Dmitry Gutov @ 2023-02-04 17:32 UTC (permalink / raw)
  To: Alan Mackenzie, emacs-devel

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.



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 17:32 ` Dmitry Gutov
@ 2023-02-04 18:13   ` Eli Zaretskii
  2023-02-04 18:16     ` Dmitry Gutov
  2023-02-04 18:19     ` Eli Zaretskii
  2023-02-04 20:09   ` Alan Mackenzie
  1 sibling, 2 replies; 13+ messages in thread
From: Eli Zaretskii @ 2023-02-04 18:13 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: acm, emacs-devel

> Date: Sat, 4 Feb 2023 19:32:11 +0200
> From: Dmitry Gutov <dgutov@yandex.ru>
> 
> 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.

AFAIU, this patch will fontify variables in function parameter lists
at level 1, not 2, but I don't mind.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 18:13   ` Eli Zaretskii
@ 2023-02-04 18:16     ` Dmitry Gutov
  2023-02-04 18:19     ` Eli Zaretskii
  1 sibling, 0 replies; 13+ messages in thread
From: Dmitry Gutov @ 2023-02-04 18:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: acm, emacs-devel

On 04/02/2023 20:13, Eli Zaretskii wrote:
> this patch will fontify variables in function parameter lists
> at level 1, not 2

That's how other modes do it too.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 18:13   ` Eli Zaretskii
  2023-02-04 18:16     ` Dmitry Gutov
@ 2023-02-04 18:19     ` Eli Zaretskii
  2023-02-04 18:44       ` Dmitry Gutov
  1 sibling, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2023-02-04 18:19 UTC (permalink / raw)
  To: dgutov; +Cc: acm, emacs-devel

> Date: Sat, 04 Feb 2023 20:13:20 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: acm@muc.de, emacs-devel@gnu.org
> 
> > Date: Sat, 4 Feb 2023 19:32:11 +0200
> > From: Dmitry Gutov <dgutov@yandex.ru>
> > 
> > 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.
> 
> AFAIU, this patch will fontify variables in function parameter lists
> at level 1, not 2, but I don't mind.

Btw, we should probably do the same for C++ and Java.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 18:19     ` Eli Zaretskii
@ 2023-02-04 18:44       ` Dmitry Gutov
  0 siblings, 0 replies; 13+ messages in thread
From: Dmitry Gutov @ 2023-02-04 18:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: acm, emacs-devel

On 04/02/2023 20:19, Eli Zaretskii wrote:
>> Date: Sat, 04 Feb 2023 20:13:20 +0200
>> From: Eli Zaretskii<eliz@gnu.org>
>> Cc:acm@muc.de,emacs-devel@gnu.org
>>
>>> Date: Sat, 4 Feb 2023 19:32:11 +0200
>>> From: Dmitry Gutov<dgutov@yandex.ru>
>>>
>>> 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.
>> AFAIU, this patch will fontify variables in function parameter lists
>> at level 1, not 2, but I don't mind.
> Btw, we should probably do the same for C++ and Java.

AFAICS, Java has this already, and c++-ts-mode will be affected by the 
proposed patch (c and c++ share c-ts-mode--font-lock-settings).



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 17:32 ` Dmitry Gutov
  2023-02-04 18:13   ` Eli Zaretskii
@ 2023-02-04 20:09   ` Alan Mackenzie
  2023-02-04 20:19     ` Eli Zaretskii
  1 sibling, 1 reply; 13+ messages in thread
From: Alan Mackenzie @ 2023-02-04 20:09 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Eli Zaretskii, emacs-devel

Hello, Dmitry.

On Sat, Feb 04, 2023 at 19:32:11 +0200, Dmitry Gutov wrote:
> 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.

That patch is just the job!  Thanks!

I don't understand what Eli meant when he wrote that it was only
effective on "level 1".  Does this mean treesit-font-lock-level?  I see
the fontification of parameter names that I wanted with your patch when
treesit-font-lock-level is 2.

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 20:09   ` Alan Mackenzie
@ 2023-02-04 20:19     ` Eli Zaretskii
  2023-02-04 20:42       ` Alan Mackenzie
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2023-02-04 20:19 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: dgutov, emacs-devel

> Date: Sat, 4 Feb 2023 20:09:12 +0000
> Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
> From: Alan Mackenzie <acm@muc.de>
> 
> I don't understand what Eli meant when he wrote that it was only
> effective on "level 1".  Does this mean treesit-font-lock-level?

Yes.

> I see the fontification of parameter names that I wanted with your
> patch when treesit-font-lock-level is 2.

Try level 1, you should see that there as well.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 20:19     ` Eli Zaretskii
@ 2023-02-04 20:42       ` Alan Mackenzie
  2023-02-05  5:33         ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Alan Mackenzie @ 2023-02-04 20:42 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: dgutov, emacs-devel

Hello, Eli.

On Sat, Feb 04, 2023 at 22:19:24 +0200, Eli Zaretskii wrote:
> > Date: Sat, 4 Feb 2023 20:09:12 +0000
> > Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
> > From: Alan Mackenzie <acm@muc.de>

> > I don't understand what Eli meant when he wrote that it was only
> > effective on "level 1".  Does this mean treesit-font-lock-level?

> Yes.

> > I see the fontification of parameter names that I wanted with your
> > patch when treesit-font-lock-level is 2.

> Try level 1, you should see that there as well.

Ah, I've understood you, now.  The bit I missed was that fontification
features active at level n are also active for levels greater than n.

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names.
  2023-02-04 20:42       ` Alan Mackenzie
@ 2023-02-05  5:33         ` Eli Zaretskii
  0 siblings, 0 replies; 13+ messages in thread
From: Eli Zaretskii @ 2023-02-05  5:33 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: dgutov, emacs-devel

> Date: Sat, 4 Feb 2023 20:42:00 +0000
> Cc: dgutov@yandex.ru, emacs-devel@gnu.org
> From: Alan Mackenzie <acm@muc.de>
> 
> > > I see the fontification of parameter names that I wanted with your
> > > patch when treesit-font-lock-level is 2.
> 
> > Try level 1, you should see that there as well.
> 
> Ah, I've understood you, now.  The bit I missed was that fontification
> features active at level n are also active for levels greater than n.

This should be conveyed by the doc string of treesit-font-lock-level.
If it isn't, we need to make that more clear.



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-02-05  5:33 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-04 14:49 c-ts-mode: (eq treesit-font-lock-level 2) doesn't fontify parameter names Alan Mackenzie
2023-02-04 15:04 ` Eli Zaretskii
2023-02-04 16:36   ` Alan Mackenzie
2023-02-04 16:59     ` Eli Zaretskii
2023-02-04 17:32 ` Dmitry Gutov
2023-02-04 18:13   ` Eli Zaretskii
2023-02-04 18:16     ` Dmitry Gutov
2023-02-04 18:19     ` Eli Zaretskii
2023-02-04 18:44       ` Dmitry Gutov
2023-02-04 20:09   ` Alan Mackenzie
2023-02-04 20:19     ` Eli Zaretskii
2023-02-04 20:42       ` Alan Mackenzie
2023-02-05  5:33         ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).