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

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

[elpa] externals/csharp-mode bd881cd 303/459: Add a little better heuris


From: ELPA Syncer
Subject: [elpa] externals/csharp-mode bd881cd 303/459: Add a little better heuristics to vsemi-p
Date: Sun, 22 Aug 2021 13:59:49 -0400 (EDT)

branch: externals/csharp-mode
commit bd881cd345652e3fbd28d05a1109c52483c287e7
Author: Theodor Thornhill <theodor.thornhill@frende.no>
Commit: Theodor Thornhill <theodor.thornhill@frende.no>

    Add a little better heuristics to vsemi-p
    
    The earlier implementation was indenting things like this:
    
    resource.DoStuff(new Something("a", "b"));
        resource.DoStuff(new Something("c", "d"));
    
    Now we get this behaviour:
    resource.DoStuff(new Something("a", "b"));
    resource.DoStuff(new Something("c", "d"));
    
    And still keep the csharp specific object inits like these:
    
    yield return new Foo<bar>
    {
        a,
        b,
        c
    };
    
    new Foo<Bar>
    {
        a,
        b,
        c
    };
---
 csharp-mode.el | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/csharp-mode.el b/csharp-mode.el
index f488554..bc8ae8a 100644
--- a/csharp-mode.el
+++ b/csharp-mode.el
@@ -196,17 +196,24 @@
 
 (defun csharp-at-vsemi-p (&optional pos)
   (if pos (goto-char pos))
-  (or (and (eq (char-before) ?\])
-           (save-excursion
-             (c-backward-sexp)
-             (looking-at "\\[")))
+  (or (and
+       ;; Heuristics to find attributes
+       (eq (char-before) ?\])
+       (save-excursion
+         (c-backward-sexp)
+         (looking-at "\\[")))
       (and
+       ;; Heuristics to find object initializers
        (save-excursion
+         ;; Next non-whitespace character should be '{'
          (c-forward-syntactic-ws)
          (char-after ?{))
        (save-excursion
+         ;; 'new' should be part of the line
          (beginning-of-line)
-         (looking-at ".*new.*")))))
+         (looking-at ".*new.*"))
+       ;; Line should not already be terminated
+       (not (eq (char-after) ?\;)))))
 
 (c-lang-defconst c-at-vsemi-p-fn
   csharp 'csharp-at-vsemi-p)



reply via email to

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