branch: externals/csharp-mode commit bd881cd345652e3fbd28d05a1109c52483c287e7 Author: Theodor Thornhill <theodor.thornh...@frende.no> Commit: Theodor Thornhill <theodor.thornh...@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)