branch: elpa/swift-mode commit 0b1f29daa9e441dd7d24b6898131bdbcc14970c2 Author: taku0 <mxxouy6x3m_git...@tatapa.org> Commit: taku0 <mxxouy6x3m_git...@tatapa.org>
Fix indentation of setter --- swift-mode-lexer.el | 60 ++++++++++++++++++++++--------------- test/swift-files/declarations.swift | 22 ++++++++++++++ 2 files changed, 58 insertions(+), 24 deletions(-) diff --git a/swift-mode-lexer.el b/swift-mode-lexer.el index 4224f1e..4c616bb 100644 --- a/swift-mode-lexer.el +++ b/swift-mode-lexer.el @@ -302,17 +302,6 @@ END is the point after the token." '("get" "set" "willSet" "didSet" "subscript" "init" "deinit")) t) - ;; Suppress implicit semicolon after keywords that behave like method - ;; names. - ;; - ;; Note that binary operators take precedence over this: - ;; - ;; self . // not insert semicolon here - ;; init - ((member (swift-mode:token:text previous-token) - '("set" "willSet" "didSet" "subscript" "init" "deinit")) - nil) - ;; Suppress implicit semicolon after declaration starters. ((member (swift-mode:token:text previous-token) '("class" "struct" "protocol" "enum" "extension" "func" @@ -341,6 +330,42 @@ END is the point after the token." (swift-mode:forward-token-simple))) "<"))) + ;; Inserts semicolon before open curly bracket. + ;; + ;; Open curly bracket may continue the previous line, but we do not indent + ;; there. For example, the code below is parsed as `(foo() { x in ... })' + ;; by the Swift compiler, but we indent it like `foo(); { x in ... }'. + ;; + ;; foo() + ;; { // does not indent here + ;; x in + ;; ... + ;; } + ((eq (swift-mode:token:type next-token) '\{) t) + + ;; Suppress implicit semicolon after keywords that behave like method + ;; names. + ;; + ;; Note that binary operators take precedence over this: + ;; + ;; self . // not insert semicolon here + ;; init + ;; + ;; var x { + ;; set // not insert semicolon here + ;; (x) { + ;; } + ;; } + ;; + ;; var x { + ;; set // inserts semicolon here + ;; { + ;; } + ;; } + ((member (swift-mode:token:text previous-token) + '("set" "willSet" "didSet" "subscript" "init" "deinit")) + nil) + ;; Inserts implicit semicolon before open square bracket. ;; ;; Open square bracket for array indexing cannot appear at the start of a @@ -371,19 +396,6 @@ END is the point after the token." ;; ) ((eq (swift-mode:token:type next-token) '\() t) - ;; Inserts semicolon before open curly bracket. - ;; - ;; Open curly bracket may continue the previous line, but we do not indent - ;; there. For example, the code below is parsed as `(foo() { x in ... })' - ;; by the Swift compiler, but we indent it like `foo(); { x in ... }'. - ;; - ;; foo() - ;; { // does not indent here - ;; x in - ;; ... - ;; } - ((eq (swift-mode:token:type next-token) '\{) t) - ;; Otherwise, inserts implicit semicolon. (t t)))) diff --git a/test/swift-files/declarations.swift b/test/swift-files/declarations.swift index ecb8fcf..88eb98f 100644 --- a/test/swift-files/declarations.swift +++ b/test/swift-files/declarations.swift @@ -180,6 +180,28 @@ class Foo { foo() } } + + var x { + get { + 1 + } + + set { + foo() + } + } + + var x { + get + { + 1 + } + + set + { + foo() + } + } } // Type alias declaration