From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61502: 29.0.60; c-ts-mode auto-indent not working Date: Wed, 15 Feb 2023 07:07:59 +0100 Message-ID: References: <87v8k4g8xu.fsf@codeisgreat.org> <83a61ge69s.fsf@gnu.org> <87edqs11db.fsf@thornhill.no> <67e055d8-c709-df09-374e-560057f61731@yandex.ru> Reply-To: Theodor Thornhill 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="28892"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 61502@debbugs.gnu.org To: Dmitry Gutov , Eli Zaretskii , Pankaj Jangid , Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 15 07:09:26 2023 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 1pSAyr-0007Ic-Rn for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 15 Feb 2023 07:09:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSAyZ-0000MC-SN; Wed, 15 Feb 2023 01:09:07 -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 1pSAyV-0000Lw-5T for bug-gnu-emacs@gnu.org; Wed, 15 Feb 2023 01:09:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSAyU-00089e-SF for bug-gnu-emacs@gnu.org; Wed, 15 Feb 2023 01:09:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pSAyU-0000AW-Hi for bug-gnu-emacs@gnu.org; Wed, 15 Feb 2023 01:09:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 15 Feb 2023 06:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61502 X-GNU-PR-Package: emacs Original-Received: via spool by 61502-submit@debbugs.gnu.org id=B61502.1676441297593 (code B ref 61502); Wed, 15 Feb 2023 06:09:02 +0000 Original-Received: (at 61502) by debbugs.gnu.org; 15 Feb 2023 06:08:17 +0000 Original-Received: from localhost ([127.0.0.1]:57610 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pSAxk-00009V-Pe for submit@debbugs.gnu.org; Wed, 15 Feb 2023 01:08:17 -0500 Original-Received: from out-86.mta1.migadu.com ([95.215.58.86]:56130) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pSAxh-00009J-1a for 61502@debbugs.gnu.org; Wed, 15 Feb 2023 01:08:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1676441290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=35YQYnshj8imVg/EYIvgudWvgCOGaQ+uH+hHbbN/zu8=; b=P7Ir/q4zz315ZNtxAxTdvOKR/FHxfsxzv++mrdPRuSnU2BlniUBzGatG+VxC1Je7HLmkTo NSpJnaTuxWm1u7aVOsChwl1ZTN5I7N3tYGS68SSANelmxy/nPbhVDzzk84aoibh5c6MQ18 4gjinnDNmuk4c5TYhPRu1lQXSS7rcn0yL0TbA/ylbMpdvMK3Q0y0Kqivo6FO0jqWTdqF5g 3GIxP0SD7COgrIZl32rV+kU/y+g7x1shIVg3J4nYP+GdkbJX3uw6hfcRZ73jl4n1oABExy 049pDcFrf0DJEd8zkXGpdsw+Xwbt41pb5/YUgoQaUPAk10uB5MUv20T2mwwqYw== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-Reply-To: <67e055d8-c709-df09-374e-560057f61731@yandex.ru> X-Migadu-Flow: FLOW_OUT 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:255667 Archived-At: On 15 February 2023 00:57:17 CET, Dmitry Gutov wrote: >On 14/02/2023 21:41, Theodor Thornhill via Bug reports for GNU Emacs, the= Swiss army knife of text editors wrote: >> What do you think? >>=20 >> Theo >>=20 >>=20 >> diff --git a/lisp/treesit=2Eel b/lisp/treesit=2Eel >> index 749781894b=2E=2E300a703515 100644 >> --- a/lisp/treesit=2Eel >> +++ b/lisp/treesit=2Eel >> @@ -1418,6 +1418,8 @@ treesit--indent-1 >> ;; encompass the whitespace=2E >> (parent (cond ((and node parser) >> (treesit-node-parent node)) >> + ((equal (treesit-node-type smallest-node) "}") >> + (treesit-node-parent smallest-node)) >> (t (treesit-node-on bol bol))))) >> (funcall treesit-indent-function node parent bol)))) > >Here's a counter-example for this patch: > >int >main () >{}| > >press RET at |, and you'll see the next line indented by 2 spaces=2E Wher= eas it shouldn't=2E This happens, among other things, because the added cod= e doesn't distinguish between "real" and "virtual" nodes=2E > >BTW, in this example: > >int >main >{ > for (;;) > {| >} > >the "}" node selected by treesit--indent-1 is not "unexisting": it select= s the closer on the next line, which is parsed to be the part of the "for" = node=2E Thanks to its presence, the parent compound_statement node contains= the point, and everything works out=2E > >And this one > >int >main >{ > for (;;)| >} > >isn't fixed with your patch because the "unexisting" node in place is a d= ifferent one: "expression_statement", and it has no closers=2E And it's "vi= rtually" placed at the end of the previous line by the parser=2E > >So in most cases if the user has electric-pair-mode on, indentation shoul= d work okay=2E Without a pairing solution, though, we see different grammar= s handling incomplete code in different ways for different syntactic elemen= ts: virtual nodes, container nodes that span after point, container nodes t= hat don't span after point, statements that parse into a different node typ= e (usually wrapped in ERROR)=2E We could report these one by one, hoping fo= r the best=2E I'm curious how different editors fare with indentation in th= ese conditions -- perhaps they use a different, more error-proof approach= =2E But it could be that their uses are less fussy about indentation than w= e are=2E Sure, i agree - the patch was not a change request, merely an example to s= how why the root node was chosen rather than the closer compound_statement = node=2E