[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode 86eb49c 323/496: Fix indentation of for-in
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode 86eb49c 323/496: Fix indentation of for-in |
Date: |
Sun, 29 Aug 2021 11:33:59 -0400 (EDT) |
branch: elpa/swift-mode
commit 86eb49c33e383a57133e30a5375859c3ed7cd7e6
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>
Fix indentation of for-in
---
swift-mode-indent.el | 84 +++++++++++++++-----------
test/swift-files/statements.swift | 120 ++++++++++++++++++++++++++++++++++----
2 files changed, 157 insertions(+), 47 deletions(-)
diff --git a/swift-mode-indent.el b/swift-mode-indent.el
index 6645737..cdfcc5d 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" "catch"))
+ '(\, < supertype-: "where" "if" "guard" "while" "for" "catch"))
"Parent tokens for expressions.")
(defun swift-mode:indent-line ()
@@ -282,31 +282,37 @@
((and next-is-on-same-line (equal next-text "where"))
;; switch {
;; case let P(x)
- ;; where
+ ;; where // Aligns with the pattern.
;; a
;; aaa
;; }
+ ;; case let A
+ ;; .P(x)
+ ;; where // Aligns with the last line of the pattern.
+ ;; a
+ ;; aaa
+ ;; }
;;
;; for case (x, y) in xys
- ;; where
+ ;; where // Aligns with the next token of the "for" token.
;; aaa {
;; }
;;
;; for (x, y)
;; in
;; xys
- ;; where
+ ;; where // Aligns with the next token of the "for" token.
;; aaa {
;; }
;;
;; do {
;; } catch let P(x)
- ;; where
+ ;; where // Aligns with the pattern.
;; aaa
;;
;; func foo<A: AAA,
;; B: BBB
- ;; where
+ ;; where // Aligns with the start of the type parameters.
;; ABC>() {
;; }
;;
@@ -315,7 +321,7 @@
;; C>: AAA,
;; BBB,
;; CCC
- ;; where
+ ;; where // Aligns with the "class" token.
;; ABC {
;; }
(let* ((parent (save-excursion (swift-mode:backward-sexps-until
@@ -359,50 +365,51 @@
;; After "where"
((equal previous-text "where")
;; switch {
- ;; case let P(x) where
- ;; A,
- ;; let Q(x) where
- ;; A:
+ ;; case let .P(x) where
+ ;; A, // Aligns with the pattern.
+ ;; let A
+ ;; .Q(x) where // Aligns with the last line of the pattern.
+ ;; A:
;; aaa
- ;; case let P(x)
- ;; where
- ;; a,
- ;; let Q(x)
+ ;; case let .P(x)
;; where
- ;; a:
+ ;; A, // Aligns with the "where" token.
+ ;; let .Q(x)
+ ;; where // Aligns with the "where" token.
+ ;; A:
;; aaa
- ;; case let P(x), let Q(x) where
- ;; a
+ ;; case let .P(x), let .Q(x) where // Aligns with the pattern.
+ ;; a
;; }
;;
;; for case let (x, y) in xys where
- ;; aaa {
+ ;; aaa { // Aligns with the next token of the "for" token.
;; }
;;
;; for case let (x, y) in xys
- ;; where
- ;; aaa {
+ ;; where
+ ;; aaa { // Aligns with the "where" token
;; }
;;
;; do {
- ;; } catch let P(x) where
- ;; aaa
+ ;; } catch let .P(x) where
+ ;; aaa // Aligns with the pattern.
;; do {
- ;; } catch let P(x)
+ ;; } catch let .P(x)
;; where
- ;; aaa
+ ;; aaa // Aligns with the "where" token.
;;
;;
;;
;; func foo<A: AAA,
;; B: BBB where
- ;; ABC>() {
+ ;; ABC>() { // Aligns with the start of the type parameters.
;; }
;;
;; func foo<A: AAA,
;; B: BBB
;; where
- ;; ABC>() {
+ ;; ABC>() { // Aligns with the "where" token.
;; }
;;
;; class Foo<A,
@@ -410,7 +417,7 @@
;; C> A,
;; B,
;; C where
- ;; ABC {
+ ;; ABC { // Aligns with the "class" token"
;; }
;;
;; class Foo<A,
@@ -419,7 +426,7 @@
;; B,
;; C
;; where
- ;; ABC {
+ ;; ABC { // Aligns with the "where" token"
;; }
(goto-char (swift-mode:token:start previous-token))
(if (swift-mode:bol-other-than-comments-p)
@@ -431,7 +438,6 @@
'("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
@@ -693,8 +699,9 @@ This function is also used for close-curly-brace."
;; }
(setq is-declaration-or-control-statement-body nil)
(save-excursion
- (swift-mode:backward-sexps-until swift-mode:statement-parent-tokens)
- (swift-mode:forward-token)
+ (goto-char (swift-mode:token:end
+ (swift-mode:backward-sexps-until
+ swift-mode:statement-parent-tokens)))
(setq next-token (swift-mode:forward-token-or-list))
(while (<= (point) pos)
(cond
@@ -959,11 +966,19 @@ comma at eol."
;; TODO Unify with swift-mode:find-parent-of-list-element
(let ((pos (point))
(parent (swift-mode:backward-sexps-until
- swift-mode:expression-parent-tokens)))
+ swift-mode:expression-parent-tokens
+ '("in") '("in"))))
(cond
((memq (swift-mode:token:type parent) '(\( \[))
parent)
+ ((equal (swift-mode:token:text parent) "in")
+ (goto-char (swift-mode:token:end parent))
+ (if (swift-mode:eol-other-than-comments-p)
+ parent
+ (goto-char (swift-mode:token:start parent))
+ (swift-mode:backward-token-or-list)))
+
((or
(memq (swift-mode:token:type parent)
swift-mode:statement-parent-tokens)
@@ -975,8 +990,7 @@ comma at eol."
result)
(while (and (<= (point) pos) (not result))
(cond
- ((member (swift-mode:token:text next-token)
- '("guard" "while" "case" "where" "catch"))
+ ((equal (swift-mode:token:text next-token) "case")
(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 a7ee80a..cde6127 100644
--- a/test/swift-files/statements.swift
+++ b/test/swift-files/statements.swift
@@ -40,7 +40,7 @@ for
for
x
in xs
- .foo() { // swift-mode:test:known-bug
+ .foo() {
foo()
foo()
}
@@ -52,7 +52,7 @@ for
)
in
xs
- .foo() +++ { z in // swift-mode:test:known-bug
+ .foo() +++ { z in
bar()
} {
foo()
@@ -61,13 +61,13 @@ for
for
case
- ( // swift-mode:test:known-bug
+ (
x,
y
)
in
xs
- .foo() +++ { z in // swift-mode:test:known-bug
+ .foo() +++ { z in
bar()
bar()
} {
@@ -76,13 +76,13 @@ for
}
for case
- ( // swift-mode:test:known-bug
+ (
x,
y
)
in
xs
- .foo() +++ { z in // swift-mode:test:known-bug
+ .foo() +++ { z in
bar()
bar()
} {
@@ -92,7 +92,7 @@ for case
for Foo
- .Bar(x) // swift-mode:test:known-bug
+ .Bar(x)
in
xs {
foo()
@@ -101,7 +101,7 @@ for Foo
for
Foo
- .Bar(x) // swift-mode:test:known-bug
+ .Bar(x)
in
xs {
foo()
@@ -111,7 +111,7 @@ for
for x as
- Foo // swift-mode:test:known-bug
+ Foo
in
xs {
foo()
@@ -122,7 +122,7 @@ for x as
for x
in
xs
- .foo // swift-mode:test:known-bug
+ .foo
where
aaa
.bbb(x) {
@@ -174,8 +174,8 @@ for case .P(x)
}
for case .P(x) in xs where
- aaa
- .bbb(x) {
+ aaa
+ .bbb(x) {
foo()
foo()
}
@@ -187,6 +187,102 @@ for .P(x) in xs where
foo()
}
+for case .P(x) in xs
+ where
+ aaa
+ .bbb(x) {
+ foo()
+ foo()
+}
+
+for .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()
+}
+
+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()
+}
+
+for
+ case .P(x) in xs
+ where
+ aaa
+ .bbb(x) {
+ foo()
+ foo()
+}
+
+for
+ .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
- [nongnu] elpa/swift-mode 68a3a29 231/496: Support for choosing framework search paths., (continued)
- [nongnu] elpa/swift-mode 68a3a29 231/496: Support for choosing framework search paths., ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 8e0f8d6 240/496: Merge pull request #94 from wiruzx/new-range-operator, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 17bf117 242/496: Merge pull request #95 from wiruzx/add-as!-operator, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode b3af0b0 252/496: Constraint all look backs to the reasonable amount of lines, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 52a01b1 269/496: Add test case for backward-sexp, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 5c09b07 289/496: Merge pull request #114 from uk-ar/fix-indent-for-ternary-operator, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 4e9da69 299/496: Release 0.4.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c303245 291/496: Merge pull request #115 from uk-ar/add-melpa-badge, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 9211980 312/496: Bump version to 2.1.2, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 3d27871 313/496: Tweak README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 86eb49c 323/496: Fix indentation of for-in,
ELPA Syncer <=
- [nongnu] elpa/swift-mode 78cea9d 337/496: Improve CI, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 63580e8 339/496: Speed-up indentation for colon, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode e91e924 347/496: Bump version to 2.2.4, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 9892096 350/496: Bump version to 2.3.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 55ea958 354/496: Fix syntax error, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode e8d9a5d 363/496: Bump version to 3.0.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 99ff376 362/496: Improve functions related to defuns, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode e3cb72b 360/496: Fix `swift-mode:forward-sexp` for `up-list` and `down-list`, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 50394e4 357/496: Bump version to 2.4.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 82ee822 361/496: Fix code styles, ELPA Syncer, 2021/08/29