emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 910ea5f1e55: Make object init more robust (bug#69571)


From: Theodor Thornhill
Subject: emacs-29 910ea5f1e55: Make object init more robust (bug#69571)
Date: Sun, 31 Mar 2024 04:45:23 -0400 (EDT)

branch: emacs-29
commit 910ea5f1e55793fa29292730a59397867b4e868f
Author: Theodor Thornhill <theo@thornhill.no>
Commit: Theodor Thornhill <theo@thornhill.no>

    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.
---
 lisp/progmodes/csharp-mode.el                      | 10 ++-
 .../progmodes/csharp-mode-resources/indent.erts    | 78 ++++++++++++++++++++++
 2 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 2740d34e3b2..607360f737a 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]
+    }
+}
 =-=-=



reply via email to

[Prev in Thread] Current Thread [Next in Thread]