[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode cb7ba6f 245/496: Add an option for indent after
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode cb7ba6f 245/496: Add an option for indent after hanging comma |
Date: |
Sun, 29 Aug 2021 11:33:44 -0400 (EDT) |
branch: elpa/swift-mode
commit cb7ba6f0bfc07211235f84fd47c95b63fa54632e
Author: uk-ar <yuuki.ari@gmail.com>
Commit: uk-ar <yuuki.ari@gmail.com>
Add an option for indent after hanging comma
---
swift-mode.el | 29 +++++++++++++++++++++++------
test/indentation-tests.el | 8 +++++---
2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/swift-mode.el b/swift-mode.el
index 15a7e20..19dd18a 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -61,6 +61,12 @@
:type 'integer
:package-version '(swift-mode "0.3.0"))
+(defcustom swift-indent-hanging-comma-offset 4
+ "Defines the indentation offset for hanging comma."
+ :group 'swift
+ :type 'integer
+ :package-version '(swift-mode "0.4.0"))
+
(defcustom swift-repl-executable
"xcrun swift"
"Path to the Swift CLI."
@@ -153,9 +159,11 @@
(enum-cases (enum-case) (enum-case ";" enum-case))
(enum-body (enum-cases) (insts))
- (case-exps (exp) (guard-exp))
- (case (case-exps ":" insts))
- (switch-body (case) (case "case" case))
+ (case-exps (exp)
+ (guard-exp)
+ (case-exps "," case-exps))
+ (case ("case" case-exps "case-:" insts))
+ (switch-body (case))
(for-head (in-exp) (op-exp) (for-head ";" for-head))
@@ -247,7 +255,10 @@
((looking-at "}") (forward-char 1) "}")
((looking-at ",") (forward-char 1) ",")
- ((looking-at ":") (forward-char 1) ":")
+ ((looking-at ":") (forward-char 1)
+ (if (looking-back "case [^:]+:")
+ "case-:"
+ ":"))
((looking-at "->") (forward-char 2) "->")
@@ -292,7 +303,10 @@
((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 [^:]+")
+ "case-:"
+ ":"))
((looking-back "->" (- (point) 2) t)
(goto-char (match-beginning 0)) "->")
@@ -369,9 +383,12 @@
;; Indent second line of the multi-line class
;; definitions with swift-indent-offset
+ (`(:before . "case")
+ (smie-rule-parent))
+
(`(:before . ",")
(if (smie-rule-parent-p "class" "case")
- (smie-rule-parent)))
+ (smie-rule-parent swift-indent-hanging-comma-offset)))
;; Disable unnecessary default indentation for
;; "func" and "class" keywords
diff --git a/test/indentation-tests.el b/test/indentation-tests.el
index 9773aac..3153cf1 100644
--- a/test/indentation-tests.el
+++ b/test/indentation-tests.el
@@ -59,6 +59,8 @@ values of customisable variables."
(swift-indent-offset 4)
(swift-indent-switch-case-offset 0)
(swift-indent-multiline-statement-offset 2)
+ ;; Change from default value to detect offset bug.
+ (swift-indent-hanging-comma-offset 3)
,@var-bindings)
(with-temp-buffer
(insert ,before)
@@ -486,7 +488,7 @@ case foo where bar,
" "
switch true {
case foo where bar,
-|bar where baz:
+ |bar where baz:
}
")
@@ -685,7 +687,7 @@ class Foo: Foo, Bar,
}
" "
class Foo: Foo, Bar,
-|Baz {
+ |Baz {
}
")
@@ -725,7 +727,7 @@ public class Foo: Foo, Bar,
}
" "
public class Foo: Foo, Bar,
-|Baz {
+ |Baz {
}
")
- [nongnu] elpa/swift-mode 782378c 214/496: Correct regex in lexer for the "default" keyword, (continued)
- [nongnu] elpa/swift-mode 782378c 214/496: Correct regex in lexer for the "default" keyword, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c38b721 216/496: Support default values for arguments in function declaration, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 2cb54c9 222/496: Make grammar for if statement a bit more precise, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode b6bad10 225/496: Set minimum required version to 24.4, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 4a27477 230/496: Merge pull request #89 from uk-ar/fix-indent-in-trailing-closure, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 4289bd7 235/496: Fix implicit semicolon rule, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a29398b 239/496: Fix half-open range operator, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7f25806 241/496: Add as! operator, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 86339ed 247/496: Fix curly bracket's syntax table to enable electric-pair, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 37cab39 263/496: Improve indentation for switch and class statements, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cb7ba6f 245/496: Add an option for indent after hanging comma,
ELPA Syncer <=
- [nongnu] elpa/swift-mode 0185315 274/496: Merge pull request #107 from uk-ar/fix-forward-list, ELPA Syncer, 2021/08/29
- [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