From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: treesit indentation "blinking" Date: Sun, 2 Apr 2023 14:26:04 +0000 Message-ID: References: <87lejgsf0m.fsf@gmail.com> <83pm8s70o3.fsf@gnu.org> <83mt3u65vw.fsf@gnu.org> <87y1newqus.fsf@gmail.com> <83bkka5z7w.fsf@gnu.org> <871ql6a4d4.fsf@gmail.com> <83jzyy4776.fsf@gnu.org> <9F152CAA-6326-459F-84FF-87988B3A92B6@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21873"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , theodor thornhill , geza.herman@gmail.com, Daniel Colascione , emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 02 16:27:17 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 1piyft-0005Ui-AV for ged-emacs-devel@m.gmane-mx.org; Sun, 02 Apr 2023 16:27:17 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1piyfA-0003Wk-5l; Sun, 02 Apr 2023 10:26:32 -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 1piyf8-0003WY-N6 for emacs-devel@gnu.org; Sun, 02 Apr 2023 10:26:30 -0400 Original-Received: from mx3.muc.de ([193.149.48.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1piyey-0000SR-Sg for emacs-devel@gnu.org; Sun, 02 Apr 2023 10:26:23 -0400 Original-Received: (qmail 41012 invoked by uid 3782); 2 Apr 2023 16:26:05 +0200 Original-Received: from acm.muc.de (pd953a231.dip0.t-ipconnect.de [217.83.162.49]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 02 Apr 2023 16:26:05 +0200 Original-Received: (qmail 12973 invoked by uid 1000); 2 Apr 2023 14:26:04 -0000 Content-Disposition: inline In-Reply-To: <9F152CAA-6326-459F-84FF-87988B3A92B6@gmail.com> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.5; envelope-from=acm@muc.de; helo=mx3.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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:305036 Archived-At: Hello, Yuan. On Sat, Apr 01, 2023 at 18:49:46 -0700, Yuan Fu wrote: > > On Apr 1, 2023, at 12:39 PM, Yuan Fu wrote: > >> On Mar 30, 2023, at 7:58 AM, Eli Zaretskii wrote: > >>> From: Herman, Géza > >>> Cc: João Távora , > >>> dgutov@yandex.ru, dancol@dancol.org, > >>> casouri@gmail.com, theo@thornhill.no, emacs-devel@gnu.org > >>> Date: Thu, 30 Mar 2023 12:26:16 +0200 > >>> Type this example into a c++-ts-mode buffer (I used "emacs -Q"): > >>> --8<---------------cut here---------------start------------->8--- > >>> int main() { > >>> for (;;) { > >>> printf("Hello world\n"); > >>> } > >>> } > >>> --8<---------------cut here---------------end--------------->8--- > >>> This is how it will be indented as I wrote it here. c++-ts-mode doesn't > >>> re-indent anything during typing, even though it had the chance to do > >>> that, because electric-indent-mode is enabled by default, and > >>> electric-indent-chars contains the necessary characters. > >>> Or, another example. Put the "void foo() { }" part first into a > >>> c++-ts-mode buffer, then write the main function: > >>> --8<---------------cut here---------------start------------->8--- > >>> int main() { > >>> int a = 0; > >>> for (;;) { > >>> printf("Hello!\n"); > >>> } > >>> } > >>> void foo() { > >>> } > >>> --8<---------------cut here---------------end--------------->8--- > >>> Again, c++-ts-mode doesn't indent anything. > >>> If you change the example to contain "void foo();" instead of "void > >>> foo() { }", then indenting happens during typing the main function. > >>> If you try adding "int a = 0;" into the first example, then it will be > >>> indented at typing the ";". But then for loop is still not get indented, > >>> and the buffer will look like this: > >>> --8<---------------cut here---------------start------------->8--- > >>> int main() { > >>> int a = 0; > >>> for (;;) { > >>> printf("Hello world\n"); > >>> } > >>> } > >>> --8<---------------cut here---------------end--------------->8--- > >>> If you start by adding an empty comment, and then write the first > >>> example above the empty comment, the buffer will look like this: > >>> --8<---------------cut here---------------start------------->8--- > >>> int main() { > >>> for (;;) { > >>> printf("Hello world\n"); > >>> } > >>> } > >>> /**/ > >>> --8<---------------cut here---------------end--------------->8--- > >> Yuan and Theo, can you please look into these examples? A simple > >> "C-c C-q" fixes the indentation, but the question is why it doesn't > >> happen while typing? > > I’ll have a look! > Ok, the reason is that while you were typing, because the closing > bracket was missing, the parser couldn’t produce a “good” parse tree. > OTOH, the C parser can reasonably fix the source and produce something > easy to use by our indenting rules (perhaps due to its simpler grammar) > so you don’t see this problem in c-ts-mode. > If you enable electric-pair-mode so that the brackets are always > balanced, then both c-ts-mode and c++-ts-mode should work fine. That is not a solution. Some people dislike electric-pair-mode, and they would be faced with the unwelcome choice of having to put up with e-p-m or having source code not indenting (or jumping all over the place) on the text line being input. > Trying to solve this with heuristics is going against to grain, IMO. Does the parser not produce adequate information for source code which isn't syntactically valid (which is most of the time when editing is in progress)? > I think it’s acceptable to say that users of ts-modes should enable > electric-pair-mode, since it’s based on a parser, after all. electric-pair-mode is a user option. We shouldn't be mandating such things to users, they should be individual choices. I've had to use a proprietary editor where e-p-m couldn't be disabled (or at least I didn't know how to), and I hated it. Emacs should be better than such editors. That electric-pair-mode isn't needed to get reasonable electric indentation is demonstrated by CC Mode, where electric indentation occurs when needed, but rarely happens more than once per source line. > As for the blinking, I’ll let Theo to assess the solutions mentioned > earlier (removing some indentation rules set on error nodes). > Yuan -- Alan Mackenzie (Nuremberg, Germany).