From: Theodor Thornhill Date: Sun, 31 Mar 2024 08:43:44 +0000 (+0200) Subject: Make object init more robust (bug#69571) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7600aa6fe87d0915f7b99a3e9d99e12a1b831fda;p=emacs.git Make object init more robust (bug#69571) * lisp/progmodes/csharp-mode.el (csharp-guess-basic-syntax): Make the regex same as before, but conditionally check other heuristics rather than crazy regex shenanigans. (cherry picked from commit 910ea5f1e55793fa29292730a59397867b4e868f) --- diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el index 9782eb443f2..10ac73d9691 100644 --- a/lisp/progmodes/csharp-mode.el +++ b/lisp/progmodes/csharp-mode.el @@ -500,7 +500,15 @@ compilation and evaluation time conflicts." ;; Also, deal with the possible end of line obscured by a ;; trailing comment. (goto-char (c-point 'iopl)) - (looking-at "^[^//]*new[^//]*;$"))) + (when (looking-at-p ".*new.*") + (if (re-search-forward ";" (pos-eol) t 1) + ;; If the ';' is inside a comment, the statement hasn't + ;; likely ended, so we should accept as object init. + ;; Example: + ;; var x = new // This should return true ; + ;; var x = new(); // This should return false ; + (nth 4 (syntax-ppss (point))) + t)))) ;; Line should not already be terminated (save-excursion (goto-char (c-point 'eopl)) diff --git a/test/lisp/progmodes/csharp-mode-resources/indent.erts b/test/lisp/progmodes/csharp-mode-resources/indent.erts index a676ecc9728..e03ba80d709 100644 --- a/test/lisp/progmodes/csharp-mode-resources/indent.erts +++ b/test/lisp/progmodes/csharp-mode-resources/indent.erts @@ -16,4 +16,82 @@ public class Foo { } // [2] } } + +public class Foo { + void Bar () { + var x = new X(); + for (;;) { + x(); + } // [2] + } +} + +public class Foo { + void Bar () { + var x = new X() + { + var b = 3; + }; + for (;;) { + x(); + } // [2] + } +} + +public class Foo { + void Bar () { + var x = new X() // Hello + { + var b = 3; + }; + for (;;) { + x(); + } // [2] + } +} + +public class Foo { + void Bar () { + var x = new X() // Hello ; + { + var b = 3; + }; + for (;;) { + x(); + } // [2] + } +} + +public class Foo { + void Bar () { + var x = new X // Hello ; + { + var b = 3; + }; + for (;;) { + x(); + } // [2] + } +} + +public class Foo { + void Bar () { + var x = new X(); // Hello ; + for (;;) { + x(); + } // [2] + } +} + +public class Foo +{ + void Bar () + { + var x = new X(); // Hello ; + for (;;) + { + x(); + } // [2] + } +} =-=-=