From: "João Távora" <joaotavora@gmail.com>
To: Herman@debbugs.gnu.org, Géza <geza.herman@gmail.com>
Cc: Yuan Fu <casouri@gmail.com>,
Theodor Thornhill <theo@thornhill.no>,
62412@debbugs.gnu.org
Subject: bug#62412: 29.0.60; strange c++ indentation behavior with tree sitter
Date: Sat, 25 Mar 2023 11:43:45 +0000 [thread overview]
Message-ID: <CALDnm53AT_3co3161z03bFi+7R=25mmi+poUxmSHRb+-ZJi6Gg@mail.gmail.com> (raw)
In-Reply-To: <c83ed667-06a1-80f2-cd48-8e600f9367a5@gmail.com>
On Sat, Mar 25, 2023 at 10:26 AM Herman, Géza <geza.herman@gmail.com> wrote:
>
> That's the difference. c++-ts-mode appends "{}():;,#" to
> electric-indent-chars, while c++-mode doesn't do this.
>
> Nevertheless, I think that the calculated intendation should be a
> correct number. Even if the user turns off electric-indent-mode, but
> dedices to call re-indenting manually for a half-written for loop, emacs
> should re-intent the line properly. At least, this specific example
> works OK with c++-mode.
>
> (note that I understand that this problem is not trivial, tree
> sitter/emacs may get confused if the buffer cannot be properly parsed)
There can be no "correct" indentation in a buffer with an invalid state.
But there are heuristics. Here, it can be argued that c++-mode's
heuristics are better.
Let's assume you turn off electric-indent-mode. In c++-mode, pressing RET
after:
int main() {
"correctly" indents the next line. In c++-ts-mode, it doesn't.
Both programs are ill-formed but you're right that after correcting
that, by say adding 'return 0; RET }', the c++-mode version of the
same program is closer to being correctly indented.
But this heuristic is not always great, so it's a stick with two ends.
Now let's take another invalid program:
int foo()
class bar { | <- cursor here
}
In c++-mode typing TAB indents the class line to the second column,
which is arguably worse than c++-ts-mode, which doesn't do anything.
That's because you may well want to work on that class and then only
remember that you need the ';' for the declaration of 'foo'.
IMO, it's a question of getting used to it in the end. And using
electric-pair-mode helps a lot, as some have pointed out.
João
next prev parent reply other threads:[~2023-03-25 11:43 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-23 20:43 bug#62412: 29.0.60; strange c++ indentation behavior with tree sitter Herman, Geza
2023-03-24 18:17 ` Yuan Fu
2023-03-24 20:04 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-25 8:53 ` João Távora
2023-03-25 10:19 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-25 10:28 ` João Távora
2023-03-25 10:26 ` Herman, Géza
2023-03-25 11:43 ` João Távora [this message]
2023-03-25 13:48 ` Herman, Géza
2023-03-25 16:23 ` João Távora
2023-03-25 17:41 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-12 0:03 ` Stefan Kangas
2023-03-25 17:47 ` Herman, Géza
2023-03-25 17:53 ` João Távora
2023-03-26 13:54 ` Herman, Géza
2023-03-26 13:25 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CALDnm53AT_3co3161z03bFi+7R=25mmi+poUxmSHRb+-ZJi6Gg@mail.gmail.com' \
--to=joaotavora@gmail.com \
--cc=62412@debbugs.gnu.org \
--cc=Herman@debbugs.gnu.org \
--cc=casouri@gmail.com \
--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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).