Skip to content

Commit e65a80a

Browse files
Josh Caswelltaku0
authored andcommitted
Support full-indent for switch cases
When `swift-mode:switch-case-offset` is set equal to the basic offset, lines following a `case` inside a `switch` should still be indented. Change the offset calculation to fall back to `swift-mode:basic-offset` if the difference between the offsets is 0 (or less). Resolves #166
1 parent 7d93c75 commit e65a80a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

swift-mode-indent.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ declaration and its offset is `swift-mode:basic-offset'."
689689
(goto-char (swift-mode:token:start previous-token))
690690
(swift-mode:find-parent-and-align-with-next
691691
swift-mode:statement-parent-tokens
692-
(- swift-mode:basic-offset swift-mode:switch-case-offset)))
692+
(let ((relative-case-offset (- swift-mode:basic-offset swift-mode:switch-case-offset)))
693+
(if (<= relative-case-offset 0) swift-mode:basic-offset relative-case-offset))))
693694

694695
;; Before ; on the current line
695696
((and next-is-on-current-line (eq next-type '\;))

test/swift-files/indent/statements.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,22 @@ switch foo {
923923

924924
// swift-mode:test:eval (setq-local swift-mode:switch-case-offset 0)
925925

926+
// swift-mode:test:eval (setq-local swift-mode:switch-case-offset 4)
927+
928+
switch foo {
929+
case foo:
930+
foo()
931+
if let x = y {
932+
bar()
933+
}
934+
foo()
935+
default:
936+
foo()
937+
foo()
938+
}
939+
940+
// swift-mode:test:eval (setq-local swift-mode:switch-case-offset 0)
941+
926942

927943

928944
// Labeled statements

0 commit comments

Comments
 (0)