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

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

[nongnu] elpa/zig-mode 1a4446af77: Handle multi-line if expressions bett


From: ELPA Syncer
Subject: [nongnu] elpa/zig-mode 1a4446af77: Handle multi-line if expressions better
Date: Wed, 4 Jan 2023 01:00:18 -0500 (EST)

branch: elpa/zig-mode
commit 1a4446af7777d04ca2d243681ac63b8c8b7f677b
Author: Michael Bartnett <michael.bartnett@gmail.com>
Commit: Joachim Schmidt <joachim.schmidt557@outlook.com>

    Handle multi-line if expressions better
    
    Exclude a line from being treated as a continuing expression if it
    starts with `else`. I'm not sure where else in the grammar this would
    show up.
    
    Also added quotes around ${EMACS} in run_tests.sh to make it easier to
    run the tests on windows (my Emacs is under "C:\Program Files").
---
 run_tests.sh |  2 +-
 tests.el     | 23 ++++++++++++++++++++++-
 zig-mode.el  |  2 +-
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/run_tests.sh b/run_tests.sh
index cb504585d8..d2db694413 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -19,4 +19,4 @@ INIT_PACKAGES="(progn \
       (package-install pkg))) \
   )"
 
-${EMACS} --eval "${INIT_PACKAGES}" --batch -l zig-mode.el -l tests.el -f 
ert-run-tests-batch-and-exit
+"${EMACS}" --eval "${INIT_PACKAGES}" --batch -l zig-mode.el -l tests.el -f 
ert-run-tests-batch-and-exit
diff --git a/tests.el b/tests.el
index 60a4caf3ea..a24c17ce9a 100644
--- a/tests.el
+++ b/tests.el
@@ -219,7 +219,7 @@ blarg(foo,
           quux,
       quux);"))
 
-(ert-deftest test-indent-if-else ()
+(ert-deftest test-indent-if-else-statement ()
   (zig-test-indent-region
    "
 fn sign(value: i32) i32 {
@@ -240,6 +240,27 @@ fn sign(value: i32) i32 {
     }
 }"))
 
+(ert-deftest test-indent-if-else-expression ()
+  (zig-test-indent-region
+   "
+fn sign(i: i32) i32 {
+return if (i == 0)
+0
+else if (i > 0)
+-1
+else
+-1;
+}"
+   "
+fn sign(i: i32) i32 {
+    return if (i == 0)
+        0
+    else if (i > 0)
+        -1
+    else
+        -1;
+}"))
+
 (ert-deftest test-indent-struct ()
   (zig-test-indent-region
    "
diff --git a/zig-mode.el b/zig-mode.el
index 32dc4c517b..277668174d 100644
--- a/zig-mode.el
+++ b/zig-mode.el
@@ -378,7 +378,7 @@ This is written mainly to be used as 
`end-of-defun-function' for Zig."
                   ;; expression from the previous line, false otherwise.
                   (is-expr-continutation
                    (and
-                    (not (looking-at "[]});]"))
+                    (not (looking-at "[]});]\\|else"))
                     (save-excursion
                       (zig-skip-backwards-past-whitespace-and-comments)
                       (when (> (point) 1)



reply via email to

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