From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Konstantin Kharlamov Newsgroups: gmane.emacs.devel Subject: Re: tree-sitter: conceptional problem solvable at Emacs' level? Date: Sat, 11 Feb 2023 12:37:30 +0300 Message-ID: <1c17038bf458a7c05e1f260ee0ffb5d342f80bba.camel@yandex.ru> References: <87zg9n45ig.fsf@yahoo.com> <0DDF6978-D75A-4137-9D93-6200908675B6@gmail.com> <837cwplxni.fsf@gnu.org> <83zg9lkagi.fsf@gnu.org> <87ttzt0wtv.fsf@yahoo.com> <357e68eacfb7931fae08704ebfcbe1178a08fd69.camel@yandex.ru> <0768E0D7-6D58-40AC-A1D4-784C27CE0D7F@thornhill.no> <1f06600f6fcffebff90234bf4875c89b747a8841.camel@yandex.ru> 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="28864"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.46.3 Cc: Holger Schurig To: Theodor Thornhill , emacs-devel@gnu.org, Po Lu , Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Feb 11 10:38: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 1pQmKm-0007MN-EK for ged-emacs-devel@m.gmane-mx.org; Sat, 11 Feb 2023 10:38:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQmKD-0006Xx-JR; Sat, 11 Feb 2023 04:37:41 -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 1pQmKB-0006Xl-Bd for emacs-devel@gnu.org; Sat, 11 Feb 2023 04:37:39 -0500 Original-Received: from forward502a.mail.yandex.net ([178.154.239.82]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQmK8-0004vi-DM; Sat, 11 Feb 2023 04:37:38 -0500 Original-Received: from vla1-7447ae3f89af.qloud-c.yandex.net (vla1-7447ae3f89af.qloud-c.yandex.net [IPv6:2a02:6b8:c0d:3281:0:640:7447:ae3f]) by forward502a.mail.yandex.net (Yandex) with ESMTP id 446315EAD0; Sat, 11 Feb 2023 12:37:32 +0300 (MSK) Original-Received: by vla1-7447ae3f89af.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id VbcFmFJaCmI1-PzrlryDM; Sat, 11 Feb 2023 12:37:31 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1676108251; bh=QRH4lKdoVEEQ55GLZaKsU5uhGDzVeDxPSD8npqSR7zY=; h=References:Date:In-Reply-To:Cc:To:From:Subject:Message-ID; b=f/v9vN0eu82TUW/xDBzijuMROYr+tsIHxO/SmVhryaCrcb5lHt1EWJ8xzw+1r+6Oh Pm7GaOFlFKEypU4y6fcfxbLp4viuqU33utqUKuzA9nkT68uPphVSpyRwVV1zNlZ2tF /rnm5/EFJ6E4y87WxXCuDiTd7c6rEGsuXk2R6N68= Authentication-Results: vla1-7447ae3f89af.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru In-Reply-To: Received-SPF: pass client-ip=178.154.239.82; envelope-from=hi-angel@yandex.ru; helo=forward502a.mail.yandex.net 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, 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:303134 Archived-At: On Sat, 2023-02-11 at 09:41 +0100, Theodor Thornhill wrote: >=20 >=20 > On 11 February 2023 09:22:06 CET, Konstantin Kharlamov > wrote: > > On Sat, 2023-02-11 at 10:11 +0300, Konstantin Kharlamov wrote: > > > On Sat, 2023-02-11 at 07:51 +0100, Theodor Thornhill wrote: > > > >=20 > > > >=20 > > > > On 11 February 2023 07:36:26 CET, Konstantin Kharlamov > > > > > > > > wrote: > > > > > On Sat, 2023-02-11 at 09:25 +0300, Konstantin Kharlamov wrote: > > > > > > On Sat, 2023-02-11 at 10:17 +0800, Po Lu wrote: > > > > > > > Eli Zaretskii writes: > > > > > > >=20 > > > > > > > > However, I meant the IDEs which are using tree-sitter and > > > > > > > > support > > > > > > > > developing C/C++ programs.=C2=A0 I believe some do. > > > > > > >=20 > > > > > > > I think most of those have similar problems supporting macros= . > > > > > > > Who knows their names? I may be able to ask some of their use= rs. > > > > > >=20 > > > > > > From my experience on and off work, there are just two IDEs (as= in, > > > > > > not > > > > > > editors) > > > > > > used most widely for C++ code: QtCreator and Visual Studio. The > > > > > > first > > > > > > you > > > > > > discussed, the second is proprietary. > > > > > >=20 > > > > > > Then again, people most often code in C++ and C with text edito= rs, > > > > > > in > > > > > > that > > > > > > case > > > > > > popular choices from my experience: Sublime Text and VS Code. T= hese > > > > > > two > > > > > > have > > > > > > don't use tree-sitter either. > > > > >=20 > > > > > I installed Sublime Text on my Archlinux and tested with the C++ = code > > > > > OP > > > > > posted. > > > > >=20 > > > > > What I see is that ST does seem confused about indentation, while > > > > > trying > > > > > to > > > > > make > > > > > a newline right after `slots:` line. > > > > >=20 > > > > > However, if you try to make a newline after the `void someSlot() = {};` > > > > > line, > > > > > it > > > > > will use the indentation used on the previous line. > > > > >=20 > > > > > The default cc-mode in Emacs works similarly. The cc-ts-mode on t= he > > > > > other > > > > > hand > > > > > doesn't make use of the previous indentation, and I think it shou= ld. > > > > > It > > > > > would > > > > > resolve that problem and others, because in my experience it happ= ens > > > > > very > > > > > often > > > > > in C and C++ code that you want some custom indentation level, so= you > > > > > just > > > > > make > > > > > one and you expect the editor to keep it while creating more new > > > > > lines. > > > > >=20 > > > >=20 > > > > That last statement sounds easily solvable. Can you send me a short > > > > example > > > > describing exactly what you want in a code snippet and I'll add it. > > > >=20 > > > > Thanks, > > > > Theo > > >=20 > > > Thank you! The example is below, but please wait a bit just to make s= ure > > > there's no opposition from other people, because I don't know if it w= orks > > > like > > > this on purpose, or not. > > >=20 > > > Given this C++ code with weird class members indentation: > > >=20 > > > =C2=A0=C2=A0=C2=A0 class Foo { > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int a; > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bool b; > > > =C2=A0=C2=A0=C2=A0 }; > > >=20 > > > Now, suppose you put a caret after `bool b;` text and press Enter to = make > > > a > > > new > > > line (all tests are done with `emacs -Q`). The behaviour: > > >=20 > > > * cc-mode and Sublime Text: creates a newline with the indentation ex= actly > > > as > > > on > > > the previous one. > > > * cc-ts-mode: re-indents the `bool b;` line, then creates a new one w= ith a > > > custom indentation that is different from one on the `int a;` line. > > >=20 > > > The cc-mode and Sublime Text behaviour seems like less annoying to me= , > > > because > > > if I wanted to reindent the prev. line, most likely I'd did it by pre= ssing > > > an > > > indentation hotkey (e.g. `=3D` in Evil mode I use). > >=20 > > Oh, wait, though I mistakengly used c-mode instead of c++-mode. The c-m= ode > > works this way, it keeps prev. indentation, however c++-mode instead us= es a > > new indentation. It's odd they behave differently, and it certainly is > > different from other modes (e.g. emacs-lisp-mode). In this case I think= the > > question of whether it should re-use prev. line indentation, which I th= ink > > the should. >=20 > C-mode or c-ts-mode? >=20 > Yeah, this is what I'm thinking too. I'll look at it tonight or tomorrow = :) c-ts-mode works the same way as c++-ts-mode does. Upon further inspection I realised that the vanilla c-mode keeps previous indentation in aforementioned case just because it doesn't recognise `class= ` keyword. But if you replace it with `struct`, it will make use of whatever indentation it thinks is correct instead of one from previous line. However, actually, the vanilla c-mode and c++-mode behave inconsistently. Depending on the code they may or may not make use of previous indentation.= So anyway, I re-created an example where indentation is being kept in ST, c-mo= de, c++-mode, but not in c-ts-mode or c++-ts-mode, below. I also threw in other editors for comparison. Given this code: int main() { foobar( arg1, arg2 ); } Suppose you put a caret after `arg2` text and press Enter to make a new lin= e (all tests are done with `emacs -Q`). The behaviour: * c-mode, c++-mode, Sublime Text (both with `.c` and `.cpp` file), VS Code = (both with `.c` and `.cpp` file): creates a new line indented same way as previou= s one. * c-ts-mode, c++-ts-mode: re-indents the `arg2` line to have indentation different from `arg1,` line, and creates a new line that also has new indentation. * QtCreator: lol, it does no indentation whatsoever in this case. Overall, it seems like "using the previous indentation" is the way to go, i= t also is used in VS Code and Sublime Text. As a side note, if a user explicitly wants to re-indent the code, behaviour should depend on how much text they selected for re-indentation (at least c= -mode and c++-mode behave this way) which is intuitive. For example: if I only se= lect arg2 line, then re-indentation uses previous offsets, so basically nothing happens. However if I select arg1 and arg2 lines, then indentation would be different because the previous line has a different syntax construction of "opening parenthesis", so the default indentation for that case is used, wh= ich is "indent arguments to the opening parenthesis of the function".