emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/csharp-mode 4516a18 223/459: Fix indentation of generic


From: ELPA Syncer
Subject: [elpa] externals/csharp-mode 4516a18 223/459: Fix indentation of generic type-initializers.
Date: Sun, 22 Aug 2021 13:59:31 -0400 (EDT)

branch: externals/csharp-mode
commit 4516a18c0dd1797a2d1eb2ae3069c0e16efa14a7
Author: Jostein Kjønigsen <jostein@kjonigsen.net>
Commit: Jostein Kjønigsen <jostein@kjonigsen.net>

    Fix indentation of generic type-initializers.
    
    This commit should address
    https://github.com/josteink/csharp-mode/issues/95.
---
 csharp-mode.el                  | 31 ++++++++++++++++++++-----------
 test-files/indentation-tests.cs | 30 ++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/csharp-mode.el b/csharp-mode.el
index ae1e649..1d97d16 100644
--- a/csharp-mode.el
+++ b/csharp-mode.el
@@ -412,6 +412,12 @@ Most other csharp functions are not instrumented.
   ;; constants used in this module
   ;; ==================================================================
 
+  (defconst csharp-type-initializer-statement-re
+    (concat
+     "\\<new[ \t\n\r\f\v]+"
+     "\\([[:alpha:]_][[:alnum:]_<>\\.]*\\)")
+    "Regexp that captures a type-initializer statement in C#")
+
   (defconst csharp-enum-decl-re
     (concat
      "\\<enum[ \t\n\r\f\v]+"
@@ -423,8 +429,7 @@ Most other csharp functions are not instrumented.
        (list "sbyte" "byte" "short" "ushort" "int" "uint" "long" "ulong"))
      "\\)"
      "\\)?")
-    "Regex that captures an enum declaration in C#"
-    )
+    "Regex that captures an enum declaration in C#")
 
   ;; ==================================================================
 
@@ -2596,16 +2601,20 @@ are the string substitutions (see `format')."
                         (c-safe (c-forward-sexp -1))
                         (looking-at c-brace-list-key))
 
-                      ;; dinoch Thu, 22 Apr 2010  18:20
-                      ;; ============================================
-                      ;; looking enum Foo : int
-                      ;; means this is a brace list, so, return nil,
-                      ;; implying NOT looking-at-inexpr-block
-
                       (and (c-major-mode-is 'csharp-mode)
-                           (progn
-                             (c-safe (c-forward-sexp -1))
-                             (looking-at csharp-enum-decl-re))))
+                           (or
+                            ;; dinoch Thu, 22 Apr 2010  18:20
+                            ;; ============================================
+                            ;; looking enum Foo : int
+                            ;; means this is a brace list, so, return nil,
+                            ;; implying NOT looking-at-inexpr-block
+                            (progn
+                              (c-safe (c-forward-sexp -1))
+                              (looking-at csharp-enum-decl-re))
+
+                            ;; no need to forward when looking here, because 
enum
+                            ;; check already did it!
+                            (looking-at 
csharp-type-initializer-statement-re))))
 
                   (setq bracepos (c-down-list-forward (point)))
                   (not (c-crosses-statement-barrier-p (point)
diff --git a/test-files/indentation-tests.cs b/test-files/indentation-tests.cs
index 32a93c8..96b17c3 100644
--- a/test-files/indentation-tests.cs
+++ b/test-files/indentation-tests.cs
@@ -48,6 +48,36 @@ namespace Boo
                 with = new prop(),
             };
 
+            // test-cases for type initializer indetation issue:
+            // https://github.com/josteink/csharp-mode/issues/95
+            var x_gen = new Foo<bar>
+            {
+                a,
+                b,
+                c
+            };
+
+            return new Foo<bar>
+            {
+                a,
+                b,
+                c
+            };
+
+            yield return new Foo<bar>
+            {
+                a,
+                b,
+                c
+            };
+
+            new Foo<Bar>
+            {
+                a,
+                b,
+                c
+            };
+
             var array1 = new ArrayList
             {
                 1, 2, 3, 4, 5



reply via email to

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