branch: externals/csharp-mode commit 31124dba6833a4de144ca508edb90d5adfeec209 Merge: 57bd21b 85d36e1 Author: Jostein Kjønigsen <jost...@kjonigsen.net> Commit: GitHub <nore...@github.com>
Merge pull request #156 from krzsztf/fix-lambda-indentation Fix lambda indentation #105 --- csharp-mode.el | 12 ++++++++++-- test-files/indentation-tests.cs | 20 ++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/csharp-mode.el b/csharp-mode.el index 85c7745..0fea1d1 100644 --- a/csharp-mode.el +++ b/csharp-mode.el @@ -556,6 +556,10 @@ to work properly with code that includes attributes." (t nil)) ))) +(defun csharp--at-lambda-header () + "Determines if there is lambda header at point" + (or (looking-at "([[:alnum:][:space:]_,]*)[ \t\n]*=>[ \t\n]*{") + (looking-at "[[:alnum:]_]+[ \t\n]*=>[ \t\n]*{"))) ;; ================================================================== ;; end of csharp-mode utility and feature defuns @@ -2549,7 +2553,8 @@ are the string substitutions (see `format')." (> (point) closest-lim)) (not (bobp)) (progn (backward-char) - (looking-at "[\]\).]\\|\w\\|\\s_")) + (or (looking-at "[\]\).]\\|\w\\|\\s_") + (looking-at ">"))) (c-safe (forward-char) (goto-char (scan-sexps (point) -1)))) @@ -2612,7 +2617,10 @@ are the string substitutions (see `format')." 'maybe) (setq passed-paren (char-after)) 'maybe) - 'maybe)))) + 'maybe) + + (if (csharp--at-lambda-header) + (cons 'inexpr (point)))))) (if (eq res 'maybe) (when (and c-recognize-paren-inexpr-blocks diff --git a/test-files/indentation-tests.cs b/test-files/indentation-tests.cs index 4c32a5a..8d91f78 100644 --- a/test-files/indentation-tests.cs +++ b/test-files/indentation-tests.cs @@ -162,21 +162,29 @@ namespace Boo /* Callback indentation test. */ SomeFunction(() => { - // empty. - }); + System + .Console + .WriteLine("boo"); + }); SomeFunction(() => { - // empty. + System + .Console + .WriteLine("boo"); }); SomeFunction((withParam) => { - // empty. - }); + System + .Console + .WriteLine("boo"); + }); SomeFunction((withParam) => { - // empty. + System + .Console + .WriteLine("boo"); }); }