branch: externals/csharp-mode commit 8ab3cc8d0143c878cab0f3424916cd9c0edc3217 Author: Jostein Kjønigsen <jost...@kjonigsen.net> Commit: Jostein Kjønigsen <jost...@kjonigsen.net>
Dirty hack to force type-initializer indentation. This potentially fixes https://github.com/josteink/csharp-mode/issues/94. --- csharp-mode.el | 15 +++++++++++---- test-files/indentation-tests.cs | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/csharp-mode.el b/csharp-mode.el index ffce5f7..25a8aaa 100644 --- a/csharp-mode.el +++ b/csharp-mode.el @@ -299,6 +299,7 @@ ;; - Fix fontification of using and namespace-statements with ;; underscores in them. ;; - Derive csharp-mode-map from prog-mode-map. +;; - Fixes for indentation for many kinds of type-initializers. ;; ;;; Code: @@ -2611,13 +2612,19 @@ are the string substitutions (see `format')." (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! + ;; type-initializers are not properly detected and + ;; indented unless we help out. (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) - (- bracepos 2)))) + (or + (not (c-crosses-statement-barrier-p (point) + (- bracepos 2))) + ;; this little hack (combined with the regexp-check above) + ;; fixes indentation for all type-initializers. + (c-major-mode-is 'csharp-mode))) (point))))) ;; this will pick up array/aggregate init lists, even if they are nested. diff --git a/test-files/indentation-tests.cs b/test-files/indentation-tests.cs index c0c4d8f..199f936 100644 --- a/test-files/indentation-tests.cs +++ b/test-files/indentation-tests.cs @@ -134,6 +134,27 @@ namespace Boo May = "Yay" }; + // extra test-cases + + new Foo{ + a, + b, + c + }; + + new Foo { + a, + b, + c + }; + + new Foo + { + a, + b, + c + }; + using (test) { System.Console.WriteLine("boo");