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.devel Subject: Re: Tree-sitter integration in python.el Date: Tue, 11 Oct 2022 22:04:38 -0700 Message-ID: References: <3A68545C-2E40-4BB4-8563-8041A5452634@gmail.com> <87y1twlr0v.fsf@gmail.com> <83czb8ycpo.fsf@gnu.org> <87tu4klfcw.fsf@gmail.com> <87ill0le20.fsf@gmail.com> <87y1ttfmj8.fsf@gmail.com> <19950F30-F4DB-4CE4-9257-24DA39594669@gmail.com> <87czb47jya.fsf@gmail.com> <87wn9c7xxd.fsf@gmail.com> <83wn9altdu.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) 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="17024"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , arstoffel@gmail.com, orontee@gmail.com, emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Oct 12 07:07:25 2022 Return-path: Envelope-to: ged-emacs-devel@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 1oiTxl-0004B0-5A for ged-emacs-devel@m.gmane-mx.org; Wed, 12 Oct 2022 07:07:25 +0200 Original-Received: from localhost ([::1]:48412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiTxj-0007Kw-Af for ged-emacs-devel@m.gmane-mx.org; Wed, 12 Oct 2022 01:07:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiTv9-0005OS-JY for emacs-devel@gnu.org; Wed, 12 Oct 2022 01:04:43 -0400 Original-Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:39648) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oiTv7-0007O8-Ug; Wed, 12 Oct 2022 01:04:43 -0400 Original-Received: by mail-pg1-x535.google.com with SMTP id b5so14617224pgb.6; Tue, 11 Oct 2022 22:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=XH/veT3/YXrHvcFCOHf6qqzOQh6Dp/RL04LBHlvXA7U=; b=iOGDD72o69nMVITa21yn4XTpjB9V0+sDocPpQAqi/TQjpJxtOiccpto2EgaMAzcBN0 /yR+HjI0gYuOKdCGixX1n2KKMhYvD6PglZcN1CXHOGiEV8HFrAm6MvA/NBSIcysmYwxY tXXZOZBfBAgVbFjzXoPVXoyC9kdpUdYSWUC97ASbv/vXmov9K+eaudkJqjCfbdbyKQtZ v8DkZqzx2UqbJeGYXUnUklLbFbUkT4g1P9Cg/6JRyoZZ0zJ5K5yUBPycCUpDF1sCJgVE 4CQ8G7zz9qLslbpH0bHOiAllRBLhTnnDrYaCMOX7fzOQIakkk6jt5nLdOPkkQWMscFwk HkXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=XH/veT3/YXrHvcFCOHf6qqzOQh6Dp/RL04LBHlvXA7U=; b=xQWB+m05F8dKPCDhxJAyKUsD0nhQYk7f/25fWg3zmLUEA/i8MlrJm4S2XdKbgAAxV2 8MjS7RDkmQJqB9KDJtA4CiqzJ9ZI2jOyMSt9ionpKW1FNamIuEuY7H9XnbSMzQrDK7Jj H2Ypczplw/QMvnw8Kix2ishMnue4cRDUlz6s4Q/DohwV9HPahoBtQYSVimakHDmRQXSs nnz8Dz2HNLcgJ+lJrSWoffUNb6uYERyKliOBHe3RsUWAy5Qck7e20zQamGl6L+RHJ9Qu g7CmWoCnUelxoJD3/kr3eu5RAuRe4Zo7s/F8jGPRNT8eJlYxjsa6WEgjaubtvQn50cRv RdIQ== X-Gm-Message-State: ACrzQf1gZRW33wKfp3iVBUIX4LVGTuTA2JPKzmDEfXPG/1NwQm5+L24e 55+dOThsnHxVhvSNWLC8FHo= X-Google-Smtp-Source: AMsMyM54XScSOGlC2gYt0hGN67+C074C+LFoe8iCpIohAoDRyLEU3KukLIaFUEiefC87YYp7to1Riw== X-Received: by 2002:a65:6d89:0:b0:421:94bc:cb89 with SMTP id bc9-20020a656d89000000b0042194bccb89mr23699754pgb.129.1665551080005; Tue, 11 Oct 2022 22:04:40 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id t7-20020a625f07000000b00562b05c9674sm9931495pfb.130.2022.10.11.22.04.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Oct 2022 22:04:39 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=casouri@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:297566 Archived-At: > On Oct 11, 2022, at 3:15 PM, Stefan Monnier = wrote: >=20 >>>> The complaint for font-lock-maximum-decoration is that it=E2=80=99s = obscure and >>>> too corse-grained. So my idea is for each major mode to provide >>>> fined-grained controls like >>>> python-fontify-type/f-string/assignment/built-in/etc. And = tree-sitter >>>> makes it easy to implement this kind of toggle. But I guess a = global >>>> control is also nice, I can make tree-sitter respect >>>> font-lock-maximum-decoration, in addition to the fined grained >>>> local-control. >>>=20 >>> I think having tree-sitter respect font-lock-maximum-decoration = would >>> be good, because it allows a major-mode agnostic way of controlling >>> fontifications. With tree-sitter in mind, we'd need to agree on = what >>> kind of syntactic entities are included in each level (which is also = a >>> Good Thing, because currently what is level N of font-lock is = entirely >>> up to the major-mode, AFAIU). >>=20 >> I think it is difficult to define syntactic entities for each level = such >> that it is generally enough to include all kinds of major mode out = there, >> and specific enough to be useful. It is easy for common programming >> languages, but hard for others like html, css, prolog, etc. >=20 > How 'bout: >=20 > - Major modes provide a list of available fontification "features" > in a buffer-local variable like `treesit-font-lock-features` > e.g. `(type f-string assignment built-in ...)`. > - the list of features is *ordered* so that > the user can control the fontification via a Customizable > `treesit-font-lock-level` that can be set between 0 and 100 to > select the corresponding proportion of features. > - Users can additionally enable/disable those features individually = via > some `treesit-font-lock-control` variable. One problem I can see is that the same level could give very different = busyness across modes. That would defeat the purpose of having a single = setting. Say mode 1 has (A B C D E F G H I), where ABC are very basic, = DEF moderate, and GHI fancy, mode 2 has (A B C D E F G), A basic, BCDEF = moderate, G fancy. Then 80 would give a fancy font-lock in mode 1 and a = moderate font-lock in mode 2. You get the idea. Currently tree-sitter supports both :level and :toggle. When defining = queries you can say :toggle python-fontify-types, and = python-fontify-types can control this query. :level would be the global = rough settings, :toggle would be the local, fine-grained setting. = Instead of variables, :toggle could be changed to use symbols as you = suggested, so it doesn=E2=80=99t create a gazillion variables. But WDYT = of the general design? Yuan=