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

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

[nongnu] elpa/haskell-tng-mode ddd0706 108/385: suggest next line indent


From: ELPA Syncer
Subject: [nongnu] elpa/haskell-tng-mode ddd0706 108/385: suggest next line indentation
Date: Tue, 5 Oct 2021 23:59:11 -0400 (EDT)

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

    suggest next line indentation
---
 haskell-tng-smie.el              | 17 ++++++++++----
 test/src/layout.hs.insert.indent |  6 ++---
 test/src/medley.hs.insert.indent | 50 ++++++++++++++++++++--------------------
 3 files changed, 40 insertions(+), 33 deletions(-)

diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el
index 84f4be4..53dc63f 100644
--- a/haskell-tng-smie.el
+++ b/haskell-tng-smie.el
@@ -138,17 +138,24 @@
   "Returns a list of alternative indentation levels for the
 current line."
   (save-excursion
-    (let ((end (line-number-at-pos))
+    (let ((the-line (line-number-at-pos))
           indents)
       (when (re-search-backward haskell-tng:regexp:toplevel nil t)
-        (while (< (line-number-at-pos) end)
+        (while (< (line-number-at-pos) the-line)
           ;; TODO add positions of WLDOS
           ;; TODO special cases for import (unless grammar handles it)
           ;; TODO special cases for multiple whitespaces (implies alignment)
-          ;; TODO end +- 2
+          ;; TODO the-line +- 2
           (push (current-indentation) indents)
-          (forward-line))
-        (-distinct (-sort '< indents))))))
+          (forward-line)))
+
+      ;; indentation of the next line is common for insert edits
+      (forward-line)
+      (forward-comment (point-max))
+      (when (not (eq the-line (line-number-at-pos)))
+        (push (current-indentation) indents))
+
+      (-distinct indents))))
 
 (defun haskell-tng-smie:setup ()
   (setq-local smie-indent-basic 2)
diff --git a/test/src/layout.hs.insert.indent b/test/src/layout.hs.insert.indent
index 9133f2a..18cd6ad 100644
--- a/test/src/layout.hs.insert.indent
+++ b/test/src/layout.hs.insert.indent
@@ -3,7 +3,7 @@ v
 module AStack( Stack, push, pop, top, size ) where
 . v
 data Stack a = Empty
-.                v
+.            .   v
              | MkStack a (Stack a)
 .            v
 
@@ -17,7 +17,7 @@ v
 size :: Stack a -> Int
 v
 size s = length (stkToLst s)  where
-. v
+. v        .
            stkToLst  Empty         = []
 .          .                           v
            stkToLst (MkStack x s)  = x:xs where xs = stkToLst s
@@ -27,7 +27,7 @@ size s = length (stkToLst s)  where
 pop :: Stack a -> (a, Stack a)
 v
 pop (MkStack x s)
-.   v
+. . v
   = (x, case s of r -> i r where i x = x) -- (pop Empty) is an error
 . .   v
 
diff --git a/test/src/medley.hs.insert.indent b/test/src/medley.hs.insert.indent
index b077e30..2469ed6 100644
--- a/test/src/medley.hs.insert.indent
+++ b/test/src/medley.hs.insert.indent
@@ -7,7 +7,7 @@ v
 -- | This file is a medley of various constructs and some corner cases
 v
 module Foo.Bar.Main
-.              v
+. .            v
   ( Wibble(..), Wobble(Wobb, (!!!)), Woo
 . .                                    v
   -- * Operations
@@ -35,7 +35,7 @@ v
 import  qualified  Options.Applicative  as  Opts
 v
 import qualified Options.Divisible -- wibble (wobble)
-.      v
+.  .   v
    as Div
 v  .
 import qualified ProfFile.App        hiding (as, hiding, qualified)
@@ -89,19 +89,19 @@ class Get a s where
 
 . v
 instance {-# OVERLAPS #-} Get a (a ': s) where
-.   v
+. . v
   get (Ext a _) = a
 . .                 v
 
 . v
 instance {-# OVERLAPPABLE #-} Get a s => Get a (b ': s) where
-.   v
+. . v
   get (Ext _ xs) = get xs
 . .                    v
 
 . v
 data Options = Options
-.                v
+. .              v
   { optionsReportType      :: ReportType
 . .                        v
   , optionsProfFile        :: Maybe FilePath
@@ -115,7 +115,7 @@ data Options = Options
 
 v .
 class  (Eq a) => Ord a  where
-.   v
+. . v
   (<), (<=), (>=), (>)  :: a -> a -> Bool
 . .                                    v
   max @Foo, min        :: a -> a -> a
@@ -123,7 +123,7 @@ class  (Eq a) => Ord a  where
 
 . v
 instance (Eq a) => Eq (Tree a) where
-.   v
+. . v
   Leaf a         == Leaf b          =  a == b
 . .                                           v
   (Branch l1 r1) == (Branch l2 r2)  =  (l1==l2) && (r1==r2)
@@ -133,7 +133,7 @@ instance (Eq a) => Eq (Tree a) where
 
 . v
 data ReportType = Alloc   -- ^ Report allocations, percent
-.                   v
+.               .   v
                 | Entries -- ^ Report entries, number
 .               v
                 | Time    -- ^ Report time spent in closure, percent
@@ -147,7 +147,7 @@ data ReportType = Alloc   -- ^ Report allocations, percent
 
 v               .
 type family G a where
-.   v
+. . v
   G Int = Bool
 . .         v
   G a   = Char
@@ -155,7 +155,7 @@ type family G a where
 
 . v
 data Flobble = Flobble
-.                v
+. .              v
   deriving (Eq) via (NonNegative (Large Int))
 . v
   deriving stock (Floo)
@@ -169,9 +169,9 @@ newtype Flobby = Flobby
 
 v
 foo ::
-.   v
+..  v
  Wibble -- wibble
-.v
+.v  .
     -> Wobble -- wobble
 ..  .    v
     -> Wobble -- wobble
@@ -191,7 +191,7 @@ v.  .
 
 v.  .
 newtype TestApp
-.       v
+.  .    v
    (logger :: TestLogger)
 .  v
    (scribe :: TestScribe)
@@ -207,9 +207,9 @@ v  .
 optionsParser :: Opts.Parser Options
 v
 optionsParser = Options
-.                 v
-  <$> (Opts.flag' Alloc (Opts.long "alloc" <> Opts.help "wibble")
 . .               v
+  <$> (Opts.flag' Alloc (Opts.long "alloc" <> Opts.help "wibble")
+. .    .          v
        <|> Opts.flag' Entries (Opts.long "entry" <> Opts.help "wobble")
 . .    .              v
        <|> Opts.flag' Bytes   (Opts.long "bytes" <> Opts.help "i'm a fish"))
@@ -217,9 +217,9 @@ optionsParser = Options
   <*> optional
 . .    .v
         (Opts.strArgument
-. .    ..       v
-          (Opts.metavar "MY-FILE" <>
 . .    .. .     v
+          (Opts.metavar "MY-FILE" <>
+. .    .. ..    v
            Opts.help "meh"))
 . .    .v ..
 
@@ -229,9 +229,9 @@ type PhantomThing
 
 v
 type SomeApi =
-. v
+. v    .
        "thing" :> Capture "bar" Index :> QueryParam "wibble" Text
-.      .       v
+.      .       v                               .
                                                :> QueryParam "wobble" Natural
 .      .                                       v
                                                :> Header TracingHeader 
TracingId
@@ -239,9 +239,9 @@ type SomeApi =
                                                :> ThingHeader
 .      .                                       v
                                                :> Get '[JSON] (The ReadResult)
-.      .                                       v
+. .    .                                       v
   :<|> "thing" :> ReqBody '[JSON] Request
-. v    .                                       .
+. v    .              .                        .
                       :> Header TracingHeader TracingId
 . .    .              v                        .
                       :> SpecialHeader
@@ -259,13 +259,13 @@ deriving newtype instance FromJSON Treble
 
 v
 foo = bar
-.       v
+. .     v
   where baz = _
-. .             v
+. .     .       v
   -- checking that comments are ignored in layout
-. .             v
+. .     .       v
   -- and that a starting syntax entry is ok
-. .             v
+. .     .       v
         (+) = _
 . .     .       v
 



reply via email to

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