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: treesit indentation "blinking" Date: Fri, 7 Apr 2023 19:42:56 -0700 Message-ID: <836E537D-0146-4F1D-BF04-863C3029C50E@gmail.com> References: <83bkka5z7w.fsf@gnu.org> <871ql6a4d4.fsf@gmail.com> <83jzyy4776.fsf@gnu.org> <9F152CAA-6326-459F-84FF-87988B3A92B6@gmail.com> <6bf0322b-1151-129a-e26f-61cf4f232d17@yandex.ru> <6efb9f84-211d-560e-3196-95d7f0b8be19@yandex.ru> <1874921e1d0.2829.cc5b3318d7e9908e2c46732289705cb0@dancol.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.500.231\)) 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="2442"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?utf-8?Q?Daniel_Mart=C3=ADn?= , Daniel Colascione , Dmitry Gutov , Alan Mackenzie , =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= , Eli Zaretskii , theodor thornhill , geza.herman@gmail.com, emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Apr 08 04:44:16 2023 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 1pkyYq-0000Me-L5 for ged-emacs-devel@m.gmane-mx.org; Sat, 08 Apr 2023 04:44:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkyXq-0006tM-C0; Fri, 07 Apr 2023 22:43:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pkyXp-0006tC-H6 for emacs-devel@gnu.org; Fri, 07 Apr 2023 22:43:13 -0400 Original-Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkyXn-0005R1-Ny; Fri, 07 Apr 2023 22:43:13 -0400 Original-Received: by mail-pl1-x62f.google.com with SMTP id h24so511218plr.1; Fri, 07 Apr 2023 19:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680921789; 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=tVI6SHexqk/fHDW9ZV/hvRMhbzKIOya+xJv7Fb+vwi4=; b=KRmZg5pgB5REhjI7Srh9rXEpaor46INHRnO5bV2L7BUgX/MAFTB3YUrmFBNqd9IAvC 5ZSIoyNUQcaOLoATpxK42zfR7+HIS/HAXSmQ7v8rV9JapyWvcCWMav5LFirM0cT6s0wd 5qKyeC+PN8ZQkLhBn6HWSKLrilck3RfmnZTx79ODLpm4eIiZTZCfXR1liYriYVU7wW53 jE9NpnAjUvM5vuuWA9UJI06Pm48NzGb8glXW0m8gPO0SVL2Zf/lxCVVu55qhMNrQyU+s 3JH5WBIyMB1pxwR3CuEVRTqZmbRKnxjYtiSr9t4OTCpOb0eTuxxvsSnGj2xfkNI7hj2E Z9Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680921789; 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=tVI6SHexqk/fHDW9ZV/hvRMhbzKIOya+xJv7Fb+vwi4=; b=hoPLCz5LnDuzevOzAe5lIjXfQN019bfn4OlYOOEAU5WebUKnsZyRuZwwlQ+9zliaNE 5jxqtTcpHPqTUuZ0znUNKQzSVCX+xjSQtFACts5foetd/Y/MqQuoEjYfu1lBxGif8gdh Fcb9nAuQKaUQ/3+2KHbk8Oy3OgKLKCsqs9zCpJemp6GrkYMlp3vTODfeyFrjw7MqGqAr tcjOAFkAN0x1RJA4yfH1ITFAj263SES0Z+nY61VZ31k+vqmIyk8OFsDwaTdmSq8rNa4r nt18xDXJWTTVBg75UMKipeUlWd9aA8YQuv6G9MuaLM3kyIZEEJQ4HXQP1bxDc+MdHMPi IziQ== X-Gm-Message-State: AAQBX9eZYnwZYiTTwOhyTNc1bubKRmgS+fs3O37qfvF27PWOs8yT6bgm TQtYAJposFrsRIDpjgiyE4o= X-Google-Smtp-Source: AKy350a8pp89Lmb0L32kNG2BtIDECP+aTtm7jUt/8Kv3yvJ34QxCn+N41cdSWhVI0BR4oiH6CSF61A== X-Received: by 2002:a17:90b:164f:b0:240:67d5:aea1 with SMTP id il15-20020a17090b164f00b0024067d5aea1mr4936950pjb.14.1680921789153; Fri, 07 Apr 2023 19:43:09 -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 r14-20020a17090a4dce00b00233db0db3dfsm5309655pjl.7.2023.04.07.19.43.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2023 19:43:08 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3731.500.231) Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=casouri@gmail.com; helo=mail-pl1-x62f.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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:305166 Archived-At: > On Apr 7, 2023, at 6:32 PM, Dmitry Gutov wrote: >=20 > On 07/04/2023 17:20, Daniel Mart=C3=ADn wrote: >> In general, I'd suggest taking a look at Neovim's Tree-sitter >> implementation and perhaps reuse (part of) their .scm Tree-sitter = syntax >> highlight or indentation queries: >> = https://github.com/nvim-treesitter/nvim-treesitter/tree/master/queries/c >> Neovim's implementation doesn't "blink" in the scenarios presented = here, >> but I'm not sure about how it performs in other tricky cases. >=20 > Looking at that file, it does contain queries that look for ERROR = nodes, e.g. >=20 > ( > ERROR > "for" "(" @indent.begin ";" ";" ")" @indent.end) >=20 > So perhaps we should revisit that approach too. Yeah, some more specific error handling can be only beneficial. >=20 >> Now that text editors have access to the same programming language >> grammars, I'm surprised the Tree-sitter community hasn't started any >> cross-team effort to work on canonical queries (or slighter richer >> abstractions) per programming language. Text editor developers are >> working and rediscovering complex language problems independently. >=20 > We could do an indent implementation that just uses these indents.scm = files. Not exactly sure why we didn't start out this way, but note that = our Lisp based solution is a lot more flexible. >=20 > E.g. there doesn't seem to be an obvious way to support "indentation = styles" with these. The indent.scm way basically queries the whole file with all the = queries, build a hash map out of the captured nodes, then get the node = at the current line and go up the tree; at each parent, check if it=E2=80=99= s a node that was captured, if so, add an indentation level. To be honest, this will work fine in even largish files, but it=E2=80=99ll= be slow when you indent a region instead of a line (in a large file). = And as you said, it=E2=80=99s a bit more work to support styles. But, = there are ways to make this method more efficient, by using some caching = and localizing, so maybe it could work. indent.scm definitely looks neater and more convenient to write than the = rules we use (plus it already exists). So it would be nice to somehow = make it compatible. I=E2=80=99ve been trying to conceive some way to = convert the normal query into something more flexible, so that it can be = used for more than querying =E2=80=9Ctop-down=E2=80=9D from a node. For = example, verifying that a node would be captured as xxx in a query. Ideas and patches are welcome :-) Yuan=