branch: elpa/swift-mode commit 85e05ea5e901fa7010db62d39c6efd728ccf3448 Merge: 37cab39 ce816a8 Author: Arthur Evstifeev <m...@ap4y.me> Commit: Arthur Evstifeev <m...@ap4y.me>
Merge pull request #105 from uk-ar/fix-move-by-sexp Fix move by sexp --- swift-mode.el | 25 ++++++++++++------------- test/indentation-tests.el | 21 ++++++++++++++------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/swift-mode.el b/swift-mode.el index edea55f..d14cd9f 100644 --- a/swift-mode.el +++ b/swift-mode.el @@ -107,8 +107,8 @@ (top-level-st ("import" type) (decl) - ("ACCESSMOD" "class" class-decl-exp "class-{" class-level-sts "}") - ("ACCESSMOD" "protocol" class-decl-exp "protocol-{" protocol-level-sts "}") + ("ACCESSMOD" "class" class-decl-exp "{" class-level-sts "}") + ("ACCESSMOD" "protocol" class-decl-exp "{" protocol-level-sts "}") ) (class-level-sts (class-level-st) (class-level-st ";" class-level-st)) @@ -278,16 +278,16 @@ We try to constraint those lookups by reasonable number of lines.") ((and (looking-at "\n\\|\/\/") (swift-smie--implicit-semi-p)) (if (eolp) (forward-char 1) (forward-comment 1)) ";") - - ((looking-at "{") (forward-char 1) - (if (looking-back "\\(class\\|protocol\\) [^{]+{" (line-beginning-position swift-smie--lookback-max-lines) t) - (concat (match-string 1) "-{") - "{")) + (t + (forward-comment (point)) + (cond + ((looking-at "{") (forward-char 1) "{") ((looking-at "}") (forward-char 1) "}") ((looking-at ",") (forward-char 1) ",") ((looking-at ":") (forward-char 1) - (if (looking-back "\\(case [^:]+\\|default\\):" (line-beginning-position 0) t) + ;; look-back until "case", "default", ":", "{", ";" + (if (looking-back "\\(case[\n\t ][^:{;]+\\|default[\n\t ]*\\):") "case-:" ":")) @@ -327,6 +327,7 @@ We try to constraint those lookups by reasonable number of lines.") "else")) (t tok)))) )) + )) (defun swift-smie--backward-token () (let ((pos (point))) @@ -336,15 +337,13 @@ We try to constraint those lookups by reasonable number of lines.") (swift-smie--implicit-semi-p)) ";") - ((eq (char-before) ?\{) (backward-char 1) - (if (looking-back "\\(class\\|protocol\\) [^{]+" (line-beginning-position swift-smie--lookback-max-lines) t) - (concat (match-string 1) "-{") - "{")) + ((eq (char-before) ?\{) (backward-char 1) "{") ((eq (char-before) ?\}) (backward-char 1) "}") ((eq (char-before) ?,) (backward-char 1) ",") ((eq (char-before) ?:) (backward-char 1) - (if (looking-back "case [^:]+\\|default" (line-beginning-position 0)) + ;; look-back until "case", "default", ":", "{", ";" + (if (looking-back "\\(case[\n\t ][^:{;]+\\|default[\n\t ]*\\)") "case-:" ":")) diff --git a/test/indentation-tests.el b/test/indentation-tests.el index 8defb9a..30ec607 100644 --- a/test/indentation-tests.el +++ b/test/indentation-tests.el @@ -72,7 +72,14 @@ values of customisable variables." (indent-according-to-mode) (should (equal expected-state (buffer-string))) - (should (equal expected-cursor-pos (point)))))))) + (should (equal expected-cursor-pos (point))) + + (goto-char (point-min)) + (forward-sexp 10) + (should (equal (point-max) (point))) + (forward-sexp -10) + (should (equal (point-min) (point))) + ))))) ;; Provide font locking for easier test editing. @@ -1181,10 +1188,10 @@ let foo = [ (check-indentation indents-declaration/12 " let foo = [ -|[ +|[]] " " let foo = [ - |[ + |[]] ") (check-indentation indents-declaration/13 @@ -1381,10 +1388,10 @@ func a () { (check-indentation indents-multiline-expressions/13 " if (a -|.b) +|.b){} " " if (a - |.b) + |.b){} ") (check-indentation indents-multiline-expressions/14 @@ -2048,12 +2055,12 @@ foo.bar(10, foo.bar(10, completionHandler: { (bar, baz) -> Void in |foo - } + }) " " foo.bar(10, completionHandler: { (bar, baz) -> Void in |foo - } + }) ") (check-indentation anonymous-function-as-a-argument/9