branch: elpa/swift-mode commit 2d478bf82e6e5668027ec73db1cc8f1ea879b702 Merge: 2eb3952 5e3ab8c Author: Bozhidar Batsov <bozhidar.bat...@gmail.com> Commit: Bozhidar Batsov <bozhidar.bat...@gmail.com>
Merge pull request #46 from ap4y/multiline_op_statemenets Multiline op statemenets --- swift-mode.el | 16 +++++++++++----- test/indentation-tests.el | 27 +++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/swift-mode.el b/swift-mode.el index 370f78b..f16fbe9 100644 --- a/swift-mode.el +++ b/swift-mode.el @@ -53,8 +53,8 @@ :group 'swift :type 'integerp) -(defcustom swift-indent-multiline-dot-offset 2 - "Defines the indentation offset for for multiline dot statement." +(defcustom swift-indent-multiline-statement-offset 2 + "Defines the indentation offset for for multiline statements." :group 'swift :type 'integerp :package-version '(swift-mode "0.3.0")) @@ -121,7 +121,7 @@ ("for" for-head "{" insts "}") ("while" exp "{" insts "}")) - (dot-exp (exp "." exp)) + (dot-exp (id "." id)) (method-call (dot-exp "(" method-args ")")) (method-args (method-arg) (method-arg "," method-arg)) @@ -272,13 +272,19 @@ (if (smie-rule-parent-p "case" "default") (smie-rule-parent swift-indent-offset))) - ;; Apply swift-indent-multiline-dot-offset only if + ;; Apply swift-indent-multiline-statement-offset only if ;; - dot is followed by newline, or ;; - have at least one whitespace character before dot (`(:before . ".") (if (or (looking-at "[.][\n]") (looking-back "[ \t\n]" 1 t)) - (smie-rule-parent swift-indent-multiline-dot-offset))) + (smie-rule-parent swift-indent-multiline-statement-offset))) + + ;; Apply swift-indent-multiline-statement-offset if + ;; operator is the last symbol on the line + (`(:before . "OP") + (if (looking-at ".[\n]") + (smie-rule-parent swift-indent-multiline-statement-offset))) (`(:before . "if") (if (smie-rule-prev-p "else") diff --git a/test/indentation-tests.el b/test/indentation-tests.el index c4c9e2a..f958732 100644 --- a/test/indentation-tests.el +++ b/test/indentation-tests.el @@ -58,7 +58,7 @@ values of customisable variables." ;; Bind customisable vars to default values for tests. (swift-indent-offset 4) (swift-indent-switch-case-offset 0) - (swift-indent-multiline-dot-offset 2) + (swift-indent-multiline-statement-offset 2) ,@var-bindings) (with-temp-buffer (insert ,before) @@ -811,6 +811,15 @@ let json_ary = NSJSONSerialization |.JSONObjectWithData(data, options: nil, error: &json_err) as NSArray ") +(check-indentation indents-multiline-expressions/8 + " +let options = NSRegularExpressionOptions.CaseInsensitive & +|NSRegularExpressionOptions.DotMatchesLineSeparators +" " +let options = NSRegularExpressionOptions.CaseInsensitive & + |NSRegularExpressionOptions.DotMatchesLineSeparators +") + (check-indentation indents-multiline-expressions-to-user-defined-offset/1 " NSNotificationCenter.defaultCenter(). @@ -819,7 +828,7 @@ NSNotificationCenter.defaultCenter(). NSNotificationCenter.defaultCenter(). |postNotificationName(foo, object: nil) " -((swift-indent-multiline-dot-offset 4))) +((swift-indent-multiline-statement-offset 4))) (check-indentation indents-multiline-expressions-to-user-defined-offset/2 " @@ -829,7 +838,7 @@ NSNotificationCenter.defaultCenter() NSNotificationCenter.defaultCenter() |.postNotificationName(foo, object: nil) " -((swift-indent-multiline-dot-offset 4))) +((swift-indent-multiline-statement-offset 4))) (check-indentation indents-multiline-expressions-to-user-defined-offset/3 " @@ -839,7 +848,17 @@ let json_ary = NSJSONSerialization let json_ary = NSJSONSerialization |.JSONObjectWithData(data, options: nil, error: &json_err) as NSArray " -((swift-indent-multiline-dot-offset 4))) +((swift-indent-multiline-statement-offset 4))) + +(check-indentation indents-multiline-expressions-to-user-defined-offset/4 + " +let options = NSRegularExpressionOptions.CaseInsensitive & +|NSRegularExpressionOptions.DotMatchesLineSeparators +" " +let options = NSRegularExpressionOptions.CaseInsensitive & + |NSRegularExpressionOptions.DotMatchesLineSeparators +" +((swift-indent-multiline-statement-offset 4))) (check-indentation indents-type-annotations/1 "