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: Sat, 16 Dec 2023 17:10:24 -0800 Message-ID: <8915940C-F69C-4CAE-80E8-4F70C5753061@gmail.com> 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> <7371702772641@mail.yandex.ru> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33417"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Dmitry Gutov , Eli Zaretskii , "67061@debbugs.gnu.org" <67061@debbugs.gnu.org> To: Denis Zubarev Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 17 02:11:29 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 1rEfgm-0008YQ-Ds for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 17 Dec 2023 02:11:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEfgP-0006BT-De; Sat, 16 Dec 2023 20:11: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 1rEfgN-0006BG-D1 for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 20:11:03 -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 1rEfgL-0005XR-0L for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 20:11:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rEfgL-0003yG-IO for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 20:11:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 17 Dec 2023 01:11:01 +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.170277544615227 (code B ref 67061); Sun, 17 Dec 2023 01:11:01 +0000 Original-Received: (at 67061) by debbugs.gnu.org; 17 Dec 2023 01:10:46 +0000 Original-Received: from localhost ([127.0.0.1]:56390 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rEfg5-0003xX-QM for submit@debbugs.gnu.org; Sat, 16 Dec 2023 20:10:46 -0500 Original-Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:49487) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rEfg2-0003xD-Vg for 67061@debbugs.gnu.org; Sat, 16 Dec 2023 20:10:44 -0500 Original-Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso1563663a12.3 for <67061@debbugs.gnu.org>; Sat, 16 Dec 2023 17:10:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702775436; x=1703380236; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UXRV6BxtcefNFYqhr0fQRjKcGKhjzRwvDF94fToM0hs=; b=arAGsB3kmha7U80TzVryFxVtAYO21bOX0s2j7kDhukFErUdNIsITjcb1dHvKfjrEaC KvKvH2x17L0gImLLlQAaDQZQQrQyuievDzjqZbMy1Su8H+p/pFhuPtbk6cucEiTurvCh M+X/QIKS3urgFFtYQreNmXJr8DHibCIIYs0I9z8E6u5FtMc80Lg5l4i6OSQK9GhRr2ef LB6LPnX2FNEb0RASFgnVptB/lVFXO7XR89ZYUnFLY9Bb1R0JjESv71q7Dx7LA60hbz2s eWNffhb6LQSqzEBBJAhK9PnVNvqUTZQB8urpcnkhck027ylDj4cYk49zQQ3lWyIRMAZU QADA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702775436; x=1703380236; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UXRV6BxtcefNFYqhr0fQRjKcGKhjzRwvDF94fToM0hs=; b=lQrJReAXQxVwMlSyp2nGpIJICPsOc9HkiCpSAXxlYcCjcPWqFA/xXO4Sf/uJ85ga2E 0U3fCT4XUeePujBiPrmgwt6GYM5c6A/7yMQ7lHxizydZDU+tnTRQBW4N10vkSPmzni9a utcSY5VuUYytVI/vASi3mOCZ8rjEkD3MaWf2KhLVDVVFegsKN15UGDAOR38Wdo3sccIZ pMfuPzVJCVEb/qalB99l3flILl8iCP1lIJ50bU5L4M1msfy5zxcuKxugeA/OS0J19yx+ YR9ti4UA5Ab/XdrWUCnP2J/a+WKrcQ57i0EpaS5FwDrdx247UMYAUsC80PtJvtTOcuPr sKAg== X-Gm-Message-State: AOJu0Yz10hfsuXAVQ9U7ckmVHoofqfnzSIlbcDZ2kv8DzzCO6N0LIjfs A+3j9tyZYjBniheJdtkPlV8= X-Google-Smtp-Source: AGHT+IGyDkANwS4EttmBTKcg5pHyST4+73VSTOcEienKrM2g99pN/jLBDMtvp2imHgM4gwf5wNEfEQ== X-Received: by 2002:a17:903:110d:b0:1d3:2a96:5c81 with SMTP id n13-20020a170903110d00b001d32a965c81mr11960935plh.51.1702775436086; Sat, 16 Dec 2023 17:10:36 -0800 (PST) Original-Received: from smtpclient.apple (172-117-161-177.res.spectrum.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id j3-20020a170902c08300b001d0b3c4f5fbsm16487317pld.63.2023.12.16.17.10.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Dec 2023 17:10:35 -0800 (PST) In-Reply-To: <7371702772641@mail.yandex.ru> X-Mailer: Apple Mail (2.3731.700.6) 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:276399 Archived-At: > On Dec 16, 2023, at 4:26 PM, Denis Zubarev = wrote: >=20 > Sorry for the delayed response. > > For many Emacs users, they want a quieter or even minimal = fontification. > I'm not against it. I just think that highlighting of an = interpolation > as a string is wrong. Is it possible to set quiet fontification in > emacs-lisp mode, in such a way that `keywords' in doc-strings were > fontified as a doc-string itself? I think it is similar to > interpolation, it serves the purpose of separating different semantic > elements from each other. IMHO, users who like quiet levels will = benefit > from interpolation highlighted differently. I definitely can see your point, and it makes a lot of sense. I don=E2=80=99= t really know people who want quieter fontification wants (probably both = approach has their supporters) so can=E2=80=99t speak for them. But in = general, I think it wouldn=E2=80=99t hurt to have the option. > > Instead of the third level, the check should use the value > > treesit-font-lock-level. And it should check for each level smaller = than > > or equal to treesit-font-lock-level. > Done. Thank you for your hard work! I=E2=80=99m just here talking and you went = ahead and did all the work :-) > > 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 added a new feature variable-definition for variables defined for = local scopes and put it on the 3rd level. > I also added rules to variable-definition feature for variables in = list > comprehension ( [var+1 for var in []] ) and as_pattern (with T as = var:, > except E as var:, case str() as var:). > I've noticed that vars in `for var1, (var2, var3) in []:` are = highlighted by the rule from the assignment feature (specifically = `pattern_list`, `tuple_pattern`). > It seems easy to fix `pattern_list`, but not so easy for > `tuple_pattern`, since this node may occur recursively. > I didn't touch these rules for now. Ok, makes sense. > Summary for all changes in the patch. > New feature variable-definition: > `for var in range(3)` > `[var+1 for var in []]` > `with T as var:` > `except E as var:` > `case str() as var:` > highlight var as font-lock-variable-name-face > assignment feature: > var :=3D 3 (named_expression) > var *=3D 3 (augmented_assignment) > Highlight var as font-lock-variable-name-face. > Make list_splat_pattern query more precise. > list_splat_pattern may appear not only in assignments: var, *rest =3D = call(), > but in the parameter list too: def f(*args). > Highlight args only for the first case in assignment feature. > type feature: > Fontify built-ins (dict,list,etc.) as types when they are used in type = hints. > support nested union types, for example `Lvl1 | Lvl2[Lvl3[Lvl3], = Lvl2]`. > This structure is represented via nesting binary_operator and = subscript nodes in the grammar. > Function python--treesit-fontify-union-types iterates over all = children and highlight identifier nodes. > Fontify base class names in the class definition: class Temp(Base1, = pack0.Base2): > Fontify class patterns in case statement: case [TempC() | bytes(b)]: > Highlight the second argument as a type in isinstance/issubclass call: > isinstance(var2, (str, dict, Type1)); issubclass(var1, int|str) > For all dotted names of a type highlight only the last part of the = name, > e.g. collections.abc.Iterator. > decorator feature: > Highlight dotted names: @pytest.mark.skip > Function python--treesit-fontify-dotted-decorator iterates over all = nested attribute nodes and highlight identifier nodes. > When font-lock-level is set 4, `skip` had function-call face in: = @pytest.mark.skip(reason=3D't') > Add `:override t` to decorator feature to override function-call face. > string feature: > Enable interpolation highlighting only if string-interpolation is > presented on the enabled levels of treesit-font-lock-feature-list. > Fix fontification of strings inside of f-strings interpolation, > e.g. for f"beg {'nested'}" - 'nested' was not fontified as string. > function feature: > Do not override the face of builtin functions (all, bytes etc.) with > the function call face > keyword feature: > Add "is not" to the `python--treesit-keywords` list. Thanks. I think the only thing that=E2=80=99s still up to discussion is = the variable-definition rules. Others can be merged to emacs-29. Yuan=