From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: theodor thornhill <theo@thornhill.no>,
geza.herman@gmail.com, Daniel Colascione <dancol@dancol.org>,
emacs-devel@gnu.org
Subject: Re: treesit indentation "blinking"
Date: Sat, 1 Apr 2023 18:49:46 -0700 [thread overview]
Message-ID: <9F152CAA-6326-459F-84FF-87988B3A92B6@gmail.com> (raw)
In-Reply-To: <EED1F254-C8D2-4491-BF4F-C6BD57B9FE36@gmail.com>
> On Apr 1, 2023, at 12:39 PM, Yuan Fu <casouri@gmail.com> wrote:
>
>
>
>> On Mar 30, 2023, at 7:58 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>>
>>> From: Herman, Géza <geza.herman@gmail.com>
>>> Cc: João Távora <joaotavora@gmail.com>,
>>> 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.
Trying to solve this with heuristics is going against to grain, IMO. I think it’s acceptable to say that users of ts-modes should enabled electric-pair-mode, since it’s based on a parser, after all.
As for the blinking, I’ll let Theo to assess the solutions mentioned earlier (removing some indentation rules set on error nodes).
Yuan
next prev parent reply other threads:[~2023-04-02 1:49 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-22 20:49 treesit indentation "blinking" Daniel Colascione
2023-03-23 0:00 ` Yuan Fu
2023-03-23 0:07 ` Daniel Colascione
2023-03-23 1:02 ` Yuan Fu
2023-03-23 4:51 ` Daniel Colascione
2023-03-23 20:04 ` Yuan Fu
2023-03-23 21:10 ` Daniel Colascione
2023-03-23 21:24 ` Dmitry Gutov
2023-03-25 9:05 ` João Távora
2023-03-25 12:42 ` Dmitry Gutov
2023-03-25 14:42 ` Eli Zaretskii
2023-03-25 16:18 ` João Távora
2023-03-28 22:11 ` João Távora
2023-03-28 23:57 ` Daniel Colascione
2023-03-29 2:26 ` Eli Zaretskii
2023-03-29 22:30 ` João Távora
2023-03-29 22:37 ` Herman, Géza
2023-03-29 23:25 ` João Távora
2023-03-30 7:47 ` Herman, Géza
2023-03-29 22:56 ` Lynn Winebarger
2023-03-30 7:43 ` Eli Zaretskii
2023-03-30 8:58 ` Dmitry Gutov
2023-03-30 9:15 ` João Távora
2023-03-30 9:06 ` João Távora
2023-03-30 9:20 ` Dmitry Gutov
2023-03-30 9:28 ` João Távora
2023-03-30 9:36 ` Dmitry Gutov
2023-03-30 10:00 ` João Távora
2023-03-30 16:29 ` Dmitry Gutov
2023-03-30 17:14 ` João Távora
2023-03-30 10:07 ` Eli Zaretskii
2023-03-30 10:26 ` Herman, Géza
2023-03-30 13:39 ` Eli Zaretskii
2023-03-30 15:03 ` Herman, Géza
2023-03-30 14:58 ` Eli Zaretskii
2023-04-01 19:39 ` Yuan Fu
2023-04-02 1:49 ` Yuan Fu [this message]
2023-04-02 5:31 ` Eli Zaretskii
2023-04-02 14:26 ` Alan Mackenzie
2023-04-02 15:48 ` João Távora
2023-04-02 17:04 ` Alan Mackenzie
2023-04-02 17:23 ` João Távora
2023-04-02 17:51 ` Eli Zaretskii
2023-04-02 18:04 ` João Távora
2023-04-02 18:14 ` Eli Zaretskii
2023-04-02 21:38 ` João Távora
2023-04-02 21:21 ` Dmitry Gutov
2023-04-02 21:40 ` João Távora
2023-04-03 9:59 ` Alan Mackenzie
2023-04-03 10:28 ` João Távora
2023-04-03 12:07 ` Dmitry Gutov
2023-04-03 12:56 ` Alan Mackenzie
2023-04-03 20:58 ` Dmitry Gutov
2023-04-03 21:59 ` Daniel Colascione
2023-04-03 22:10 ` Dmitry Gutov
2023-04-04 8:31 ` João Távora
2023-04-07 14:20 ` Daniel Martín
2023-04-08 1:32 ` Dmitry Gutov
2023-04-08 2:42 ` Yuan Fu
2023-04-08 18:59 ` Daniel Martín
2023-04-03 21:47 ` parser error recovery algorithm vs " Stephen Leake
2023-04-04 12:01 ` John Yates
2023-04-04 13:40 ` Dmitry Gutov
2023-04-04 16:00 ` Stephen Leake
2023-04-04 13:50 ` Stephen Leake
2023-04-04 14:05 ` Dmitry Gutov
2023-03-30 11:05 ` João Távora
2023-03-30 14:00 ` Eli Zaretskii
2023-03-30 14:43 ` João Távora
2023-03-30 14:52 ` Eli Zaretskii
2023-03-30 15:42 ` João Távora
2023-03-25 16:14 ` João Távora
2023-03-24 11:39 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9F152CAA-6326-459F-84FF-87988B3A92B6@gmail.com \
--to=casouri@gmail.com \
--cc=dancol@dancol.org \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=geza.herman@gmail.com \
--cc=theo@thornhill.no \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.