branch: elpa/swift-mode commit cdf7ad49e332546f644296f7f8d41e44d6e8639c Author: ap4y <l...@pisem.net> Commit: ap4y <l...@pisem.net>
Fix indentation issues with deep nested if cluase --- swift-mode.el | 10 +++----- test/indentation-tests.el | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/swift-mode.el b/swift-mode.el index c5412fb..65796e4 100644 --- a/swift-mode.el +++ b/swift-mode.el @@ -159,14 +159,12 @@ (for-head (in-exp) (op-exp) (for-head ";" for-head)) - (conditional (exp) (let-decl)) - (if-body ("if" conditional "{" insts "}")) - (if-else-if (if-body) (if-else-if "else" if-else-if)) - (if-clause (if-else-if))) + (if-conditional (exp) (let-decl)) + (if-body ("if" if-conditional "{" insts "}")) + (if-clause (if-body) (if-body "else" if-body))) ;; Conflicts '((nonassoc "{") (assoc ",") (assoc ";") (assoc ":") (right "=")) '((assoc "in") (assoc "where") (assoc "OP")) - '((assoc "else")) '((assoc ";") (assoc "ecase")) '((assoc "case"))) @@ -359,7 +357,7 @@ (`(:before . "if") (if (smie-rule-prev-p "else") (if (smie-rule-parent-p "{") - swift-indent-offset + (smie-rule-parent swift-indent-offset) (smie-rule-parent)))) ;; Disable unnecessary default indentation for diff --git a/test/indentation-tests.el b/test/indentation-tests.el index 65897e9..2d24fa8 100644 --- a/test/indentation-tests.el +++ b/test/indentation-tests.el @@ -1677,6 +1677,68 @@ if a { } ") +(check-indentation indent-long-if-else-if/3 + " +class Foo { + func a() { + if a { + a + } else if b { + |a + } else if a { + a + } else { + a + } + } +} +" " +class Foo { + func a() { + if a { + a + } else if b { + |a + } else if a { + a + } else { + a + } + } +} +") + +(check-indentation indent-long-if-else-if/4 + " +class Foo { + func a() { + if a { + a + } else if b { + a + |} else if a { + a + } else { + a + } + } +} +" " +class Foo { + func a() { + if a { + a + } else if b { + a + |} else if a { + a + } else { + a + } + } +} +") + (check-indentation anonymous-function-as-a-argument/1 " UIView.animateWithDuration(1.0,