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

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

[nongnu] elpa/nix-mode bf027132d0 341/500: Merge pull request #83 from j


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode bf027132d0 341/500: Merge pull request #83 from j-piecuch/smie-tweaks
Date: Sat, 29 Jan 2022 08:27:19 -0500 (EST)

branch: elpa/nix-mode
commit bf027132d04a6b16aa49606b7e7ea7d7913cd9d4
Merge: e820157994 2bb0a0c1f4
Author: Elis Hirwing <elis@hirwing.se>
Commit: GitHub <noreply@github.com>

    Merge pull request #83 from j-piecuch/smie-tweaks
    
    Improve indentation of let expressions
---
 nix-mode.el                  | 28 ++++++++++++++-------------
 tests/nix-mode-tests.el      |  4 ++++
 tests/testcases/smie-let.nix | 45 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 13 deletions(-)

diff --git a/nix-mode.el b/nix-mode.el
index 4fa219ce14..6e354cc19e 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -433,15 +433,21 @@ STRING-TYPE type of string based off of Emacs syntax 
table types"
     (`(:after . ,(guard (string-match-p nix-smie-indent-tokens-re
                                         token)))
      (nix-smie--indent-anchor))
-    (`(:after . "in")
-     (cond
-      ((bolp) '(column . 0))
-      ((<= (line-beginning-position)
-           (save-excursion
-             (forward-word)
-             (smie-backward-sexp t)
-             (point)))
-       (smie-rule-parent))))
+    (`(,_ . "in")
+     (let ((bol (line-beginning-position)))
+       (forward-word)
+       ;; Go back to the corresponding "let".
+       (smie-backward-sexp t)
+       (pcase kind
+         (:before
+          (if (smie-rule-hanging-p)
+              (nix-smie--indent-anchor 0)
+            `(column . ,(current-column))))
+         (:after
+          (cond
+           ((bolp) '(column . 0))
+           ((<= bol (point))
+            `(column . ,(current-column))))))))
     (`(:after . "nonsep-;")
      (forward-char)
      (backward-sexp)
@@ -453,10 +459,6 @@ STRING-TYPE type of string based off of Emacs syntax table 
types"
          (nix-smie--indent-anchor)))
     (`(:after . ",")
      (smie-rule-parent tab-width))
-    (`(:before . "in")
-     (forward-word)
-     (smie-backward-sexp t)
-     (nix-smie--indent-anchor 0))
     (`(:before . ",")
      ;; The parent is either the enclosing "{" or some previous ",".
      ;; In both cases this is what we want to align to.
diff --git a/tests/nix-mode-tests.el b/tests/nix-mode-tests.el
index 2a58e0d67c..f3e4a77b98 100644
--- a/tests/nix-mode-tests.el
+++ b/tests/nix-mode-tests.el
@@ -197,5 +197,9 @@ Related issue: https://github.com/NixOS/nix-mode/issues/72";
   "Proper indentation of closing parentheses."
   (with-nix-mode-test ("smie-close-parens.nix" :indent 'smie-indent-line)))
 
+(ert-deftest nix-mode-test-let-smie ()
+  "Proper indentation of let expressions."
+  (with-nix-mode-test ("smie-let.nix" :indent 'smie-indent-line)))
+
 (provide 'nix-mode-tests)
 ;;; nix-mode-tests.el ends here
diff --git a/tests/testcases/smie-let.nix b/tests/testcases/smie-let.nix
new file mode 100644
index 0000000000..ab21db86b4
--- /dev/null
+++ b/tests/testcases/smie-let.nix
@@ -0,0 +1,45 @@
+let
+  foo = 42;
+  bar = let foo = 42; in
+        let bar = 42; in
+        42;
+  baz = 42;
+in
+let foo = 42; in
+let foo = 42;
+    bar = 42;
+in
+let foo = let
+      bar = 42;
+    in
+      42;
+    bar = 42;
+in
+let
+  foo = let
+    bar = 42;
+  in
+    42;
+  bar = 42;
+in
+let foo = 42;
+in
+{
+  foo = let
+    bar = 42;
+  in
+    42;
+
+  foo = let bar = 42;
+        in 42;
+
+  foo = let bar = 42; in
+        42;
+
+  foo =
+    let
+      foo = 42;
+      bar = 42;
+    in
+      42;
+}



reply via email to

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