Skip to content

Commit 0cab4b2

Browse files
committed
Fix indentation for catch blocks without patterns
Fixes #138. ``` do { } catch { } ```
1 parent 75cbae2 commit 0cab4b2

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

swift-mode-lexer.el

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,19 @@ END is the point after the token."
194194
'("inout" "throws" "rethrows" "in" "where")))
195195
nil)
196196

197+
;; Inserts semicolon before open curly bracket.
198+
;;
199+
;; Open curly bracket may continue the previous line, but we do not indent
200+
;; there. For example, the code below is parsed as `(foo() { x in ... })'
201+
;; by the Swift compiler, but we indent it like `foo(); { x in ... }'.
202+
;;
203+
;; foo()
204+
;; { // does not indent here
205+
;; x in
206+
;; ...
207+
;; }
208+
((eq (swift-mode:token:type next-token) '\{) t)
209+
197210
;; Inserts implicit semicolon around #... directives.
198211
;;
199212
;; Note that we cannot split #if line; the following code is not allowed.
@@ -330,19 +343,6 @@ END is the point after the token."
330343
(swift-mode:forward-token-simple)))
331344
"<")))
332345

333-
;; Inserts semicolon before open curly bracket.
334-
;;
335-
;; Open curly bracket may continue the previous line, but we do not indent
336-
;; there. For example, the code below is parsed as `(foo() { x in ... })'
337-
;; by the Swift compiler, but we indent it like `foo(); { x in ... }'.
338-
;;
339-
;; foo()
340-
;; { // does not indent here
341-
;; x in
342-
;; ...
343-
;; }
344-
((eq (swift-mode:token:type next-token) '\{) t)
345-
346346
;; Suppress implicit semicolon after keywords that behave like method
347347
;; names.
348348
;;

test/swift-files/statements.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,11 @@ catch
10351035
foo()
10361036
foo()
10371037
}
1038-
1038+
catch
1039+
{
1040+
foo()
1041+
foo()
1042+
}
10391043

10401044
// Conditional control statements
10411045

0 commit comments

Comments
 (0)