[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode 821d9af 064/496: Make switch-case indent offset
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode 821d9af 064/496: Make switch-case indent offset customisable |
Date: |
Sun, 29 Aug 2021 11:33:08 -0400 (EDT) |
branch: elpa/swift-mode
commit 821d9afb6d43b53f90e590a3252d4a0368609a4e
Author: Chris Barrett <chris.d.barrett@me.com>
Commit: Chris Barrett <chris.d.barrett@me.com>
Make switch-case indent offset customisable
---
swift-mode.el | 11 +++++++++--
test/indentation-tests.el | 38 ++++++++++++++++++++++++++++++++++----
2 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/swift-mode.el b/swift-mode.el
index 84c85df..8ceea49 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -46,6 +46,11 @@
:group 'swift
:type 'integer)
+(defcustom swift-indent-switch-case-offset 0
+ "Defines the indentation offset for cases in a switch statement."
+ :group 'swift
+ :type 'integer)
+
;;; Indentation
(defun swift-indent--paren-level ()
@@ -153,9 +158,11 @@ Returns the column number as an integer."
(cond
((swift-indent--at-enum-case?)
baseline)
- ;; Cases are indented to the same level as the enclosing switch
statement.
+ ;; Cases are indented to the same level as the enclosing switch
+ ;; statement, plus a user-customisable offset.
((looking-at (rx bow (or "case" "default") eow))
- (- baseline swift-indent-offset))
+ (+ (- baseline swift-indent-offset)
+ swift-indent-switch-case-offset))
(t
baseline)))))))))
diff --git a/test/indentation-tests.el b/test/indentation-tests.el
index 9d9fffd..6c24edd 100644
--- a/test/indentation-tests.el
+++ b/test/indentation-tests.el
@@ -30,7 +30,7 @@
(require 'swift-mode)
(require 's)
-(defmacro check-indentation (description before after)
+(defmacro check-indentation (description before after &optional var-bindings)
"Declare an ert test for indentation behaviour.
The test will check that the swift indentation command changes the buffer
from one state to another. It will also test that point is moved to an
@@ -42,7 +42,10 @@ BEFORE is the buffer string before indenting, where a pipe
(|) represents
point.
AFTER is the expected buffer string after indenting, where a pipe (|)
-represents the expected position of point."
+represents the expected position of point.
+
+VAR-BINDINGS is an optional let-bindings list. It can be used to set the
+values of customisable variables."
(declare (indent 1))
(let ((fname (intern (format "indentation/%s" description))))
`(ert-deftest ,fname ()
@@ -50,8 +53,10 @@ represents the expected position of point."
(expected-cursor-pos (1+ (s-index-of "|" after)))
(expected-state (delete ?| after))
- ;; Set the offset to a consistent value for tests.
- (swift-indent-offset 4))
+ ;; Bind customisable vars to default values for tests.
+ (swift-indent-offset 4)
+ (swift-indent-switch-case-offset 0)
+ ,@var-bindings)
(with-temp-buffer
(insert ,before)
(goto-char (point-min))
@@ -229,6 +234,31 @@ switch true {
}
")
+(check-indentation indents-case-statements-to-user-defined-offset/1
+ "
+switch true {
+ |case
+}
+" "
+switch true {
+ |case
+}
+"
+((swift-indent-switch-case-offset 2)))
+
+(check-indentation indents-case-statements-to-user-defined-offset/2
+ "
+switch true {
+ |case
+}
+" "
+switch true {
+ |case
+}
+"
+((swift-indent-switch-case-offset 2)))
+
+
(check-indentation indents-case-statements-in-enum/1
"
enum T {
- [nongnu] elpa/swift-mode 741859e 018/496: Add `convenience` to language keywords, (continued)
- [nongnu] elpa/swift-mode 741859e 018/496: Add `convenience` to language keywords, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 8d2720b 020/496: Add autoload token, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 71e3d6f 033/496: Remove unneeded infrastructure, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 28c5b54 027/496: More improvements to comment handling, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 9b367fe 038/496: Remove duplicate in keywords list, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0bf214b 030/496: Update readme, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cb745d5 029/496: Define basic indentation command., ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0344f63 036/496: Merge pull request #11 from bbatsov/patch-1, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 89ce39c 050/496: Format file sections, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0f99a5a 067/496: Tweak docstring to supress checkdoc error, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 821d9af 064/496: Make switch-case indent offset customisable,
ELPA Syncer <=
- [nongnu] elpa/swift-mode bbd8f91 096/496: Add tests for all implemented smie grammars, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cfbc318 092/496: Merge pull request #24 from ap4y/fix_paragraph_movements, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a8fa421 086/496: Use a more descriptive map variable name inside its definition, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0c908ad 103/496: Remove an outdated statement about the indentation code, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 41d38bd 117/496: Clarify syntax table for syntactic fontification., ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 18e1e4a 107/496: Highlight attributes as keyword, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 98556c1 120/496: Start work on version 0.3, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 8be19fb 108/496: Highlight self and super as keyword, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 3caacf3 007/496: Highlight attributes and _ wildcards, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c8f1dbd 014/496: Update readme, ELPA Syncer, 2021/08/29