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

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

[nongnu] elpa/haskell-tng-mode a754020 144/385: indent alts will suggest


From: ELPA Syncer
Subject: [nongnu] elpa/haskell-tng-mode a754020 144/385: indent alts will suggest based on previous <- lines
Date: Tue, 5 Oct 2021 23:59:18 -0400 (EDT)

branch: elpa/haskell-tng-mode
commit a754020de0830c103eadf1e00762ca519e215389
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>

    indent alts will suggest based on previous <- lines
---
 haskell-tng-smie.el                   | 20 ++++++++++++++------
 test/src/indentation.hs.append.indent | 12 ++++++------
 test/src/indentation.hs.insert.indent | 10 +++++-----
 test/src/indentation.hs.reindent      | 10 +++++-----
 4 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el
index b4ebc93..d056b21 100644
--- a/haskell-tng-smie.el
+++ b/haskell-tng-smie.el
@@ -211,7 +211,7 @@ current line."
     (save-excursion
       (end-of-line 0)
       (re-search-backward haskell-tng:regexp:toplevel nil t)
-      (when-let (new (haskell-tng-smie:relevant-alts pos))
+      (when-let (new (haskell-tng-smie:relevant-alts pos t))
         (setq indents (append new indents))))
 
     ;; alts are easier to use when ordered
@@ -221,13 +221,15 @@ current line."
     (--each '(1 -1)
       (save-excursion
         (forward-line it)
-        (when-let (new (haskell-tng-smie:relevant-alts (point-at-eol)))
+        (when-let (new (haskell-tng-smie:relevant-alts (point-at-eol) (< it 
0)))
           (setq indents (append new indents)))))
 
     (-distinct indents)))
 
-(defun haskell-tng-smie:relevant-alts (bound)
-  "A list of indentation levels from point to BOUND."
+(defun haskell-tng-smie:relevant-alts (bound before)
+  "A list of indentation levels from point to BOUND.
+
+BEFORE is t if the line appears before the indentation."
   (let ((start (point))
         relevant)
     (while (< (point) bound)
@@ -235,8 +237,14 @@ current line."
              (looking-at
               (rx (* space) (| "where" "let" "do") word-end)))
         (push (current-indentation) relevant))
-      ;; TODO when there is a <- add its close +4 (possibly just for the
-      ;; immediately previous line).
+      (when
+          (and
+           before
+           (re-search-forward
+            (rx symbol-start "<-" (+ " "))
+            (line-end-position)
+            t))
+        (push (current-column) relevant))
       (forward-line))
     (goto-char start)
     (while (< (point) bound)
diff --git a/test/src/indentation.hs.append.indent 
b/test/src/indentation.hs.append.indent
index bd9418a..0a56dfa 100644
--- a/test/src/indentation.hs.append.indent
+++ b/test/src/indentation.hs.append.indent
@@ -33,9 +33,9 @@ v                     1 2
 basic_do = do
 1 v
   foo <- blah blah blah
-1 v
+2 v      1
   bar <- blah blah
-1 v
+2 v      1
          blah -- manual correction
 2 v      1
          blah -- manual correction
@@ -61,13 +61,13 @@ basic_do = do
 nested_do = -- manual correction
 1 v
   do foo <- blah
-1    v
+2    v      1
      do bar <- blah -- same level as foo
-2    1  v
+3    1  v   4  2
         baz -- same level as bar
-1    2  v
+1    2  v   3  4
 
-1    2  v
+1    2  v   3  4
 nested_where a b = foo a b
 v
   where -- TODO 2
diff --git a/test/src/indentation.hs.insert.indent 
b/test/src/indentation.hs.insert.indent
index 9578e89..9042620 100644
--- a/test/src/indentation.hs.insert.indent
+++ b/test/src/indentation.hs.insert.indent
@@ -33,7 +33,7 @@ v                     1 2
 basic_do = do
 1 v
   foo <- blah blah blah
-1 v
+2 v      1
   bar <- blah blah
 2 1      v
          blah -- manual correction
@@ -61,13 +61,13 @@ basic_do = do
 nested_do = -- manual correction
 1 v  2
   do foo <- blah
-2    v  1
+3    v  2   1
      do bar <- blah -- same level as foo
-2    1  v
+3    1  v   4  2
         baz -- same level as bar
-1    2  v
+1    2  v   3  4
 
-1    2  v
+1    2  v   3  4
 nested_where a b = foo a b
 1                  v
   where -- TODO 2
diff --git a/test/src/indentation.hs.reindent b/test/src/indentation.hs.reindent
index 6428102..8906b4b 100644
--- a/test/src/indentation.hs.reindent
+++ b/test/src/indentation.hs.reindent
@@ -32,7 +32,7 @@ v                     1 2
 
 v 1                   2 3
 basic_do = do
-1 v
+1 v      2
   foo <- blah blah blah
 v 1      2
   bar <- blah blah
@@ -62,13 +62,13 @@ v 2  13 45  6
 nested_do = -- manual correction
 v       1
   do foo <- blah
-v    1  2
+v    1  3   2
      do bar <- blah -- same level as foo
-v    2  1
+v    2  1   4  3
         baz -- same level as bar
-1    2  v
+1    2  v   3  4
 
-v    1  2
+v    1  2   3  4
 nested_where a b = foo a b
 1 v 2
   where -- TODO 2



reply via email to

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