]> git.eshelyaron.com Git - emacs.git/commitdiff
Make object init more robust (bug#69571)
authorTheodor Thornhill <theo@thornhill.no>
Sun, 31 Mar 2024 08:43:44 +0000 (10:43 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 7 Apr 2024 16:33:14 +0000 (18:33 +0200)
* 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)

lisp/progmodes/csharp-mode.el
test/lisp/progmodes/csharp-mode-resources/indent.erts

index 9782eb443f2f234c1e5062a2645809cb51d5a5c5..10ac73d9691ab62693f8b1fc93839a55ca504120 100644 (file)
@@ -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))
index a676ecc972883e3c8a334fa14a5b7f7e5525b2ce..e03ba80d709ea065c56b86822c29c1a6505e0bf3 100644 (file)
@@ -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]
+    }
+}
 =-=-=