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: Recent updates to tree-sitter branch Date: Sun, 2 Oct 2022 15:54:54 -0700 Message-ID: <67BF9BE5-4131-49CF-BB0A-687D51BB4870@gmail.com> References: <87wn9srn9n.fsf@localhost> <87leq65v3t.fsf@localhost> <87k05m96cy.fsf@localhost> <09FF0751-A76E-449F-9F6C-7F3FDEC11DA1@gmail.com> <871qrs2mzl.fsf@localhost> <59AE5D4B-39D2-4C18-BAC6-9C71B736F0D0@gmail.com> <87zgeeznl3.fsf@localhost> 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="20420"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel , Theodor Thornhill , Stefan Monnier To: Ihor Radchenko Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 03 00:55:41 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 1of7s4-00055o-TF for ged-emacs-devel@m.gmane-mx.org; Mon, 03 Oct 2022 00:55:41 +0200 Original-Received: from localhost ([::1]:48260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1of7s3-0000Ci-33 for ged-emacs-devel@m.gmane-mx.org; Sun, 02 Oct 2022 18:55:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1of7rQ-0007ru-Bb for emacs-devel@gnu.org; Sun, 02 Oct 2022 18:55:00 -0400 Original-Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:42685) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1of7rO-0007xa-Fm for emacs-devel@gnu.org; Sun, 02 Oct 2022 18:55:00 -0400 Original-Received: by mail-pl1-x631.google.com with SMTP id v1so8247447plo.9 for ; Sun, 02 Oct 2022 15:54:57 -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; bh=C94AO4RYemcYHlrU+NxiNdi9fAV0/y11jU+wSYoYGsA=; b=GXEQCEfibdu7AgxmN4wMN1oAxeOI89WGW4X1cNWzybqODdvXCUlhwklhe8gDyUcuxY 9WW3CZCKG+AAabkzwnG40HZHVlXZ1nfrEGxHF34/FjpH8ir9YqGXb5mQbmK66VfWqjNW odTeyB5kFNggQdGW8zWVXy3lyzPeuK/4bfN+D/fk3ZVr1ymQkcSEugbKyJ1SC9sosBy7 I5WG0Tb4zlFOlGRzRXrcvhm0H6Qnp483FhE4UDafExBmz0GvvHe8rrDk8J9mP/ljl5uk ef+fZ/ZgycTc4vf7A5C7rvFd1bHJw3yge2aav1fVqdBqOHtXvw0AqGzBNd9BZ3u7Nbj4 Rgiw== 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; bh=C94AO4RYemcYHlrU+NxiNdi9fAV0/y11jU+wSYoYGsA=; b=ygJairQ6yPd4U1vmTwreXcFC5lmRH7YAQyaL6RsabCnpMPuFl9IZMFavciHf2kWwzy 3RXjMOSi1Olt6yzdjQp46HKQ/j4etnd8ZnOl9U+twknYTNo4vvt/Bwn2N1HVLpHKNSIK LwMHpV53vuhKVvDsDhfYsi3FCxLfiWuK5atk3Prwxk6iVb1LSqltBwQw+AMlG6wqxDrB tuZ7F7F3iN3N55tDHJOrBrmgsPm1pRf8KUNcowiprIZfBHVfrO/b3oYsqW16MgfUgemQ dLuO+IQ2fPF3oGXlhX90GbWzxzRPGcH4+aTok8SMVCNjLlG8KWSWrTcfm2jyyYSmmY+q hkjA== X-Gm-Message-State: ACrzQf3G4zaZRxIm1uVgpc6aoSntCQ2DIj/8C7oPJCZ4dfHAMPR2auaq BQNNXB9MtaePUOxvEsc+Xrk= X-Google-Smtp-Source: AMsMyM4MdWmuFs7xlZnOfufTDmyR+3P7tZk+GJw6WpEDjR7bOywZMPOD2FPL7lP2IJbgw+EYlsQzUg== X-Received: by 2002:a17:902:f814:b0:17d:f41e:8e21 with SMTP id ix20-20020a170902f81400b0017df41e8e21mr7605155plb.117.1664751296446; Sun, 02 Oct 2022 15:54:56 -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 f184-20020a6251c1000000b00537b6bfab7fsm6114439pfb.177.2022.10.02.15.54.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Oct 2022 15:54:55 -0700 (PDT) In-Reply-To: <87zgeeznl3.fsf@localhost> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=casouri@gmail.com; helo=mail-pl1-x631.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:296714 Archived-At: > On Oct 2, 2022, at 12:33 AM, Ihor Radchenko = wrote: >=20 > Yuan Fu writes: >=20 >>> I disagree. The current default in font-lock-keywords is not to >>> override. If programmatic font-lock behaves differently, it will be >>> confusing. >>=20 >> I think the tree-sitter queries are different enough from font-lock = keywords that it will not bring confusion. Further more, default to = override should make things easier, especially to delicate things like = string interpolation, or other nested constructs, where tree-sitter = shines. By default, if the to-be-fontified region has any existing face, = the whole fontification is given up instead of filling in new = fontification. That would be IMO confusing because user would think the = match failed. >=20 > I do agree that it may be confusing. Yet, it is how the default > fontification works. I do not think that tree-sitter matching is > conceptually different compared to regexp matching. (And this = particular > area is not even limited to tree-sitter, AFAIU). It=E2=80=99s not conceptually different from regex matching, but the = tooling is different enough that may bear to be different in some aspect = without creating confusion. But I understand that this is purely = subjective.=20 I cc=E2=80=99ed Stefan. Maybe he has more educated opinions about this. = (Aka could you make a decision please because I couldn=E2=80=99t.) >=20 > I do not insist on my idea being actually used, but wanted to leave a > data point to be considered. Thanks. I don=E2=80=99t think my opinion is definitely better, either. = Both sides seems reasonable to me. I hope that through discussion we can = explore the topic throughly. >=20 >> Also bear in mind that the override flag can only be applied to the = whole query, rather than individual captured nodes. >=20 > How does it change anything? I may be misunderstanding something---can > you provide some illustrative example clarifying whole query vs. > individual notes? What I meant is that, for font-lock-keywords, one can set override flag = for each individual match: (string-regex font-lock-string-face t) (function-name-regexp font-lock-function-name-face nil) (class-name-regexp font-lock-type-face t) ... But for tree-sitter, a query contains many matches and the flag is set = for the query. So if I want to use different override flag for different = matches, I need to split them into two queries: (treesit-font-lock-rules :language 'python :override 'append '((string) @python--treesit-fontify-string ((string) @font-lock-doc-face (:match "^\"\"\"" @font-lock-doc-face)) (interpolation (identifier) @font-lock-variable-name-face)) :language 'python :override nil '((function_definition name: (identifier) @font-lock-function-name-face) (class_definition name: (identifier) @font-lock-type-face) ;; Comment and string. (comment) @font-lock-comment-face)) That means if we use override=3Dnil as default, it is very likely that = users need to explicitly set override to t for the whole query, or split = the query into separate parts. Nothing serious, but it seems less = convenient. A real use-case for override is how I fontified Python strings above. I = have three matches for (1) all strings (2) docstrings (3) variable names = in string interpolations. IMO it=E2=80=99s intuitive and convenient for = later more specific matches to override earlier more general matches. Yuan