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: Fri, 30 Sep 2022 14:03:25 -0700 Message-ID: <09FF0751-A76E-449F-9F6C-7F3FDEC11DA1@gmail.com> References: <87wn9srn9n.fsf@localhost> <87leq65v3t.fsf@localhost> <87k05m96cy.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="580"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel , Theodor Thornhill To: Ihor Radchenko Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 30 23:04:21 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 1oeNBF-000AVh-Pe for ged-emacs-devel@m.gmane-mx.org; Fri, 30 Sep 2022 23:04:21 +0200 Original-Received: from localhost ([::1]:35184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oeNBE-0007ek-7O for ged-emacs-devel@m.gmane-mx.org; Fri, 30 Sep 2022 17:04:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oeNAR-0006mw-6F for emacs-devel@gnu.org; Fri, 30 Sep 2022 17:03:31 -0400 Original-Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:38761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oeNAP-00026d-Hf for emacs-devel@gnu.org; Fri, 30 Sep 2022 17:03:30 -0400 Original-Received: by mail-pg1-x536.google.com with SMTP id 129so5133531pgc.5 for ; Fri, 30 Sep 2022 14:03:28 -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=DNagp2VB7tn24xEDqq20JnFOSlKmjfd3MtR9x1y+uxE=; b=HsCHWjb0PB1mQsJz+4dPDyKFGbmiYSR3M3lylMQWIiIqMEudVnCRR2FHc9LrTt3oY2 iGetypoVvi8BVdLrL4Ib8DS5M4ghx1C2ngnfgJLXhEJoRP9PQnFOw2zxvGnXfoh024Vi HSZmQLdxh9qivTV6pekox8Pga0/aF8o+tA+9gqhezUlQUD7qAKNzIrQSc/bxu29QE9Lh 94ytuIZLcfNgC/NOyCD9SUbnu/RJBhHyLsBQrcgM1yx2dK1o/pP/pmWZhdWpi2uyp3bS IjScUljRIGFVDYopF5dUpmVUzxrl60oXagUu7Mud/eP9s+lqismyoWcq3TYUFLI9U1Jh 4UTQ== 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=DNagp2VB7tn24xEDqq20JnFOSlKmjfd3MtR9x1y+uxE=; b=43X1LDY2EXYjVtqLaT3tOYdiMoXhHDZw4aGE8pSqHSf0JZVwMc0v2mPxDlfxScFa62 A+8FCYJMsbci3uCZLcMgaApjv2TM95VCkqp6IQf3UtuDz354gxr8rzZ5DQPq8XiflHYM frCdNRaMQ1WaC/u9L9NQoiiixPt1QHS5DeVJ0wRmeMekBWSNBAG0wE57q2h35M6cMjp9 zU/e8jfu8YgjWMK3BShAC2ECxL8wWqofy5A6OGyTvsN9N6itj/GeQn7a6cjw0Z6vgrxb gDXyvWCorBTuLKQclngszfurQmnc+qbvyFTn9PJfzF30vq8NPgx4cpnt102KMFEN155c DUdg== X-Gm-Message-State: ACrzQf2NGEOaIZpKIhaWHWGBGaKfaIcyfBcoaPQPigzHxc6WLv2Snpw8 byjcsCkAdAQx13a/5GMA4E6BuDfbAvk= X-Google-Smtp-Source: AMsMyM49pljQctOLWrr8dJ8T0eT1SWd5B0zpJFWUkddmdi5wmCBc1pQFutJE5BV1q4KAnAlsgbi4iA== X-Received: by 2002:a05:6a02:43:b0:43c:dbdc:192d with SMTP id az3-20020a056a02004300b0043cdbdc192dmr9048112pgb.449.1664571807549; Fri, 30 Sep 2022 14:03:27 -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 p5-20020a170902e74500b00176ab6a0d5fsm2426744plf.54.2022.09.30.14.03.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Sep 2022 14:03:27 -0700 (PDT) In-Reply-To: <87k05m96cy.fsf@localhost> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=casouri@gmail.com; helo=mail-pg1-x536.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:296534 Archived-At: > On Sep 28, 2022, at 9:01 PM, Ihor Radchenko = wrote: >=20 > Yuan Fu writes: >=20 >>> What I am asking is an extra dynamic condition in addition to the = query. >>> For example: >>> 1. Only apply FACENAME for nodes matching QUERY, but only when Elisp >>> variable is non-nil >>>=20 >>> 2. Only apply FACENAME for nodes matching QUERY, which are in the = second >>> half of the buffer >>>=20 >>> 3. Only apply FACENAME for notes matching QUERY, which also have a = field >>> matching a dynamically assigned regexp. >>>=20 >>> Essentially any condition that is not covered by the QUERY, but can = be >>> checked in Elisp given that node object is passed to the test = function. >>=20 >> These can be achieved by using a function, no? You do need to declare = global functions for them, but it shouldn=E2=80=99t be a problem. = Besides, as I said, the query syntax is not something we can change. The = freedom we have is how do we use the capture names. We can=E2=80=99t = extend the query with arbitrary lisp. >=20 > Will the currently matched node be passed to the function? Or should = the > function run yet another query to determine the node it was called on? The matched node is passed to the function. >=20 >>>>> Further, can OVERRIDE FLAG of the MATCH-HIGHLIGHT as in >>>>> font-lock-keywords be supported? >>>>>=20 >>>>> "If OVERRIDE is t, existing fontification can be overwritten. If >>>>> keep, only parts not already fontified are highlighted. If = prepend or >>>>> append, existing fontification is merged with the new, in which = the new >>>>> or existing fontification, respectively, takes precedence.=E2=80=9D= >>>>=20 >>>> I can do that, but would it be really useful? Unlike regex = font-lock which is used for so many different things, tree-sitter = font-lock is, IMO, only used to apply a base layer of language-specific = highlight. How would one use the override feature in this scenario? >>>=20 >>> For example, consider a function definition with docstring field. >>> Imagine that you want the function definition to have gray = background, >>> but the docstring to have yellow background. OVERRIDE t is how this = is >>> usually implemented in font-lock-keywords. >>=20 >> The pattern that comes after will override patterns that come before. = By the nature of parse trees, for any node A and another smaller node B, = B is either completely contained in A or completely outside A. So I = think the override relationship is enough. >=20 > OVERRIDE can also be 'prepend or 'append to combine faces from = multiple > nodes. You can=E2=80=99t really pretend or append if the only face format we = allow is symbol. > Also, OVERRIDE nil will not apply fontification on the already = fontified > parts of the region. Note that the parent node might only fontify > fraction of the text inside the child node. The parts not yet = fontified > can make use of OVERRIDE nil. Ok, I guess it=E2=80=99s good to have options. But I think it is more = intuitive and convenient to override by default. Yuan=