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: CC Mode -> Tree sitter challenge Date: Sun, 6 Nov 2022 16:11:23 -0800 Message-ID: <7D986EF0-5967-47B9-A59B-747ABA08F6DF@gmail.com> References: <87v8nu1mt1.fsf@thornhill.no> <83eduh4vcf.fsf@gnu.org> <87mt951r69.fsf@thornhill.no> <83tu3d34u7.fsf@gnu.org> <87eduhxy9l.fsf@thornhill.no> <83pme130xs.fsf@gnu.org> <717833B0-285B-460F-B37B-F0B215BD1185@thornhill.no> <3A13DCFD-3306-492B-8022-DCE95EC340A3@thornhill.no> <87a655xspj.fsf@thornhill.no> <4E432374-A97A-48A0-A1C8-89C1DB47A7F8@gmail.com> 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="10686"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, Eli Zaretskii , monnier@iro.umontreal.ca To: Theodor Thornhill Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Nov 07 01:11:47 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 1orpju-0002Xv-Iu for ged-emacs-devel@m.gmane-mx.org; Mon, 07 Nov 2022 01:11:46 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1orpjf-0001XZ-N5; Sun, 06 Nov 2022 19:11:31 -0500 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 1orpje-0001XO-3X for emacs-devel@gnu.org; Sun, 06 Nov 2022 19:11:30 -0500 Original-Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1orpjb-0007kl-MP; Sun, 06 Nov 2022 19:11:29 -0500 Original-Received: by mail-pj1-x1029.google.com with SMTP id v4-20020a17090a088400b00212cb0ed97eso8861539pjc.5; Sun, 06 Nov 2022 16:11:26 -0800 (PST) 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 :message-id:reply-to; bh=uP37esHhOFnPmNNP+1PGKhjy77te8PYkRrCBpB0/zqc=; b=AHiVynNIeQYzxIBpZVP9HGmIN5YpdlImGEpYi6c9LSX0hgKBfORuDZpTt7nbUlcbwf yB9lgo+dgtEUSGIqE9eLcdIzuney6BBJ5EuQQYChY3sIS5ZpjkrxJVhsv14g7QTbT+fR oj8Vxg4pTLlWeA5SPHhyqKpyKLTXRmJ37EbW7f4v9K37seddNJi7ttMHgRNOJJRcD/NP 3eP3JjeMo1qiPcMAapQqz+y6bRMUhRdRMYFvwnNEhJMLITi52YSM91U5cdeFq2D/ZujC Oeu02+CRIfYSr0UgVpgdGa5Av+TmlhanHFzfpeGXeWBTQcpTclUlJuK8roPD53LRRyi5 pIbA== 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:message-id:reply-to; bh=uP37esHhOFnPmNNP+1PGKhjy77te8PYkRrCBpB0/zqc=; b=w6n8jOQ6RBLgRs4YVpWO+gHDMjFsVXrMueWokchTFqYClnGNyU5VqWGO4lIAdc0D5A HzCTIF4Jx2bWOJ4l2GH8wPZWU7RVjSa75VoLlT+j+g2ZvLApsT3GzXnw/ZtB1Jc1Olng 6Fzla2PxgkURsSsuWPjvNVKvAx9qjd3i04VysRJNcuIqlDTCu0MFxt/hhweHVNm2aQjx NmnDCCIrTmMEPJ9NcUcfNEkA8zxmybj2DuTCg7N7kOsN+YEmdavmSvqffFQOQb9SoiJt 7Ili0uYf+TQ6UD9oVg+CF0U9n7G45wP9yHDToIjoXP4NfmHKHfboMtrEYt2BK6EUFK1i LUlQ== X-Gm-Message-State: ACrzQf3ZwgB3a0RFWjJndTZdJNcAltNYIDZMFf9qtXJ5MXLLA6U3Bvm4 BAkBiMToaBZV4MqlRn0x76I= X-Google-Smtp-Source: AMsMyM4azT27tCL1gwtbfxS/AJBRNAQTdnoHwqbEbldOU4CtxM3HUy2YkgCd019hi3Nl8mLy6uN5lA== X-Received: by 2002:a17:90a:1994:b0:212:f4e9:cebf with SMTP id 20-20020a17090a199400b00212f4e9cebfmr66439113pji.51.1667779885510; Sun, 06 Nov 2022 16:11:25 -0800 (PST) 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 d5-20020a170902654500b0016c9e5f291bsm3618706pln.111.2022.11.06.16.11.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Nov 2022 16:11:25 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=casouri@gmail.com; helo=mail-pj1-x1029.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:299271 Archived-At: > On Nov 5, 2022, at 11:04 PM, Theodor Thornhill = wrote: >=20 >=20 >=20 > On 6 November 2022 02:13:14 CET, Yuan Fu wrote: >>=20 >>=20 >>> On Nov 5, 2022, at 9:38 AM, Theodor Thornhill = wrote: >>>=20 >>>=20 >>> Hi again, Eli! >>>=20 >>>>>=20 >>>>> Interesting. My guess is that there are still some improvement = possible in the indent-region code, considering that part of treesit.el = is quite new. >>>>>=20 >>>>> What do you think, Yuan? Any thoughts? >>>>>=20 >>>>> Anyways, I'll keep working on this and see how far I get next = coming weeks. At least in performance it seems I have a good thing going = here :-) >>>>>=20 >>>>=20 >>>> Thinking of it, some of the indentation questions isn't compiled. = I'll run it again later when they are compiled as well :-) >>>>=20 >>>=20 >>> Yes, that was the issue. Now the scores are as follows: >>=20 >> The indentation code has a list of rules, and it runs each rule = top-to-bottom until one rules matches, then it uses that rule to = determine how much to indent. The ordering of each rule could be tweaked = so that most frequent case comes forward. We can also arrange these = rules not linearly but in a tree, so if one rules matches/doesn=E2=80=99t = match, some other rules can be skipped. >=20 > I think the system as it is now it fine, at least for the time being. = But I hold no strong opinions there :) Yeah if there is no performance issue, it=E2=80=99s better to keep = things simple. >>=20 >> What exactly did you compile? I tried byte-compiling indentation = rules before but didn=E2=80=99t see a significant speed-up. >>=20 >> Yuan >=20 > See = https://git.sr.ht/~theo/tree-sitter-modes/tree/master/item/c-ts-mode.el#L9= 2 >=20 > Sometimes when exploring indentation i use rules like this. Usually I = try to find other ways after, but I just assumed they weren't perf = problems. Apparently they are! I see, we can precompile these queries automatically for the user.=20 >=20 > And by the way, i created an anchor like this:=20 > = https://git.sr.ht/~theo/tree-sitter-modes/tree/master/item/c-ts-mode.el#L5= 7 >=20 > This is nice when you need to just move a token to col 0, such as = preproc-directives. Maybe that should be a standard one? It could use = the buffer-root-node, but this was so simple and fast that I just did it = like that. >=20 > What do you think? I=E2=80=99ll add it, thanks! Yuan=