Skip to content

Commit 95ff004

Browse files
committed
Fix indentation of closures inside condition-list
Example: ```swift if foo( a: { } ) { } if a == [ b { } ] { } ```
1 parent abbd06e commit 95ff004

File tree

2 files changed

+123
-1
lines changed

2 files changed

+123
-1
lines changed

swift-mode-indent.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ This function is also used for close-curly-brace."
921921
(save-excursion
922922
(goto-char (swift-mode:token:end
923923
(swift-mode:backward-sexps-until
924-
swift-mode:statement-parent-tokens)))
924+
(append swift-mode:statement-parent-tokens '(\( \[)))))
925925
(setq next-token (swift-mode:forward-token-or-list))
926926
(while (<= (point) pos)
927927
(cond

test/swift-files/indent/statements.swift

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,24 @@ for
304304
}
305305

306306

307+
for
308+
x in foo(
309+
a: {
310+
b()
311+
}
312+
)
313+
{
314+
}
315+
316+
for
317+
x in [
318+
a {
319+
b()
320+
}
321+
]
322+
{
323+
}
324+
307325
// While statements
308326

309327
while foo
@@ -394,6 +412,30 @@ while let
394412
foo()
395413
}
396414

415+
416+
while
417+
let foo = bar(
418+
a: {
419+
b()
420+
}
421+
)
422+
{
423+
}
424+
425+
while
426+
foo(
427+
a: {
428+
b()
429+
}
430+
),
431+
a == [
432+
b {
433+
c()
434+
}
435+
]
436+
{
437+
}
438+
397439
// Repeat-while statements
398440

399441
repeat {
@@ -428,6 +470,20 @@ repeat {
428470
.bar()
429471
.baz()
430472

473+
repeat {
474+
} while foo(
475+
a: {
476+
b()
477+
}
478+
)
479+
480+
repeat {
481+
} while a == [
482+
b {
483+
c()
484+
}
485+
]
486+
431487
// If statement
432488

433489
if x
@@ -514,6 +570,33 @@ if foo.bar +++ {
514570
foo()
515571
}
516572

573+
if
574+
foo(
575+
a: {
576+
b()
577+
}
578+
),
579+
a == [
580+
b {
581+
c()
582+
}
583+
]
584+
{
585+
}
586+
587+
if
588+
let foo = bar(
589+
a: {
590+
b()
591+
}
592+
),
593+
let foo = bar(
594+
a: {
595+
b()
596+
}
597+
)
598+
{
599+
}
517600

518601
// Guard statement
519602

@@ -598,6 +681,29 @@ guard
598681
foo()
599682
}
600683

684+
guard
685+
let foo = bar(
686+
a: {
687+
b()
688+
}
689+
)
690+
else {
691+
}
692+
693+
guard
694+
foo(
695+
a: {
696+
b()
697+
}
698+
),
699+
a == [
700+
b {
701+
c()
702+
}
703+
]
704+
else {
705+
}
706+
601707
// Switch statement
602708

603709
switch foo
@@ -939,7 +1045,23 @@ switch foo {
9391045

9401046
// swift-mode:test:eval (setq-local swift-mode:switch-case-offset 0)
9411047

1048+
switch
1049+
foo(
1050+
a: {
1051+
b()
1052+
}
1053+
)
1054+
{
1055+
}
9421056

1057+
switch
1058+
[
1059+
a {
1060+
b()
1061+
}
1062+
]
1063+
{
1064+
}
9431065

9441066
// Labeled statements
9451067

0 commit comments

Comments
 (0)