From: Dmitry Gutov <dmitry@gutov.dev>
To: "Daniel Martín" <mardani29@yahoo.es>, 62717@debbugs.gnu.org
Cc: Yuan Fu <casouri@gmail.com>, Theodor Thornhill <theo@thornhill.no>
Subject: bug#62717: 29.0.60; c-ts-mode does not indent the first line in a function after RET
Date: Sat, 8 Apr 2023 04:57:53 +0300 [thread overview]
Message-ID: <ab20b112-057f-4dcd-268f-4095180fad2a@gutov.dev> (raw)
In-Reply-To: <m1355ba2xr.fsf@yahoo.es>
On 07/04/2023 22:48, Daniel Martín via Bug reports for GNU Emacs, the
Swiss army knife of text editors wrote:
> emacs -Q
> C-x b sample.c RET
> M-x c-ts-mode RET
>
> int main() {
>
> If I press RET at the end of the line, the point is not indented.
>
> The Tree-sitter tree for the code is
>
> (translation_unit
> (function_definition type: (primitive_type)
> declarator:
> (function_declarator declarator: (identifier)
> parameters: (parameter_list ( )))
> body: (compound_statement { })))
>
> If I insert a closing bracket, that is:
>
> int main() {
> }
>
> The newline indents correctly. The Tree-sitter tree is now
>
> (function_definition type: (primitive_type)
> declarator:
> (function_declarator declarator: (identifier)
> parameters: (parameter_list ( )))
> body: (compound_statement { }))
>
> It seems that Tree-sitter parses both code snippets without errors and
> Emacs should automatically indent after RET in the first case.
I've looked at what nvim-treesitter does for indentation, and at least
one of the steps looks like this:
https://github.com/nvim-treesitter/nvim-treesitter/blob/584ccea56e2d37b31ba292da2b539e1a4bb411ca/lua/nvim-treesitter/indent.lua#L129-L134
If the current line is empty, look at the end of the previous line and
compute based on the node there.
I'm not sure how this meshes with the fact that tree-sitter inserts a
"virtual" closer node at the end of the previous line, but the approach
is worth examining.
Daniel, you posted about testing nvim-treesitter with several scenarios.
Does it do the right thing with this one?
next prev parent reply other threads:[~2023-04-08 1:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <m1355ba2xr.fsf.ref@yahoo.es>
2023-04-07 19:48 ` bug#62717: 29.0.60; c-ts-mode does not indent the first line in a function after RET Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-08 1:57 ` Dmitry Gutov [this message]
2023-04-08 18:37 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-09 0:20 ` Dmitry Gutov
2023-04-09 5:19 ` Eli Zaretskii
2023-04-09 16:33 ` Dmitry Gutov
2023-04-09 17:37 ` Eli Zaretskii
2023-04-10 0:36 ` Dmitry Gutov
2023-04-10 21:04 ` Yuan Fu
2023-04-09 11:05 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-09 16:30 ` Dmitry Gutov
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=ab20b112-057f-4dcd-268f-4095180fad2a@gutov.dev \
--to=dmitry@gutov.dev \
--cc=62717@debbugs.gnu.org \
--cc=casouri@gmail.com \
--cc=mardani29@yahoo.es \
--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).