Subject: bug#71784: 31.0.50; Inconsistent fontification for field_identifier in c++-ts-mode

From: Yuan Fu <[email-masked]>
Date: Thu, 27 Jun 2024 00:16:13 -0700

> On Jun 26, 2024, at 7:13 AM, Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors <[email-masked]> wrote:
> 
> 
> Hi:
> 
> Using the c++-ts-mode I found that there is some inconsistent
> fontification for the `fields_identifier`:
> 
> See the fontification in this example with `emacs -Q`.
> 
> ```test.cpp
> 
> std::string key;
> bool inserted;
> 
> struct name_t {
> std::string key;
> bool inserted;
> };
> 
> name_t keys = {"aaa", true};
> 
> keys.inserted = false;
> bool a = keys.inserted;
> ```
> 
> 1. The `keys.inserted` values are shown differently before or after the
> = (the inserted word is fontified is some cases, but not in all)

What’s the value of treesit-font-lock-level for you? If it’s 4, they should be fontified the same. On level 3, only LHS is fontified.

> 
> 2. The variable names are fontified differently outside or
> inside the struct.

I mean, the “variable name” inside a structure is a field, not a variable, so it makes sense that they are fontified differently. Variable has font-lock-variable-name-face, field has font-lock-field-name-face. Also variable and field face are the same in the default theme, so they should look the same nevertheless.

> 
> 3. The escape sequence (\t) is fontified differently to the rest of the
> text inside the string. I don't know if that is intentional or not. If
> it is intentional, just ignore this comment.

Yeah it’s intentional.

> 
> The inconsistencies 1 and 2 are not only different to c++-mode but they
> are semantically incorrect.

Yuan