unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ergus via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Theodor Thornhill <theo@thornhill.no>
Cc: jostein@kjonigsen.net, 61541@debbugs.gnu.org
Subject: bug#61541: 30.0.50; Wrong indentarion in csharp-mode
Date: Sun, 19 Feb 2023 02:58:42 +0100	[thread overview]
Message-ID: <20230219015842.rp2m7n5df4fcp2ug@Ergus> (raw)
In-Reply-To: <87edqn6exf.fsf@thornhill.no>

Hi Theo:

I think this works... I will try it a bit more tomorrow.

Thanks,
Ergus

On Sat, Feb 18, 2023 at 12:38:20AM +0100, Theodor Thornhill wrote:
>Ergus <spacibba@aol.com> writes:
>
>> On Fri, Feb 17, 2023 at 10:06:50PM +0100, Jostein Kj�nigsen wrote:
>>>2/17/23 20:28, Theodor Thornhill wrote:
>>>>Ergus <spacibba@aol.com> writes:
>>>>
>>>>>Hi:
>>>>>
>>>>>I just found that this indentations are wrong in csharp mode:
>>>>>
>>>>>// wrong
>>>>>new myNamespace.myClass
>>>>>{
>>>>>     Name1 = x.Value, // defun-block-intro
>>>>>	var2 = 2     // statement-cont
>>>>>	}            // statement-cont
>>>>>
>>>>>
>>>>>The problem seems to be related with the dot (.) in the new, because
>>>>>this variant indents correctly:
>>>>>
>>>>>// right
>>>>>new myClass
>>>>>{
>>>>>     Name1 = x.Value,   // brace-list-intro
>>>>>     var2 = 2           // brace-list-entry
>>>>>}                      // brace-list-close
>>>>>
>>>>>
>>>>>csharp-ts-mode is doing it right BTW.
>>>>>
>>>>Hi!
>>>>
>>>>Yeah, this is one of the harder issues iirc, and one of the ones that
>>>>made us move to tree-sitter in csharp-mode in the first place.
>>>>
>>>>What do you think Jostein?
>>>>
>>>>Patches welcome!
>>>>
>>>>Theo
>>>>
>>>First of all: Thanks for a detailed bug-report.
>>>
>>>Then for the bad news: I may be missing something here. I'm on the
>>>latest revision of the emacs-29 branch, and I really can't reproduce
>>>at all.
>>>
>>>I've tried typing out the concrete code-samples above, and I've tried
>>>copy-pasting them.
>>>
>>>No matter what I do, I cannot reproduce the behaviour outlined above.
>>>
>>>Ergus: Could you come up with a even more complete example?
>>>
>>>I mean... If I can't reproduce, I definitely won't be able to come up
>>>with a patch.
>>>
>>>--
>>>Jostein
>>>
>>
>> Hi Jostein:
>>
>> I just do:
>>
>> emacs -Q /tmp/main.cs
>>
>> Then pasted (or write) the code snippet shown in the example, and
>> re-indent the buffer:
>>
>> I get this:
>>
>> new myNamespace.myClass
>> {
>>      Name1 = 1,
>>          Name2 =2
>>          }
>>
>> Exactly like in the example C-c C-o shows the same than in the
>> example. Even the fontification is wrong.
>>
>> If I remove the dot like this myNamespacemyClass the fontification and
>> indentation is fixed immediately.
>>
>> I am using the master branch (emacs-version = 30.0.50) tomorrow I can
>> try to reproduce the issue on emacs-29 branch, but I have to build it.
>>
>> Best,
>> Ergus
>
>
>Try this, Ergus and Jostein. What do you think?
>
>diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
>index b6b842d7fd..293a910081 100644
>--- a/lisp/progmodes/csharp-mode.el
>+++ b/lisp/progmodes/csharp-mode.el
>@@ -474,28 +474,37 @@ csharp-guess-basic-syntax
>          (and (eq (char-before) ?\])
>               (not (eq (char-after) ?\;))))))
>     `((annotation-top-cont ,(c-point 'iopl))))
>-
>    ((and
>      ;; Heuristics to find object initializers
>      (save-excursion
>        ;; Next non-whitespace character should be '{'
>        (goto-char (c-point 'boi))
>-       (eq (char-after) ?{))
>-     (save-excursion
>-       ;; 'new' should be part of the line
>-       (goto-char (c-point 'iopl))
>-       (looking-at ".*new.*"))
>+       (unless (eq (char-after) ?{)
>+         (backward-up-list 1 t t))
>+       (save-excursion
>+         ;; 'new' should be part of the line
>+         (goto-char (c-point 'iopl))
>+         (looking-at ".*new.*")))
>      ;; Line should not already be terminated
>      (save-excursion
>        (goto-char (c-point 'eopl))
>        (or (not (eq (char-before) ?\;))
>            (not (eq (char-before) ?\{)))))
>-    (if (save-excursion
>-          ;; if we have a hanging brace on line before
>-          (goto-char (c-point 'eopl))
>-          (eq (char-before) ?\{))
>-        `((brace-list-intro ,(c-point 'iopl)))
>-      `((block-open) (statement ,(c-point 'iopl)))))
>+    (cond
>+     ((save-excursion
>+        ;; if we have a hanging brace on line before
>+        (goto-char (c-point 'eopl))
>+        (eq (char-before) ?\{))
>+      `((brace-list-intro ,(c-point 'iopl))))
>+     ((save-excursion
>+        ;; if we have a hanging brace on line before
>+        (goto-char (c-point 'boi))
>+        (and (eq (char-after) ?\})
>+             `((brace-list-close ,(save-excursion
>+                                    (backward-up-list 1 t t)
>+                                    (point)))))))
>+     (t
>+      `((block-open) (statement ,(c-point 'iopl))))))
>    (t
>     (apply orig-fun args))))
>





  reply	other threads:[~2023-02-19  1:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87k00i7hko.fsf.ref@aol.com>
2023-02-15 21:19 ` bug#61541: 30.0.50; Wrong indentarion in csharp-mode Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-17 19:28   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-17 21:06     ` Jostein Kjønigsen
2023-02-17 21:43       ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-17 23:38         ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-19  1:58           ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-09-04 19:45           ` stefankangas

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=20230219015842.rp2m7n5df4fcp2ug@Ergus \
    --to=bug-gnu-emacs@gnu.org \
    --cc=61541@debbugs.gnu.org \
    --cc=jostein@kjonigsen.net \
    --cc=spacibba@aol.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).