[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode 7837c90 319/496: Fix indentation around "where"
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode 7837c90 319/496: Fix indentation around "where" and "catch" |
Date: |
Sun, 29 Aug 2021 11:33:59 -0400 (EDT) |
branch: elpa/swift-mode
commit 7837c9099840d71fd91e9ffe8c2f3bcf533a4802
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>
Fix indentation around "where" and "catch"
---
swift-mode-indent.el | 80 ++++++++++++++--------
test/swift-files/statements.swift | 137 +++++++++++++++++++++++++++++++-------
2 files changed, 166 insertions(+), 51 deletions(-)
diff --git a/swift-mode-indent.el b/swift-mode-indent.el
index fcdc999..8a4d7df 100644
--- a/swift-mode-indent.el
+++ b/swift-mode-indent.el
@@ -89,7 +89,7 @@
(defconst swift-mode:expression-parent-tokens
(append swift-mode:statement-parent-tokens
- '(\, < supertype-: "where" "if" "guard" "while"))
+ '(\, < supertype-: "where" "if" "guard" "while" "catch"))
"Parent tokens for expressions.")
(defun swift-mode:indent-line ()
@@ -272,21 +272,31 @@
;; Other cases. Aligns with the previous case.
(swift-mode:align-with-current-line))))
+ ;; After "catch"
+ ((equal previous-text "catch")
+ (swift-mode:find-and-align-with-parents
+ swift-mode:statement-parent-tokens
+ swift-mode:multiline-statement-offset))
+
;; Before "where" on the same line
((and next-is-on-same-line (equal next-text "where"))
;; switch {
;; case let P(x)
;; where
- ;; a,
- ;; let Q(x)
- ;; where
- ;; a:
+ ;; a
;; aaa
;; }
;;
;; for case (x, y) in xys
- ;; where
- ;; aaa {
+ ;; where
+ ;; aaa {
+ ;; }
+ ;;
+ ;; for (x, y)
+ ;; in
+ ;; xys
+ ;; where
+ ;; aaa {
;; }
;;
;; do {
@@ -308,20 +318,30 @@
;; where
;; ABC {
;; }
- (let ((parent (save-excursion (swift-mode:backward-sexps-until
- (append swift-mode:statement-parent-tokens
- '("case"))))))
- (if (equal (swift-mode:token:text parent) "case")
- (progn
- (goto-char (swift-mode:token:end previous-token))
- (swift-mode:backward-token-or-list)
- (swift-mode:calculate-indent-of-expression
- swift-mode:multiline-statement-offset
- swift-mode:multiline-statement-offset))
+ (let* ((parent (save-excursion (swift-mode:backward-sexps-until
+ (append
swift-mode:statement-parent-tokens
+ '("case" "catch" "for")))))
+ (previous-of-parent (save-excursion
+ (goto-char (swift-mode:token:start parent))
+ (swift-mode:backward-token))))
+ (when (and
+ (equal (swift-mode:token:text parent) "case")
+ (equal (swift-mode:token:text previous-of-parent) "for"))
+ (setq parent previous-of-parent))
+ (cond
+ ((member (swift-mode:token:text parent) '("case" "catch"))
+ (goto-char (swift-mode:token:end previous-token))
+ (swift-mode:backward-token-or-list)
+ (swift-mode:calculate-indent-of-expression
+ swift-mode:multiline-statement-offset
+ swift-mode:multiline-statement-offset))
+ ((equal (swift-mode:token:text parent) "for")
+ (swift-mode:find-and-align-with-parents '("for")))
+ (t
(swift-mode:find-and-align-with-parents
(append swift-mode:statement-parent-tokens
- '(< "case" "catch" "for"))
- swift-mode:multiline-statement-offset))))
+ '(<))
+ swift-mode:multiline-statement-offset)))))
;; After {
((eq previous-type '{)
@@ -408,12 +428,18 @@
(let ((parent (save-excursion
(swift-mode:backward-sexps-until
(append swift-mode:statement-parent-tokens
- '("case"))))))
- (swift-mode:find-and-align-with-parents
- (append swift-mode:statement-parent-tokens
- '(< "case" "catch" "for")
- (if (equal (swift-mode:token:text parent) "case") '(\,)
'()))
- swift-mode:multiline-statement-offset))))
+ '("case" "catch"))))))
+ (if (member (swift-mode:token:text parent) '("case" "catch"))
+ (progn
+ (goto-char (swift-mode:token:end previous-token))
+ (swift-mode:backward-token-or-list)
+ (swift-mode:calculate-indent-of-expression
+ swift-mode:multiline-statement-offset
+ swift-mode:multiline-statement-offset))
+ (swift-mode:find-and-align-with-parents
+ (append swift-mode:statement-parent-tokens
+ '(< "for"))
+ swift-mode:multiline-statement-offset)))))
;; After implicit-\; or ;
((memq previous-type '(implicit-\; \;))
@@ -471,7 +497,7 @@
0
'(implicit-\; \;)))
- ;; After if, guard, while
+ ;; After if, guard, and while
((member previous-text '("if" "guard" "while"))
(swift-mode:find-and-align-with-parents
swift-mode:statement-parent-tokens
@@ -949,7 +975,7 @@ comma at eol."
(while (and (<= (point) pos) (not result))
(cond
((member (swift-mode:token:text next-token)
- '("guard" "while" "case" "where"))
+ '("guard" "while" "case" "where" "catch"))
(setq result next-token))
((member (swift-mode:token:text next-token)
diff --git a/test/swift-files/statements.swift
b/test/swift-files/statements.swift
index adecd27..cd7603f 100644
--- a/test/swift-files/statements.swift
+++ b/test/swift-files/statements.swift
@@ -123,7 +123,7 @@ for x
in
xs
.foo // swift-mode:test:known-bug
- where // swift-mode:test:known-bug
+ where
aaa
.bbb(x) {
foo()
@@ -142,8 +142,8 @@ for x
for x
in
xs
- where aaa
- .bbb(x) { // swift-mode:test:known-bug
+ where aaa
+ .bbb(x) {
foo()
foo()
}
@@ -151,19 +151,44 @@ for x
for x
in
xs where aaa
- .bbb(x) { // swift-mode:test:known-bug
+ .bbb(x) {
foo()
foo()
}
for
x in xs
+ where
+ aaa.bbb(x) {
+ foo()
+ foo()
+}
+
+for case .P(x)
+ in
+ xs
where
aaa.bbb(x) {
foo()
foo()
}
+for case .P(x) in xs where
+ aaa
+ .bbb(x) {
+ foo()
+ foo()
+}
+
+for .P(x) in xs where
+ aaa
+ .bbb(x) {
+ foo()
+ foo()
+}
+
+
+
// While statements
while foo
@@ -260,16 +285,16 @@ repeat {
foo()
foo()
} while foo
- .bar() // swift-mode:test:known-bug
- .baz()
+ .bar()
+ .baz()
repeat {
foo()
foo()
} while
foo
- .bar() // swift-mode:test:known-bug
- .baz()
+ .bar()
+ .baz()
repeat {
foo()
@@ -277,16 +302,16 @@ repeat {
}
while
foo
- .bar() // swift-mode:test:known-bug
- .baz()
+ .bar()
+ .baz()
repeat {
foo()
foo()
}
while foo
- .bar() // swift-mode:test:known-bug
- .baz()
+ .bar()
+ .baz()
// If statement
@@ -713,6 +738,38 @@ default:
foo()
}
+
+switch foo {
+case let .P(x)
+ where
+ foo
+ .bar:
+case let AAA
+ .P(x)
+ where
+ foo
+ .bar:
+case let .P(x) where
+ foo
+ .bar:
+case let AAA
+ .P(x) where
+ foo
+ .bar:
+case let .P(x)
+ where foo
+ .bar:
+case let AAA
+ .P(x)
+ where foo
+ .bar:
+case let .P(x) where foo
+ .bar:
+case let AAA
+ .P(x) where foo
+ .bar:
+}
+
// swift-mode:test:eval (setq-local swift-mode:switch-case-offset 2)
switch foo {
@@ -786,27 +843,59 @@ defer {
do {
} catch Foo
- .Bar(x)
- where // swift-mode:test:known-bug
- foo()
- .bar() {
+ .Bar(x)
+ where
+ foo()
+ .bar() {
+ foo()
+ foo()
+} catch Foo
+ .Bar(x)
+ where
+ foo()
+ .bar() {
foo()
foo()
} catch
- Foo // swift-mode:test:known-bug
- .Bar(x)
- where
- foo()
- .bar() {
+ Foo
+ .Bar(x)
+ where
+ foo()
+ .bar() {
foo()
foo()
} catch
- where // swift-mode:test:known-bug
- foo()
- .bar() {
+ where
+ foo()
+ .bar() {
foo()
foo()
}
+catch Foo
+ .Bar(x)
+ where
+ foo()
+ .bar() {
+ foo()
+ foo()
+}
+catch
+ Foo
+ .Bar(x)
+ where
+ foo()
+ .bar() {
+ foo()
+ foo()
+}
+catch
+ where
+ foo()
+ .bar() {
+ foo()
+ foo()
+}
+
// Conditional control statements
- [nongnu] elpa/swift-mode 27ec163 286/496: Merge pull request #113 from uk-ar/add-keyword-for-attribute, (continued)
- [nongnu] elpa/swift-mode 27ec163 286/496: Merge pull request #113 from uk-ar/add-keyword-for-attribute, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode f43317e 290/496: Add MELPA badge in README, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c73ce40 301/496: Update README.md about swift3-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7fc03bf 295/496: Merge pull request #119 from syohex/update-url, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 73abb98 292/496: Use cl-lib function instead of cl.el one, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 787658f 305/496: Update CONTRIBUTING.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0e24233 307/496: Fix forward/backward-sexp inside comments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 60dab9b 308/496: Update test to return informative exit status, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 01a1127 318/496: Fix indentation before "where", ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode b135df3 316/496: Fix output messages of the test, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7837c90 319/496: Fix indentation around "where" and "catch",
ELPA Syncer <=
- [nongnu] elpa/swift-mode 42a209c 322/496: Fix indentation of guard, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode ab9f414 320/496: Fix indentation of close curly brace of switch, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 97d86cd 326/496: Tweak test runner, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode ea77cf9 328/496: Add comments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 6cd2948 342/496: Bump version to 2.2.1, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7e78225 336/496: Bump version to 2.2, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 1868590 348/496: Add build/debug command, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a6d00b5 352/496: Simplify code, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 75f5214 364/496: Cleanup code, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7a9cf18 382/496: Fix beginning/end-of-sentence, ELPA Syncer, 2021/08/29