GNU bug report logs -
#62717
29.0.60; c-ts-mode does not indent the first line in a function after RET
Previous Next
Full log
Message #23 received at 62717 <at> debbugs.gnu.org (full text, mbox):
On 09/04/2023 14:05, Daniel Martín wrote:
> Dmitry Gutov <dmitry <at> gutov.dev> writes:
>
>>
>> I'm not sure, though, what is the big deal with adding the top-level
>> function's closing curly first thing before writing the body (after
>> that the parser starts working much better), so as far as I'm
>> concerned this patch is very optional. It does add some complexity,
>> after all.
>
> I think this problem also affects languages without curly braces like
> Ruby or Python.
Python -- no, because it doesn't have closers. And its indentation
doesn't use tree-sitter anyway.
> For example, if I insert this Ruby code in a buffer with ruby-ts-mode
> enabled
>
> def sample RET
>
> The newline is not indented, but it is indented in ruby-mode.
Right. I mentioned that in the previous email: a fix for ruby-ts-mode
will involve a similar (but slightly different) advice together with a
new indentation rule. I'm not quite certain yet we want to go there,
because a top-level function is more rare in Ruby than in C/C++. And,
again, as soon as there is at least once 'end' below the current line in
the buffer, things start working much better. The user can either type
is manually, or use ruby-end-mode.
>> Adding Alan and Joao, who were interested in this scenario as well.
>>
>> diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
>> index 981c7766375..9aaa8b32c73 100644
>> --- a/lisp/progmodes/c-ts-mode.el
>> +++ b/lisp/progmodes/c-ts-mode.el
>
> Thanks for the patch. It works correctly and the existing c-ts-mode
> tests pass. I suggest adding a test to prevent regressions:
>
> diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
> index 5cdefe2122c..221b3d809af 100644
> --- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
> +++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
> @@ -464,3 +464,17 @@ main (void)
> |
> }
> =-=-=
> +
> +Name: Empty Line (Block Start)
> +
> +=-=
> +int
> +main (void)
> +{
> +|
> +=-=
> +int
> +main (void)
> +{
> + |
> +=-=-=
Good idea, thanks.
This bug report was last modified 2 years and 66 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.