Subject: Re: bug#62717: 29.0.60; c-ts-mode does not indent the first line in a function after RET

From: Dmitry Gutov <[email-masked]>
Date: Mon, 10 Apr 2023 03:36:35 +0300

On 09/04/2023 20:37, Eli Zaretskii wrote:
>> Date: Sun, 9 Apr 2023 19:33:20 +0300
>> Cc:[email-masked],[email-masked],[email-masked],
>>   [email-masked],[email-masked],[email-masked]
>> From: Dmitry Gutov<[email-masked]>
>>
>>> If the patch solves some of the problems, passes the test suite, and
>>> doesn't introduce any regressions you see, I think you should install
>>> it (unless someone here objects).
>> With this kind of change, it's hard to judge regression potential in
>> advance. I don't really write C/C++ myself with any regularity. And our
>> test suite doesn't really work incomplete parse trees, I think.
>>
>> So if we want this in emacs-29, I think someone interested should try
>> running with this patch applied, at least for a little bit. Maybe just
>> wait for a couple of days, if Daniel is testing it already.
> The pretest will be out VSN.  Maybe you should install this, and we
> can then back it out if people complain.  FWIW, I intend to use only
> c-ts-mode when I the pretest is out, so if there are regressions, I
> think I will see it soon enough.

Okay, SGTM. I've pushed the patch to emacs-29.

Note that there remains a bunch of more complex cases that don't indent 
well while there are no closing braces in the buffer.

Examples:

   int main() {
     for (;;) {<RET>

(including every variation where some chars are deleted from the end of 
the second line), or

   int main() {
     if (2 == 2)<RET>

or

   int main() {
     if (2 == 2)
       foo();
     else<RET>

etc.

Enumerating every such case to create a special indentation logic seems 
a little tiring. Though if 2-3 of them are determined to be the most 
important ones, that might be doable.

But again, as long as there is at least one '}' after point, though, 
indentation in all of these cases improves. Though perhaps not ideally 
sometimes (e.g. for parenless if/else clauses the indentation starts out 
without the additional level).

Anyway, the case described in the report should now be working. Whether 
to close the bug or not, it's up to you and other interested parties.