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

[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 {



reply via email to

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