Yeah - i can just write something to make sure there is a semi on line end and not inside a comment. Not a huge issue at all, I was just looking for some function or convention i don't know about.

I'll fix it :)

On Mar 16, 2024 18:01, Dmitry Gutov <dmitry@gutov.dev> wrote:

On 16/03/2024 13:19, Eli Zaretskii wrote:
> Ping!  Yuan, could help Theo figure out what's best here?

csharp-mode is based on CC Mode, not tree-sitter.

So maybe Alan will want to comment.

(csharp-ts-mode doesn't have this problem.)

>> From: Theodor Thornhill <theo@thornhill.no>
>> Cc: 69571@debbugs.gnu.org
>> Date: Sun, 10 Mar 2024 20:21:32 +0100
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>>>> Date: Tue, 5 Mar 2024 22:09:51 +0100
>>>> From: Carlos <carlos@cvkm.cz>
>>>>
>>>> Any block starting on the line immediately below a line having the
>>>> string "new" will have its closing brace aligned with the opening one.
>>>>
>>>> See the following code:
>>>>
>>>> public class Foo {
>>>>      void Bar () {
>>>> var x = new X(); // [1]
>>>> for (;;) {
>>>>     x();
>>>> }  // [2]
>>>>      }
>>>> }
>>>>
>>>> Line [1] says "new". The closing brace in line [2] is aligned to the
>>>> opening brace.
>>>>
>>>> If you comment out the "new" (or the whole line) the problem persists.
>>>>
>>>> If you remove the "new" the problem goes away and [2] is correctly
>>>> aligned.
>>>>
>>>> If you insert a line between line [1] and the one having the opening
>>>> brace the problem goes away.
>>>
>>> Theo and Yuan, could you please look into this?
>>
>> I have a working patch for this, but I'd like to expand it to cover an
>> edge case for which I'm unable to find a good solution.  Can you suggest
>> a way around this edge case?
>>
>> Consider the provided code:
>> ```
>> public class Foo {
>>      void Bar () {
>>          var x = new X(); // [1]
>>          for (;;) {
>>              x();
>>          }  // [2]
>>      }
>> }
>> ```
>>
>> Like this, the below patch doesn't work. If you remove the first
>> comment, the patch works.
>>
>> ```
>> public class Foo {
>>      void Bar () {
>>          var x = new X();
>>          for (;;) {
>>              x();
>>          }  // [2]
>>      }
>> }
>> ```
>>
>> The reason is simple, of course. What I'm struggling with here is how to
>> best handle the case where there is a comment ending the line, possibly
>> containing a ';' itself. I've tried some variations with save-excursion
>> along with syntax-ppss to detect whether or not we're in a comment, but
>> it gets verbose and ugly. Is there some simple way to do this check in
>> Emacs, or should I just resort to making some best effort judgement call
>> here?
>>
>> Thanks,
>> Theo
>>
>> diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
>> index 7bf57bcbe21..00278e18e51 100644
>> --- a/lisp/progmodes/csharp-mode.el
>> +++ b/lisp/progmodes/csharp-mode.el
>> @@ -495,9 +495,10 @@ csharp-guess-basic-syntax
>>          (unless (eq (char-after) ?{)
>>            (ignore-errors (backward-up-list 1 t t)))
>>          (save-excursion
>> -         ;; 'new' should be part of the line
>> +         ;; 'new' should be part of the line, but should not trigger if
>> +         ;; statement has already ended, like for 'var x = new X();'.
>>            (goto-char (c-point 'iopl))
>> -         (looking-at ".*new.*")))
>> +         (looking-at ".*new.*[^;]$")))
>>        ;; Line should not already be terminated
>>        (save-excursion
>>          (goto-char (c-point 'eopl))
>>
>
>
>