emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/swift-mode f03db1a 331/496: Fix indentation of switch.


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode f03db1a 331/496: Fix indentation of switch.
Date: Sun, 29 Aug 2021 11:34:01 -0400 (EDT)

branch: elpa/swift-mode
commit f03db1a91cff6cbf2ec471481eccaea27af20010
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>

    Fix indentation of switch.
    
    Close #134.
---
 swift-mode-indent.el              | 22 ++++++++++++++++++----
 test/swift-files/statements.swift | 12 ++++++++++++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/swift-mode-indent.el b/swift-mode-indent.el
index c9c1ef0..2a6c377 100644
--- a/swift-mode-indent.el
+++ b/swift-mode-indent.el
@@ -262,10 +262,24 @@ declaration and its offset is `swift-mode:basic-offset'."
        next-is-on-same-line
        (member next-text '("case" "default"))
        (save-excursion
-         (equal (swift-mode:token:text
-                 (swift-mode:backward-sexps-until
-                  '("switch" "enum" "for" "while" "if" "guard")))
-                "switch")))
+         (let ((head
+                (swift-mode:backward-sexps-until
+                 '(implicit-\; \; "switch" "enum" "for" "while" "if" 
"guard"))))
+           (or
+            (equal (swift-mode:token:text head) "switch")
+            (and
+             ;; If we got a semicolon, the statement is either switch or enum:
+             ;;
+             ;; switch foo {
+             ;; case 1:
+             ;;   if aaa {
+             ;;   }; // implicit semicolon
+             ;; case 2:
+             ;; }
+             (memq (swift-mode:token:type head) '(implicit-\; \;))
+             (equal (swift-mode:token:text
+                     (swift-mode:backward-sexps-until '("switch" "enum")))
+                    "switch"))))))
       ;; "case" is used for "switch", "enum", "for", "while", "if", and 
"guard".
       ;; Only switch statement has special indentation rule.
       ;;
diff --git a/test/swift-files/statements.swift 
b/test/swift-files/statements.swift
index f1c9851..79947ad 100644
--- a/test/swift-files/statements.swift
+++ b/test/swift-files/statements.swift
@@ -885,6 +885,18 @@ case let AAA
                      .bar:
 }
 
+switch foo {
+case 1:
+    if aaa {
+    }
+case 2:
+    if bbb {
+    }
+default:
+    if ccc {
+    }
+}
+
 // swift-mode:test:eval (setq-local swift-mode:switch-case-offset 2)
 
 switch foo {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]