From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: Recent updates to tree-sitter branch Date: Mon, 03 Oct 2022 13:58:55 +0800 Message-ID: <87lepxxxb4.fsf@localhost> 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> <67BF9BE5-4131-49CF-BB0A-687D51BB4870@gmail.com> Mime-Version: 1.0 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="14993"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel , Theodor Thornhill , Stefan Monnier To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 03 07:59:59 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 1ofEUh-0003lK-4X for ged-emacs-devel@m.gmane-mx.org; Mon, 03 Oct 2022 07:59:59 +0200 Original-Received: from localhost ([::1]:58280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofEUf-0005Xj-R3 for ged-emacs-devel@m.gmane-mx.org; Mon, 03 Oct 2022 01:59:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofESv-0004pr-JW for emacs-devel@gnu.org; Mon, 03 Oct 2022 01:58:09 -0400 Original-Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:55242) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofESt-0002tQ-LY for emacs-devel@gnu.org; Mon, 03 Oct 2022 01:58:09 -0400 Original-Received: by mail-pj1-x1032.google.com with SMTP id 70so9005832pjo.4 for ; Sun, 02 Oct 2022 22:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date; bh=MT5NJoWsCcABqueos5uQFs3hj+SnrxlwRHxWgMvaAjw=; b=k+JqhlYC5y22Btbj2IkoAVf888vbQskA5xZvv5dh1V8QfFaybezRqODkS1WYm4Ztkw foHOHp+ALOiqNizOq6zWYu3HUjzrwOH5f7207rj0kIew5ndiD2Mid1o+4i+zsbxAoxyN ncWZe0H8GsESzh/uX5oXUkchB+WKDA5ZoVvwmRQxUvNVA6DodPqKPBeLRrZOnz6DaF9j ilST7G54pctfn5w4v2ABj3XGLVhE1S2Yql3zU0impX4zhvTiR6QYOBjuA4CM+NmrLmgx fL65mH8VxejqI0FlJGvNGDSECdHZUQCQH4DnC62d1qmCpEkhan6mQcWB9CHws3YMRldr Qr/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=MT5NJoWsCcABqueos5uQFs3hj+SnrxlwRHxWgMvaAjw=; b=UrEiyPDDMNAskSM5OQftLqDFMbRl4Mb71sw9FWETb8jt9WKPfi+UKBjvLqVhAdVP+f 2o8qX1jivPZ9DhEUDYikSEFYMm4K0a2CwIzL8QD8zcX6n1DVjOKWIiogDmW8Ec5Yxczd YX4r6ZljzoxO0ORAU6ZRyc5OPoWI4itV/sFj+m395ktsA6U3FGzpc7JfQ+wut994dVgd Uq9ZMH+b7/X0XBlBEvKbVZPBIBC9WsrQ4nNX1UaKyAnfEv1CKeKfpDcu4MPKLK/i/O6h 9PQ8Xy6LvL2MAkxohIpq2N3fXSSY3VOvKhjO0Q4nD+GCSNLeN2ghKU/jHFdle11UaQD+ H9gw== X-Gm-Message-State: ACrzQf2iFE5jIoi8P6fQlcOifIdYFa52vfgtZayvmTcxqqkHPhngABdv k2Si6EpOIIhB4mHfzJZTdV4= X-Google-Smtp-Source: AMsMyM7AEUukO3ro/nAV/kGxEo7+BeA1PGzy2ZO4CVOWRkAj2WupU+dQ0UIpt3OnSCHaqk3bnl9Evg== X-Received: by 2002:a17:903:48e:b0:17e:ea4a:394e with SMTP id jj14-20020a170903048e00b0017eea4a394emr5278448plb.48.1664776686008; Sun, 02 Oct 2022 22:58:06 -0700 (PDT) Original-Received: from localhost ([1.83.154.214]) by smtp.gmail.com with ESMTPSA id t25-20020aa79479000000b0053e6bda08e0sm6420337pfq.219.2022.10.02.22.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 22:58:05 -0700 (PDT) In-Reply-To: <67BF9BE5-4131-49CF-BB0A-687D51BB4870@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=yantar92@gmail.com; helo=mail-pj1-x1032.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, 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:296730 Archived-At: Yuan Fu writes: >>> Also bear in mind that the override flag can only be applied to the who= le 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 f= or 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 fo= r the query. So if I want to use different override flag for different matc= hes, 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 us= ers 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. What about allowing (@python--treesit-fontify-string 'append) to specify the override? > A real use-case for override is how I fontified Python strings above. I h= ave 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. The current convention in font-lock-keywords is exactly opposite - earlier matches are more specific, and they are later not replaced by later more general matches. Also, for reference, I am currently developing parser-based fontification for Org. I am using a somewhat different approach (closer to font-lock-keywords): ((drawer property-drawer) ;; <- match node types (:begin-marker 'org-drawer t) ;; <- apply fontification to :begin-marker = field inside=20 (:end-marker 'org-drawer t)) ;; <- ... :end-marker ..= .. ((headline inlinetask) (:title-line (if (org-element-match-property :archivedp) ;; <- Elisp matching of the = node properties 'org-archived (pcase (org-element-match-property :todo-type) ;; <- .... (`todo (when org-fontify-todo-headline 'org-headline-todo)) (`done (when org-fontify-done-headline 'org-headline-done)) (_ nil))) t)) ;; <- override ((bold italic underline verbatim code strike-through) (:full-no-blank '(face nil org-emphasis t))) ;; <- fontify contents of t= he matched node =20=20=20 Also, see https://github.com/yantar92/org/blob/feature/org-font-lock-elemen= t/lisp/org-font-lock.el#L574 >From my experience re-implementing the vanilla fontification, fontification order is important and may create subtle issues when not designed carefully. --=20 Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at