GNU bug report logs - #67061
[PATCH] Improve syntax highlighting for python-ts-mode

Previous Next

Package: emacs;

Reported by: Denis Zubarev <dvzubarev <at> yandex.ru>

Date: Sat, 11 Nov 2023 02:23:02 UTC

Severity: normal

Tags: patch

Fixed in version 29.2

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Denis Zubarev <dvzubarev <at> yandex.ru>, Eli Zaretskii <eliz <at> gnu.org>
Cc: "casouri <at> gmail.com" <casouri <at> gmail.com>, "67061 <at> debbugs.gnu.org" <67061 <at> debbugs.gnu.org>
Subject: bug#67061: [PATCH] Improve syntax highlighting for python-ts-mode
Date: Mon, 11 Dec 2023 02:00:57 +0200
On 10/12/2023 14:04, Denis Zubarev wrote:
>  > Arguably, the last 2 lines are "variable references" rather than 
> definitions
> `var := 3`  is assignment expressions. It allows variable assignments to 
> occur inside of larger expressions. For example `if (match := 
> pattern.search(data)) is not None:`.
> It mostly used to define new variables and act on them if some condition 
> is met.

Ah, thanks! This feature is newer than my working experience with Python.

> My rationale for `var *= 3` was that it is shorthand for `var = var * 3` 
> and currently the `var` on the left hand side is fontified with 
> `font-lock-variable-name-face`.

I think ideally, in cases when "var =" is not the first occurrence for 
the same var in a given scope, we wouldn't highlight it as "definition" 
either.

Speaking of font-lock-variable-use-face, I think it would be most useful 
if it helped with noticing typos (meaning, it would only be used for 
references to variables that have been defined previously, according to 
the rules of the language). But for that we still need to implement the 
scope tracking. And before that, well, my personal preference is not to 
highlight the references at all, but opinions differ.

> I wanted shorthand form to be consistent with the full form.
> Your point makes sense too, I don't have strong opinion about this.
> Also I'm not sure now about `var[ii] = 1`, since it is actually 
> accessing the list or dictionary element and 
> `font-lock-variable-use-face` may suit better here.

Yep. To sum up, I would add highlighting to your examples `for var in 
range(3)` and `var := 3` but not others.

> Question about new changes.
> Should I push them to this patch and provide description of new changes,
> or it would be better to wait for review and send them as new patch?

I suggest sending an updated patch for review in this case, but you can 
also wait for Yuan's comments first.

Also, please double-check that the tests pass. It might be something in 
the way I applied your latest patch, but in the example that you gave 
regarding the "type" feature,

  def func(v:dict[ list[ tuple[str] ], int | None] | None):

, only the last "None" gets highlighted for me with font-lock-type-face. 
There are corresponding test failures too. Again, could be something on 
my side, but it would help to verify.




This bug report was last modified 1 year and 176 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.