From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#67061: [PATCH] Improve syntax highlighting for python-ts-mode Date: Tue, 12 Dec 2023 19:49:54 -0800 Message-ID: References: <8734xdni6y.fsf@yandex.ru> <831qcwycbj.fsf@gnu.org> <83v8a3qh6m.fsf@gnu.org> <834jhadvkt.fsf@gnu.org> <7aee7e42-c07d-9131-18a9-4806f07d4267@gutov.dev> <83a5qw7izt.fsf@gnu.org> <172531702081590@mail.yandex.ru> <212931702208489@mail.yandex.ru> <0c6e2e14-b494-a8cb-3893-ffb39577baf9@gutov.dev> <7b17c99d-6e4b-43b3-af93-993901a3a4ea@gmail.com> <95071702343720@mail.yandex.ru> <78ffdcf3-e322-49ea-a0d5-d0485ade9e73@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19552"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: "67061@debbugs.gnu.org" <67061@debbugs.gnu.org> To: Dmitry Gutov , Denis Zubarev , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 13 04:51:21 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rDGHJ-0004xt-Em for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 13 Dec 2023 04:51:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rDGH2-0005ep-KX; Tue, 12 Dec 2023 22:51:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rDGGl-0005e0-2Z for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2023 22:50:49 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rDGGk-0005UW-Pd for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2023 22:50:46 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rDGH0-00045x-Fi for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2023 22:51:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 13 Dec 2023 03:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67061 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 67061-submit@debbugs.gnu.org id=B67061.170243942015682 (code B ref 67061); Wed, 13 Dec 2023 03:51:02 +0000 Original-Received: (at 67061) by debbugs.gnu.org; 13 Dec 2023 03:50:20 +0000 Original-Received: from localhost ([127.0.0.1]:58022 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rDGGJ-00044r-K5 for submit@debbugs.gnu.org; Tue, 12 Dec 2023 22:50:20 -0500 Original-Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:49609) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rDGGH-00044Y-Qd for 67061@debbugs.gnu.org; Tue, 12 Dec 2023 22:50:18 -0500 Original-Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6ce6dd83945so5872580b3a.3 for <67061@debbugs.gnu.org>; Tue, 12 Dec 2023 19:50:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702439396; x=1703044196; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=yPTUSdIJoJLhmihB+QgEtZ5mzNffI8A7rkO2ME40VRA=; b=N7NQodBE9bXwdkzYwjH6qngY7vasOxKw+iw/hIB+rSd1YQhhEbaQzSkIxyb2xkgfKy 3kFj685csrwZnPrDy1DnNF7HDhrvk7AhD64SiPE+ex2miln4VPB5H/KXca//tbWkQg9H 2G4fpdohmVle0cR1X0Yn0gUQdPkZt3/HhYdCxyfY96xokejWXk/TAoR3dR3EdjY7bbde q1YJ3QAEByebmjb8dZkzoY0Lm+LdGXtWZV+/Kmb1JJKiPi3nMd82stJHHh5WYmRXA5Do 52sUpHKKdNP8iF017p9V2j6Rawj4VxPv84lFh/5eNHr9jrOGaVIOkStRfsSNePn2ApJK GilQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702439396; x=1703044196; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yPTUSdIJoJLhmihB+QgEtZ5mzNffI8A7rkO2ME40VRA=; b=wV06qPCdSe5wvm6C6Qfk+CUgQ+DBkzVimbTzZKE6k+24Qt3LL7IP69TIRG12SeQRQ9 K3LOqwA96NKaE/+vu4yF2W+T10GkQXnxD3MjFRO6w+s7tNl1UB6BdzIrxFFEaZSB7XSF iAZEmNk3y/gn76/lWr93RtLIro24mg4rSgBcmqZJqG2784bIScK1oV48265loX9Ou1DT +dF6I6R0BpESkKkC7JUqNbfAD5I2IwO90fGF0qdLCfOcto4JbUf0YSfKqsZ6uqZFykOJ xxf8t7K6X4zSejRdIg+D8ONHoNJ++wy8vcwnq71ov65Nna+elGRFEK1baJa35pAOs6F/ 0R/Q== X-Gm-Message-State: AOJu0YxEXGPaj/PECu4lDwJlNKtGYYXsBzquYZLXBURVMM1AmoRUDtaM 9UJftN9VqqmyNevpThR0pvRb8JYxs8ZAWw== X-Google-Smtp-Source: AGHT+IF2IhMLGBpoB9SGB5Tr3xt6eF5sOE90IPEV/Z4omxRNUSyE5pnOEcGTCSwDoYjnEvpQNOE0Sg== X-Received: by 2002:a05:6a20:1583:b0:18f:c42c:d735 with SMTP id h3-20020a056a20158300b0018fc42cd735mr9839767pzj.99.1702439396051; Tue, 12 Dec 2023 19:49:56 -0800 (PST) Original-Received: from [192.168.1.7] (172-117-161-177.res.spectrum.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id jd21-20020a170903261500b001d347c435ffsm737385plb.36.2023.12.12.19.49.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Dec 2023 19:49:55 -0800 (PST) Content-Language: en-US In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:276107 Archived-At: On 12/12/23 4:44 PM, Dmitry Gutov wrote: > On 12/12/2023 10:24, Yuan Fu wrote: >>> > I think "for var in range(3)" should be part of the "definition" >>> feature >>>   because a variable is defined there. Alongside parameters. >>> I added it to definitions. >> >> Again, if we think of fontification levels, the definition feature is >> about fontifying the function names of definitions, and it's at a low >> level (level 1). Non-essential fontification like "var" shouldn't be >> activated at that level. So I suggest to put it in the variable >> feature, along with many other non-essential fontifications. >> (Variable feature is placed at level 4.) > > I disagree: 'var' in this example is not much different from a > function parameter. It's a definite place where a variable's name > introduced in the current scope. > > Python doesn't have special keywords for variable declarations (unlike > 'let' in JavaScript or typed declaration in C), so the first time a > variable is introduced serves as its declaration. For assignments, we > can't easily determine which is the first time for a given scope, but > examples like 'for var in ...' or 'except ZeroDivisionError as e:' or > '[... for var in ...]' are all unambiguously variable definitions. Sure, I don't really care too much about which feature should a rule be in; what I do care about is to keep first and second fontification level relatively quite and minimal, and keep level 3 reasonably conservative. And people that want a lot of highlight can turn on level 4. > > So I think that: > > a) All variable definitions (functions parameters or not) should use > font-lock-variable-name-face -- to make it easier to find where a > given symbol is introduced. > b) No font-lock-variable-name-face highlights should be put into the > 'variable' feature, which is disabled by default. All of the examples > above should either go into 'definition', or if somebody does like > that approach, into some new 'variable-declaration' feature (enabled > by default). And maybe some into 'assignment', which is on feature > level 3. > c) The 'variable' feature should, at this point, only contain the > relatively useless highlights, since we don't track variable lifetimes > yet. That's why it's disabled by default. > > The current situation across ts modes is that js-ts-mode has variable > declarations in the 'definition' feature (and not by my hand, FWIW); Gah! > ruby-ts-mode has a separate 'parameter-definition' feature that > encompasses both parameters and other variables; > in c-ts-mode highlighting for 'int i = 4' is split between > 'definition' and 'assignment' (the latter seemingly redundant); Should've been in assignment IMO. I probably overlooked it. > typescript-ts-mode and rust-ts-mode also follow the principle, more or > less. Well, the only ts-mode that I actually wrote is python-ts-mode. For other major modes, I can only suggest. Even for python-ts-mode, I don't want to exert my personal opinion onto it too much, except for keeping font-lock level 1 and 2 quiet. >>> My thoughts about parameters. I started to extend rules for them >>> since they are very limited now. >>> But I'm not sure what face to use for them. >>> I would like to not use the same face as for assignments, because >>> I'd want to highlight them differently. >>> It seems that there is no appropriate face in font-lock.el, so I >>> ended up creating my own face in my config. >>> Does it make sense to add new face for parameters in font-lock.el? >>> Or it is too small feature for its own face? >>> I also apply this face for keyword argument in function calls. >> To be honest, I don't have any good ideas. Perhaps we can add a >> parameter face that inherits from variable name face by default, >> Dmitry, WDYT? > > As per above, parameters don't seem too different from any other > variable declarations from my POV. They are similarly useful, so I'd > highlight them the same way. > > Do we want to have a common face which would inherit from > font-lock-variable-name-face and would be used solely for > function/methods parameters and nothing else? I don't object, but I > don't quite see the point either. I agree. Yuan