Skip to content

Commit 0b1f29d

Browse files
committed
Fix indentation of setter
1 parent f755479 commit 0b1f29d

File tree

2 files changed

+58
-24
lines changed

2 files changed

+58
-24
lines changed

swift-mode-lexer.el

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,6 @@ END is the point after the token."
302302
'("get" "set" "willSet" "didSet" "subscript" "init" "deinit"))
303303
t)
304304

305-
;; Suppress implicit semicolon after keywords that behave like method
306-
;; names.
307-
;;
308-
;; Note that binary operators take precedence over this:
309-
;;
310-
;; self . // not insert semicolon here
311-
;; init
312-
((member (swift-mode:token:text previous-token)
313-
'("set" "willSet" "didSet" "subscript" "init" "deinit"))
314-
nil)
315-
316305
;; Suppress implicit semicolon after declaration starters.
317306
((member (swift-mode:token:text previous-token)
318307
'("class" "struct" "protocol" "enum" "extension" "func"
@@ -341,6 +330,42 @@ END is the point after the token."
341330
(swift-mode:forward-token-simple)))
342331
"<")))
343332

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+
346+
;; Suppress implicit semicolon after keywords that behave like method
347+
;; names.
348+
;;
349+
;; Note that binary operators take precedence over this:
350+
;;
351+
;; self . // not insert semicolon here
352+
;; init
353+
;;
354+
;; var x {
355+
;; set // not insert semicolon here
356+
;; (x) {
357+
;; }
358+
;; }
359+
;;
360+
;; var x {
361+
;; set // inserts semicolon here
362+
;; {
363+
;; }
364+
;; }
365+
((member (swift-mode:token:text previous-token)
366+
'("set" "willSet" "didSet" "subscript" "init" "deinit"))
367+
nil)
368+
344369
;; Inserts implicit semicolon before open square bracket.
345370
;;
346371
;; Open square bracket for array indexing cannot appear at the start of a
@@ -371,19 +396,6 @@ END is the point after the token."
371396
;; )
372397
((eq (swift-mode:token:type next-token) '\() t)
373398

374-
;; Inserts semicolon before open curly bracket.
375-
;;
376-
;; Open curly bracket may continue the previous line, but we do not indent
377-
;; there. For example, the code below is parsed as `(foo() { x in ... })'
378-
;; by the Swift compiler, but we indent it like `foo(); { x in ... }'.
379-
;;
380-
;; foo()
381-
;; { // does not indent here
382-
;; x in
383-
;; ...
384-
;; }
385-
((eq (swift-mode:token:type next-token) '\{) t)
386-
387399
;; Otherwise, inserts implicit semicolon.
388400
(t t))))
389401

test/swift-files/declarations.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,28 @@ class Foo {
180180
foo()
181181
}
182182
}
183+
184+
var x {
185+
get {
186+
1
187+
}
188+
189+
set {
190+
foo()
191+
}
192+
}
193+
194+
var x {
195+
get
196+
{
197+
1
198+
}
199+
200+
set
201+
{
202+
foo()
203+
}
204+
}
183205
}
184206

185207
// Type alias declaration

0 commit comments

Comments
 (0)