branch: elpa/swift-mode commit 1dfb1a595b66f8e02ea8f9ee80c7d834398be7ca Author: ap4y <l...@pisem.net> Commit: ap4y <l...@pisem.net>
Add indent rules for function declaration with attributes --- swift-mode.el | 9 ++++++++- test/indentation-tests.el | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/swift-mode.el b/swift-mode.el index a1eccc2..bee995e 100644 --- a/swift-mode.el +++ b/swift-mode.el @@ -95,7 +95,7 @@ (class-level-sts (class-level-st) (class-level-st ";" class-level-st)) (class-level-st (decl) - ("override" "func" func-header "{" insts "}")) + ("DECSPEC" "func" func-header "{" insts "}")) (func-header (id "(" func-params ")")) (func-param (decl-exp) ("...")) @@ -178,6 +178,9 @@ "*" "/" "%" "&*" "&/" "&%" "&" "<<" ">>"))) +(defvar swift-smie--decl-specifier-regexp + (regexp-opt '("class" "mutating" "override" "static" "unowned" "weak"))) + (defun swift-smie--implicit-semi-p () (save-excursion (not (or (memq (char-before) '(?\{ ?\[ ?\,)) @@ -193,6 +196,8 @@ ((looking-at "}") (forward-char 1) "}") ((looking-at swift-smie--operators-regexp) (goto-char (match-end 0)) "OP") + ((looking-at swift-smie--decl-specifier-regexp) + (goto-char (match-end 0)) "DECSPEC") (t (smie-default-forward-token)))) (defun swift-smie--backward-token () @@ -206,6 +211,8 @@ ((eq (char-before) ?\}) (backward-char 1) "}") ((looking-back swift-smie--operators-regexp (- (point) 3) t) (goto-char (match-beginning 0)) "OP") + ((looking-back swift-smie--decl-specifier-regexp (- (point) 8) t) + (goto-char (match-beginning 0)) "DECSPEC") (t (smie-default-backward-token))))) (defun swift-smie-rules (kind token) diff --git a/test/indentation-tests.el b/test/indentation-tests.el index 502e961..24c8b72 100644 --- a/test/indentation-tests.el +++ b/test/indentation-tests.el @@ -652,6 +652,17 @@ class Foo { } ") +(check-indentation indents-func-declaration/2 + " +class func Foo() { +|foo +} +" " +class func Foo() { + |foo +} +") + (check-indentation indents-declaration/1 " var foo = bar + baz