From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?=C3=93scar?= Fuentes Newsgroups: gmane.emacs.bugs Subject: bug#71086: 30.0.50; Setting treesit-indent-function is not effective is treesit-simple-indent-rules is nil Date: Wed, 22 May 2024 16:15:13 +0200 Message-ID: <87cypec4r2.fsf@telefonica.net> References: <87y184q7ai.fsf@telefonica.net> <86pltf8k61.fsf@gnu.org> 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="1496"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , 71086@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 22 16:16:36 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1s9mlf-00007F-Q6 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 May 2024 16:16:35 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9mlA-0007u9-NA; Wed, 22 May 2024 10:16:05 -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 1s9ml4-0007r3-Bc for bug-gnu-emacs@gnu.org; Wed, 22 May 2024 10:15:58 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s9ml2-0000rK-09 for bug-gnu-emacs@gnu.org; Wed, 22 May 2024 10:15:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s9ml7-0003R5-Oa for bug-gnu-emacs@gnu.org; Wed, 22 May 2024 10:16:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?=C3=93scar?= Fuentes Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 May 2024 14:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71086 X-GNU-PR-Package: emacs Original-Received: via spool by 71086-submit@debbugs.gnu.org id=B71086.171638733013197 (code B ref 71086); Wed, 22 May 2024 14:16:01 +0000 Original-Received: (at 71086) by debbugs.gnu.org; 22 May 2024 14:15:30 +0000 Original-Received: from localhost ([127.0.0.1]:56207 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9mkc-0003Qn-Hj for submit@debbugs.gnu.org; Wed, 22 May 2024 10:15:30 -0400 Original-Received: from relayout01-q01.e.movistar.es ([86.109.101.141]:48715) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9mkY-0003Qh-LA for 71086@debbugs.gnu.org; Wed, 22 May 2024 10:15:28 -0400 Original-Received: from relayout01-redir.e.movistar.es (unknown [86.109.101.201]) by relayout01-out.e.movistar.es (Postfix) with ESMTP id 4VktcM2GmRzjYp2; Wed, 22 May 2024 16:15:15 +0200 (CEST) Original-Received: from sky (81.red-81-39-130.dynamicip.rima-tde.net [81.39.130.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: 981711563@telefonica.net) by relayout01.e.movistar.es (Postfix) with ESMTPSA id 4VktcL2syPzfbNr; Wed, 22 May 2024 16:15:14 +0200 (CEST) In-Reply-To: (Yuan Fu's message of "Tue, 21 May 2024 23:23:30 -0700") X-TnetOut-Country: IP: 81.39.130.81 | Country: ES X-TnetOut-Information: AntiSPAM and AntiVIRUS on relayout01 X-TnetOut-MsgID: 4VktcL2syPzfbNr.A8B13 X-TnetOut-SpamCheck: no es spam, clean X-TnetOut-From: oscarfv@telefonica.net X-TnetOut-Watermark: 1716992115.0407@WkuHFo9YIvpiuABG2Fu2Xg X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:285627 Archived-At: Yuan Fu writes: > There are actually another level of customization between setting > treesit-simple-indent-rules and setting indent-line-function, which is > setting treesit-indent-function. IIUC =C3=93scar is trying to do that but > found out treesit-major-mode-setup doesn=E2=80=99t automatically setup > indent-line-functions when treesit-indent-function is set. More specifically, I found that treesit-major-mode-setup doesn't setup indentation when treesit-simple-indent-rules is *not* set, even when treesit-indent-function has been set. > I=E2=80=99ve now fixed that. Indeed, thank you. > (Though I didn=E2=80=99t expect someone to use this variable.) Why not? It is documented and the natural alternative when treesit-simple-indent-rules is not fit for the job, isn't it? > And to =C3=93scar, I=E2=80=99m curious and interested to know what indent= ation > function you came up with; if it=E2=80=99s useful maybe we can add it to > Emacs? I started with treesit-simple-indent-rules until I stumbled on something that it is not easily workable with the existing functions. My language has a Lisp syntax, and the problem was with indenting comments (and with how the presence of comments affected the indentation of other things). For instance, the typical indentation of (if p foo bar) That's simple enough to achieve with treesit-simple-indent-rules, but if we insert a comment: (if p ;; blah (foo) (bar)) things suddenly turn hairy. Likewise, starting with this: (progn (foo) (bar)) ... after inserting a comment, this is the desired indentation: (progn ;; blah (foo) (bar)) ... not this: (progn ;; blah (foo) (bar)) Maybe a variant of `match' and `nth-sibling' that take an argument of node types to skip would be enough to cover this case? That was basically what I did. Anyways, going the treesit-indent-function route was easy enough, and it is more powerful, flexible and future-proof. I don't think that treesit-simple-indent-rules would yield a significantly shorter and mantainable implementation. > I also updated the manual. Thanks! BTW, the treesit-based implementation of the major mode for this simple language is a tiny fraction of its traditional counterpart. And providing a great basis for adding more features :-)