branch: elpa/swift-mode
commit 95ff0041370660e839ed06aa92330694d8590d62
Author: taku0 <[email protected]>
Commit: taku0 <[email protected]>
Fix indentation of closures inside condition-list
Example:
```swift
if
foo(
a: {
}
)
{
}
if
a == [
b {
}
]
{
}
```
---
swift-mode-indent.el | 2 +-
test/swift-files/indent/statements.swift | 122 +++++++++++++++++++++++++++++++
2 files changed, 123 insertions(+), 1 deletion(-)
diff --git a/swift-mode-indent.el b/swift-mode-indent.el
index a5ae4a2..ea898c0 100644
--- a/swift-mode-indent.el
+++ b/swift-mode-indent.el
@@ -921,7 +921,7 @@ This function is also used for close-curly-brace."
(save-excursion
(goto-char (swift-mode:token:end
(swift-mode:backward-sexps-until
- swift-mode:statement-parent-tokens)))
+ (append swift-mode:statement-parent-tokens '(\( \[)))))
(setq next-token (swift-mode:forward-token-or-list))
(while (<= (point) pos)
(cond
diff --git a/test/swift-files/indent/statements.swift
b/test/swift-files/indent/statements.swift
index 87bdf65..a58cec8 100644
--- a/test/swift-files/indent/statements.swift
+++ b/test/swift-files/indent/statements.swift
@@ -304,6 +304,24 @@ for
}
+for
+ x in foo(
+ a: {
+ b()
+ }
+ )
+{
+}
+
+for
+ x in [
+ a {
+ b()
+ }
+ ]
+{
+}
+
// While statements
while foo
@@ -394,6 +412,30 @@ while let
foo()
}
+
+while
+ let foo = bar(
+ a: {
+ b()
+ }
+ )
+{
+}
+
+while
+ foo(
+ a: {
+ b()
+ }
+ ),
+ a == [
+ b {
+ c()
+ }
+ ]
+{
+}
+
// Repeat-while statements
repeat {
@@ -428,6 +470,20 @@ repeat {
.bar()
.baz()
+repeat {
+} while foo(
+ a: {
+ b()
+ }
+ )
+
+repeat {
+} while a == [
+ b {
+ c()
+ }
+ ]
+
// If statement
if x
@@ -514,6 +570,33 @@ if foo.bar +++ {
foo()
}
+if
+ foo(
+ a: {
+ b()
+ }
+ ),
+ a == [
+ b {
+ c()
+ }
+ ]
+{
+}
+
+if
+ let foo = bar(
+ a: {
+ b()
+ }
+ ),
+ let foo = bar(
+ a: {
+ b()
+ }
+ )
+{
+}
// Guard statement
@@ -598,6 +681,29 @@ guard
foo()
}
+guard
+ let foo = bar(
+ a: {
+ b()
+ }
+ )
+else {
+}
+
+guard
+ foo(
+ a: {
+ b()
+ }
+ ),
+ a == [
+ b {
+ c()
+ }
+ ]
+else {
+}
+
// Switch statement
switch foo
@@ -939,7 +1045,23 @@ switch foo {
// swift-mode:test:eval (setq-local swift-mode:switch-case-offset 0)
+switch
+ foo(
+ a: {
+ b()
+ }
+ )
+{
+}
+switch
+ [
+ a {
+ b()
+ }
+ ]
+{
+}
// Labeled statements