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: treesit indentation "blinking" Date: Sat, 1 Apr 2023 18:49:46 -0700 Message-ID: <9F152CAA-6326-459F-84FF-87988B3A92B6@gmail.com> References: <87h6ucik61.fsf@dancol.org> <0F406D08-56D4-4B21-B94D-A47681606911@gmail.com> <1870bcadd28.2829.cc5b3318d7e9908e2c46732289705cb0@dancol.org> <1870cce6690.2829.cc5b3318d7e9908e2c46732289705cb0@dancol.org> <35A837A9-59B4-4F1F-A5FA-8483C8024D76@gmail.com> <187104f6b48.2829.cc5b3318d7e9908e2c46732289705cb0@dancol.org> <21d018e5-a730-12e3-f97c-fffa4f646ccf@yandex.ru> <83v8ioc2ou.fsf@gnu.org> <87sfdsx0r2.fsf@gmail.com> <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> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.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="5633"; mail-complaints-to="usenet@ciao.gmane.io" Cc: theodor thornhill , geza.herman@gmail.com, Daniel Colascione , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 02 03:50:57 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 1pimrx-0001Gt-7U for ged-emacs-devel@m.gmane-mx.org; Sun, 02 Apr 2023 03:50:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pimr8-0001X0-NA; Sat, 01 Apr 2023 21:50:06 -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 1pimr6-0001W8-KK for emacs-devel@gnu.org; Sat, 01 Apr 2023 21:50:04 -0400 Original-Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pimr3-0001CR-Kg; Sat, 01 Apr 2023 21:50:03 -0400 Original-Received: by mail-pl1-x62e.google.com with SMTP id w4so24935989plg.9; Sat, 01 Apr 2023 18:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680400199; 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=bb76nTsG3NF+x//j+mtJq+AQRXzmm8Jflerof87uFZA=; b=hVO78Hf48kr9uOhL13bjupuOMxSZpimac82EVzDa7nuRYAYHjTPJa1Z3ScK3vWG65F qtI7HdlBwg/wvcWYDs0FygVLaYQOI9eizxA1Xv9OyDQtQGy5waWS96BXHVDd+38gWFw4 hjoC+iMG1ypKpXUpJy5BTxc9jH7dhrI0eDMARMUaLc0dREhJ1sgIsGffEej54SdJAd8g pPyYf/XeazoS85dmqT4G7pV1xg0BpSxjcnJrLs5zSX8hzAphp84bYd5F7/KridiXEl8W SwkEvDxUo2nWnPk6yQB22j6XgdGyacvIgSWuJrQMFP84MDDAgYzU2zp9mYBh9EV5YqTQ mlCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680400199; 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=bb76nTsG3NF+x//j+mtJq+AQRXzmm8Jflerof87uFZA=; b=BlFAv47Cow9Ago4Z+XymLb9p1dxAxZHaTs9q/4C9kfGMa97Pvhk+QYkNZh3SYlPaCH 1CNt0BKkpQH+yaEgRqC++oS5TNvLxAskwjpFJknkFuONwcXlCHCeiekCkKijzfgaPGPh nTPzcFg52rDcTCYU8MntjZlZOAJvgBNFVbBPYgOjG3sYD5HzYXUCA3d+VGjInVvZQtRd jIknfAAOEpXB6MAsVD1PwEHhsNpKMBSPiMiOB68bb88Suo5oz1FV4OygQgNTfhxgkc0o rGXkBLYzimeix7Dy24Ja6Jd4CaGN1a6PvfP+GbXCWbF6WUaz5sI4dX3ROur7XOKLYkyD 5A4Q== X-Gm-Message-State: AAQBX9dGIDijLrpcke8sTGgxuvQUT67eXi1wkJizNAHi68zVvCSMSFzv 9NYIo3x3n4tqv/Nm/APGgjSu13jftoQ= X-Google-Smtp-Source: AKy350aoWVRby6SjtIbJXAPWTZXtphhQx5kXWZlJLyoVV9UFANiP2RuLmCAlYpSsebHDXxeT1mk8oA== X-Received: by 2002:a17:902:f2d3:b0:199:1160:956c with SMTP id h19-20020a170902f2d300b001991160956cmr10444908plc.31.1680400199371; Sat, 01 Apr 2023 18:49:59 -0700 (PDT) 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 g3-20020a170902868300b0019a96a6543esm3936579plo.184.2023.04.01.18.49.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Apr 2023 18:49:59 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3731.400.51.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=casouri@gmail.com; helo=mail-pl1-x62e.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:305025 Archived-At: > On Apr 1, 2023, at 12:39 PM, Yuan Fu wrote: >=20 >=20 >=20 >> On Mar 30, 2023, at 7:58 AM, Eli Zaretskii wrote: >>=20 >>> From: Herman, G=C3=A9za >>> Cc: Jo=C3=A3o T=C3=A1vora , >>> 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 >>>=20 >>> Type this example into a c++-ts-mode buffer (I used "emacs -Q"): >>>=20 >>> --8<---------------cut here---------------start------------->8--- >>> int main() { >>> for (;;) { >>> printf("Hello world\n"); >>> } >>> } >>> --8<---------------cut here---------------end--------------->8--- >>>=20 >>> 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. >>>=20 >>> Or, another example. Put the "void foo() { }" part first into a >>> c++-ts-mode buffer, then write the main function: >>>=20 >>> --8<---------------cut here---------------start------------->8--- >>> int main() { >>> int a =3D 0; >>> for (;;) { >>> printf("Hello!\n"); >>> } >>> } >>>=20 >>> void foo() { >>> } >>> --8<---------------cut here---------------end--------------->8--- >>>=20 >>> Again, c++-ts-mode doesn't indent anything. >>>=20 >>> If you change the example to contain "void foo();" instead of "void >>> foo() { }", then indenting happens during typing the main function. >>>=20 >>> If you try adding "int a =3D 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: >>>=20 >>> --8<---------------cut here---------------start------------->8--- >>> int main() { >>> int a =3D 0; >>> for (;;) { >>> printf("Hello world\n"); >>> } >>> } >>> --8<---------------cut here---------------end--------------->8--- >>>=20 >>> If you start by adding an empty comment, and then write the first >>> example above the empty comment, the buffer will look like this: >>>=20 >>> --8<---------------cut here---------------start------------->8--- >>> int main() { >>> for (;;) { >>> printf("Hello world\n"); >>> } >>> } >>>=20 >>> /**/ >>> --8<---------------cut here---------------end--------------->8--- >>=20 >> 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? >=20 > I=E2=80=99ll have a look! Ok, the reason is that while you were typing, because the closing = bracket was missing, the parser couldn=E2=80=99t produce a =E2=80=9Cgood=E2= =80=9D 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=E2=80=99t 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. Trying to solve this with heuristics is going against to grain, IMO. I = think it=E2=80=99s acceptable to say that users of ts-modes should = enabled electric-pair-mode, since it=E2=80=99s based on a parser, after = all. As for the blinking, I=E2=80=99ll let Theo to assess the solutions = mentioned earlier (removing some indentation rules set on error nodes).=20= Yuan=