branch: elpa/swift-mode commit 42669da0b68bba2d12f9d5fc38f30def118bb999 Author: taku0 <mxxouy6x3m_git...@tatapa.org> Commit: taku0 <mxxouy6x3m_git...@tatapa.org>
Fix indentation for keywords used as parameter names ``` foo( in: 1 ) foo( where: 1 ) ``` --- swift-mode-font-lock.el | 1 - swift-mode-indent.el | 106 +++++++-------- test/swift-files/identifiers.swift | 255 +++++++++++++++++++++++++++++++++++++ 3 files changed, 308 insertions(+), 54 deletions(-) diff --git a/swift-mode-font-lock.el b/swift-mode-font-lock.el index b99b012..66faa0a 100644 --- a/swift-mode-font-lock.el +++ b/swift-mode-font-lock.el @@ -126,7 +126,6 @@ Return nil otherwise." "\\<catch\\>" "\\<dynamicType\\>" "\\<is\\>" - "\\<nil\\>" "\\<rethrows\\>" "\\<super\\>" "\\<self\\>" diff --git a/swift-mode-indent.el b/swift-mode-indent.el index bcd3d68..e7e4951 100644 --- a/swift-mode-indent.el +++ b/swift-mode-indent.el @@ -217,46 +217,6 @@ declaration and its offset is `swift-mode:basic-offset'." (goto-char (swift-mode:token:start previous-token)) (swift-mode:calculate-indent-after-comma)) - ;; Before "in" on the same line - ((and next-is-on-same-line (equal next-text "in")) - ;; When it is for-in statement, align with the token after "for": - ;; - ;; for - ;; x - ;; in - ;; foo - ;; - ;; for x - ;; in - ;; foo - ;; - ;; When it is anonymous function, align with the token after {: - ;; - ;; foo { - ;; x - ;; in - ;; ... - ;; } - ;; - ;; - ;; foo { x - ;; in - ;; ... - ;; } - ;; - ;; foo { [ - ;; weak self - ;; ] - ;; ( - ;; x, - ;; y - ;; ) - ;; -> Void - ;; in - ;; a - ;; } - (swift-mode:find-and-align-with-parents '("for" {))) - ;; Before "case" or "default" on the same line, for switch statement ((and next-is-on-same-line @@ -340,6 +300,59 @@ declaration and its offset is `swift-mode:basic-offset'." swift-mode:statement-parent-tokens swift-mode:multiline-statement-offset)) + ;; After { + ((eq previous-type '{) + (goto-char (swift-mode:token:start previous-token)) + (swift-mode:calculate-indent-after-open-curly-brace + swift-mode:basic-offset)) + + ;; After ( or [ + ((memq previous-type '(\( \[)) + (goto-char (swift-mode:token:start previous-token)) + (swift-mode:calculate-indent-of-expression + swift-mode:parenthesized-expression-offset + swift-mode:parenthesized-expression-offset)) + + ;; Before "in" on the same line + ((and next-is-on-same-line (equal next-text "in")) + ;; When it is for-in statement, align with the token after "for": + ;; + ;; for + ;; x + ;; in + ;; foo + ;; + ;; for x + ;; in + ;; foo + ;; + ;; When it is anonymous function, align with the token after {: + ;; + ;; foo { + ;; x + ;; in + ;; ... + ;; } + ;; + ;; + ;; foo { x + ;; in + ;; ... + ;; } + ;; + ;; foo { [ + ;; weak self + ;; ] + ;; ( + ;; x, + ;; y + ;; ) + ;; -> Void + ;; in + ;; a + ;; } + (swift-mode:find-and-align-with-parents '("for" {))) + ;; Before "where" on the same line ((and next-is-on-same-line (equal next-text "where")) ;; switch { @@ -411,19 +424,6 @@ declaration and its offset is `swift-mode:basic-offset'." '(<)) swift-mode:multiline-statement-offset))))) - ;; After { - ((eq previous-type '{) - (goto-char (swift-mode:token:start previous-token)) - (swift-mode:calculate-indent-after-open-curly-brace - swift-mode:basic-offset)) - - ;; After ( or [ - ((memq previous-type '(\( \[)) - (goto-char (swift-mode:token:start previous-token)) - (swift-mode:calculate-indent-of-expression - swift-mode:parenthesized-expression-offset - swift-mode:parenthesized-expression-offset)) - ;; After "where" ((equal previous-text "where") ;; switch { diff --git a/test/swift-files/identifiers.swift b/test/swift-files/identifiers.swift index 7bff27f..519ed39 100644 --- a/test/swift-files/identifiers.swift +++ b/test/swift-files/identifiers.swift @@ -33,6 +33,261 @@ let foo = foo.var let x = foo.where + a +// keywords as parameter names + +func foo() { + // Keywords used in declarations + foo( + associatedtype: 1 + ) + foo( + class: 1 + ) + foo( + deinit: 1 + ) + foo( + enum: 1 + ) + foo( + extension: 1 + ) + foo( + fileprivate: 1 + ) + foo( + func: 1 + ) + foo( + import: 1 + ) + foo( + init: 1 + ) + foo( + inout: 1 + ) + foo( + internal: 1 + ) + foo( + let: 1 + ) + foo( + open: 1 + ) + foo( + operator: 1 + ) + foo( + private: 1 + ) + foo( + protocol: 1 + ) + foo( + public: 1 + ) + foo( + static: 1 + ) + foo( + struct: 1 + ) + foo( + subscript: 1 + ) + foo( + typealias: 1 + ) + foo( + var: 1 + ) + + // Keywords used in statements + foo( + break: 1 + ) + foo( + case: 1 + ) + foo( + continue: 1 + ) + foo( + default: 1 + ) + foo( + defer: 1 + ) + foo( + do: 1 + ) + foo( + else: 1 + ) + foo( + fallthrough: 1 + ) + foo( + for: 1 + ) + foo( + guard: 1 + ) + foo( + if: 1 + ) + foo( + in: 1 + ) + foo( + repeat: 1 + ) + foo( + return: 1 + ) + foo( + switch: 1 + ) + foo( + where: 1 + ) + foo( + while: 1 + ) + + // Keywords used in expressions and types (without true, false, and keywords begin with a number sign) + foo( + as: 1 + ) + foo( + catch: 1 + ) + foo( + dynamicType: 1 + ) + foo( + is: 1 + ) + foo( + rethrows: 1 + ) + foo( + super: 1 + ) + foo( + self: 1 + ) + foo( + Self: 1 + ) + foo( + throws: 1 + ) + foo( + throw: 1 + ) + foo( + try: 1 + ) + + // Keywords reserved in particular contexts + foo( + Protocol: 1 + ) + foo( + Type: 1 + ) + foo( + and: 1 + ) + foo( + assignment: 1 + ) + foo( + associativity: 1 + ) + foo( + convenience: 1 + ) + foo( + didSet: 1 + ) + foo( + dynamic: 1 + ) + foo( + final: 1 + ) + foo( + get: 1 + ) + foo( + higherThan: 1 + ) + foo( + indirect: 1 + ) + foo( + infix: 1 + ) + foo( + lazy: 1 + ) + foo( + left: 1 + ) + foo( + lowerThan: 1 + ) + foo( + mutating: 1 + ) + foo( + none: 1 + ) + foo( + nonmutating: 1 + ) + foo( + optional: 1 + ) + foo( + override: 1 + ) + foo( + postfix: 1 + ) + foo( + precedence: 1 + ) + foo( + precedencegroup: 1 + ) + foo( + prefix: 1 + ) + foo( + required: 1 + ) + foo( + right: 1 + ) + foo( + set: 1 + ) + foo( + unowned: 1 + ) + foo( + weak: 1 + ) + foo( + willSet: 1 + ) +} + // Unicode identifiers let こんにちは = 你好 +