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 on feature/tree-sitter (severe performance issues together with linum-mode) Date: Tue, 6 Sep 2022 17:41:11 -0700 Message-ID: References: <7e24d0aa-9980-6204-5064-5a92963ae7bd@secure.kjonigsen.net> <83026cfc-8a85-9939-bab4-5b60d4812af9@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) 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="8993"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: =?utf-8?Q?Cl=C3=A9ment_Pit-Claudel?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Sep 07 02:42:03 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 1oVj8l-0002DU-8X for ged-emacs-devel@m.gmane-mx.org; Wed, 07 Sep 2022 02:42:03 +0200 Original-Received: from localhost ([::1]:46380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVj8k-00036Y-3l for ged-emacs-devel@m.gmane-mx.org; Tue, 06 Sep 2022 20:42:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVj80-0002Rt-VZ for emacs-devel@gnu.org; Tue, 06 Sep 2022 20:41:16 -0400 Original-Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:34424) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVj7z-0000UZ-0s for emacs-devel@gnu.org; Tue, 06 Sep 2022 20:41:16 -0400 Original-Received: by mail-pg1-x534.google.com with SMTP id 73so12123698pga.1 for ; Tue, 06 Sep 2022 17:41:14 -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=rWEf/9qUmqrWMJxNBZbz//CngCujb1QZqipXfnpU+dY=; b=T9ldM3NrosfBPpbXGnU01FxR6SkmhqcYpXqwYUtlvXLolvKubVAbiA2qbrbHZEd1OH lkjQlQSjbK1FFqmpM+rKHEsor7ieBZ+NcWi+1hJcTHUHiXpCZesoIB09ZglwwLPnJ3+E RrVdp+eA6qMcvAEwdUeDnGn52iktbQ7+r7/VVmKq97z6Seja6RB0LxeQDejP4Nmi4lAa YWVxQZMfamNog7depYvAi/veS7ivQUUWjkDQBWL06tfhB0v/X4rzyIuN9yPN3TDHTLCp c8eiraR/VFFzUO+8EuEJeHAkhZyUaiXRw7ohYpTvgP7WbkGVQIUgPnLMcknLhldWpvEz j5+A== 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=rWEf/9qUmqrWMJxNBZbz//CngCujb1QZqipXfnpU+dY=; b=vgSonh2gKf0g5ZTAJDGHY5dcGnnk/AsmdsdmUBWErvE70gE8caLg3GXSlBuParkEIo Y4o8vtt9dM2Bsq7oVmCN6TbY/RerfHI8uoJTTzbpAv2zIilFLzxjxAsPyfKu3sgMt+g1 8RwdvKPGia6LXraBSv6or7yFl5egc5+PxU7+cgELQ7SFVmrlBKnTQ4YMT2GHiRkjzAre 9JT1SnOl02dNVQKpG38iyDr05ea7AHaQIfgfP6Cas1/ysFcnGmy1YcmezJWAXFzpf4M6 is+ULARpeKHr7xqtzKD1Lb4ud8yHuNdsCk410xGxouvAI3MluBDW2WohBRJ3GSGDaieq FIdg== X-Gm-Message-State: ACgBeo2wld4MhxtnzDM1hfwQPe5WfMH5IYrW8s+HSYBA++Fylo+skBKF CngN1OX+NTZOt4rVjvRZedVoil6GUZM= X-Google-Smtp-Source: AA6agR5Gjyeg2cVUQBFYBUlYn4inL1PyLBM1TMdPagSZ7F5Qhulo01jRcJZ1L9xww6TUhRBngaou0A== X-Received: by 2002:aa7:93a4:0:b0:535:d714:c24c with SMTP id x4-20020aa793a4000000b00535d714c24cmr1096364pff.15.1662511272778; Tue, 06 Sep 2022 17:41:12 -0700 (PDT) Original-Received: from smtpclient.apple ([198.134.98.50]) by smtp.gmail.com with ESMTPSA id ot17-20020a17090b3b5100b001fb3522d53asm13258361pjb.34.2022.09.06.17.41.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Sep 2022 17:41:12 -0700 (PDT) In-Reply-To: <83026cfc-8a85-9939-bab4-5b60d4812af9@gmail.com> X-Mailer: Apple Mail (2.3696.100.31) Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=casouri@gmail.com; helo=mail-pg1-x534.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, T_SCC_BODY_TEXT_LINE=-0.01 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:294804 Archived-At: > On Sep 5, 2022, at 7:53 PM, Cl=C3=A9ment Pit-Claudel = wrote: >=20 > On 8/20/22 07:14, Stefan Monnier wrote: >> FWIW, I think specifying the highlighting rules with something akin = to: >> (defvar ') >> is a mistake. It should go through some kind of macro, such as = (maybe): >> (defvar (tree-sitter-rules )) >> which can thus do any preprocessing we may want, such as = pre-compiling >> queries. It also helps evolve the syntax since we can more easily = warn >> about obsolete uses, etc... >> I've had a "rewrite font-lock.el so the rules go through a macro" in = my >> todo list for ages. >=20 > We do things this way in Flycheck, but we've been bitten a few times = by the way this pattern interacts with `with-eval-after-load`, so I = would be careful about adopting this pattern in tree-sitter (unless we = expect it to be preloaded). >=20 > In fact, I think your suggestion back then was to *not* use a macro? = I can't find the exact thread, but this is close enough: = https://lists.gnu.org/archive/html/emacs-devel/2018-02/msg00820.html :) >=20 I see Stefan=E2=80=99s follow-up in the new thread, but in terms of = tree-sitter, I actually defined it as a function rather than a macro = (because the habit of always preferring functions if a function will = do). IIUC function doesn=E2=80=99t have the same problem as macros (when = byte-compiling)? It is used like this: (treesit-font-lock-rules :language 'c '((false) @font-lock-constant-face)) Definition: (defun treesit-font-lock-rules (&rest args) "Return a value suitable for `treesit-font-lock-settings'. Take a series of QUERIES in either string, s-expression or compiled form. Same as in `treesit-font-lock-settings', for each query, captured nodes are highlighted with the capture name as its face. Before each QUERY there could be :KEYWORD VALUE pairs that configure the query. For example, (treesit-font-lock-rules :language javascript '((true) @font-lock-constant-face (false) @font-lock-constant-face :language html \"(script_element) @font-lock-builtin-face\") For each QUERY, a :language keyword is required. Currently the only recognized keyword is :language. \(fn :KEYWORD VALUE QUERY...)" (let (;; Tracks the current language that following queries will ;; apply to. (current-language nil) ;; The list this function returns. (result nil)) (while args (let ((token (pop args))) (pcase token (:language (let ((lang (pop args))) (when (or (not (symbolp lang)) (null lang)) (signal 'wrong-type-argument `(symbolp ,lang))) (setq current-language lang))) ((pred treesit-query-p) (when (null current-language) (signal 'treesit-error `("Language unspecified, use :language keyword to = specify a language for this query" ,token))) (if (treesit-compiled-query-p token) (push `(,current-language token) result) (push `(,current-language ,(treesit-query-compile current-language token)) result)) ;; Clears any configurations set for this query. (setq current-language nil)) (_ (signal 'treesit-error `("Unexpected value" token)))))) (nreverse result))) Yuan=