branch: elpa/haskell-tng-mode commit 4e1f51c9205e9b40e2bbb68ab5e71de54756c050 Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
indent is deriving aware --- haskell-tng-smie.el | 21 ++++++++++++++------- test/haskell-tng-indent-test.el | 3 --- test/src/indentation.hs | 5 +++++ test/src/indentation.hs.append.indent | 10 ++++++++++ test/src/indentation.hs.insert.indent | 10 ++++++++++ test/src/indentation.hs.layout | 5 +++++ test/src/indentation.hs.lexer | 5 +++++ test/src/indentation.hs.reindent | 12 +++++++++++- test/src/indentation.hs.sexps | 5 +++++ test/src/indentation.hs.syntax | 5 +++++ 10 files changed, 70 insertions(+), 11 deletions(-) diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el index b4af17e..15d27de 100644 --- a/haskell-tng-smie.el +++ b/haskell-tng-smie.el @@ -69,10 +69,11 @@ (id "':" infixexp) ;; DataKinds (id "SYMID" infixexp)) - (adt - ("data" id "=" cop)) - (cop - (cop "|" cop)) + (data + ("data" id "=" cons)) + (cons + (id "deriving" list) + (cons "|" cons)) ;; WLDOs (wldo @@ -164,13 +165,17 @@ information, to aid in the creation of new rules." (grand (cadr parents)) (prev (save-excursion (car (smie-indent-backward-token)))) + (psexp (save-excursion + (caddr (haskell-tng:until + (smie-backward-sexp) + (bobp))))) (next (save-excursion (car (smie-indent-forward-token))))) (when haskell-tng-smie:debug (with-current-buffer haskell-tng-smie:debug - (insert (format " ^^: %S\n ^: %S\n -1: %S\n +1: %S\n" - grand parent prev next)))) + (insert (format " ^^: %S\n ^: %S\n -1: %S\n -(: %S\n +1: %S\n" + grand parent prev psexp next)))) (cond ((or @@ -181,12 +186,14 @@ information, to aid in the creation of new rules." ",") ((or (equal parent "|") - ;; TODO not if there is a deriving keyword somewhere (and (equal parent "=") (equal grand "data") (not (equal prev "}")))) "|") + ((equal parent "deriving") + ";") + ((member next '(";" "}")) ;; TODO we could do semantic indentation here ;; diff --git a/test/haskell-tng-indent-test.el b/test/haskell-tng-indent-test.el index da015fc..cd2e0a3 100644 --- a/test/haskell-tng-indent-test.el +++ b/test/haskell-tng-indent-test.el @@ -14,11 +14,8 @@ ;; FIXME implement more indentation rules ;; -;; TODO records -;; TODO coproducts ;; TODO multiline type signatures ;; TODO if/then/else -;; TODO data: one conid ~> record, multi ~> coproduct ;; TODO reindenting needs attention, it's all over the radar diff --git a/test/src/indentation.hs b/test/src/indentation.hs index b2de628..3a95061 100644 --- a/test/src/indentation.hs +++ b/test/src/indentation.hs @@ -87,6 +87,11 @@ data Record2 = Record2 , fieldB :: String } +data Record3 = Record3 String Text + deriving (Show) + +data Record4 = Record3 String Text deriving (Show) + lists1 = [ foo , bar , [ blah diff --git a/test/src/indentation.hs.append.indent b/test/src/indentation.hs.append.indent index 1f9b5ee..c52975e 100644 --- a/test/src/indentation.hs.append.indent +++ b/test/src/indentation.hs.append.indent @@ -176,6 +176,16 @@ data Record2 = Record2 v 1 v 1 +data Record3 = Record3 String Text +1 v + deriving (Show) +v 1 + +v 1 +data Record4 = Record3 String Text deriving (Show) +v + +v lists1 = [ foo 1 v , bar diff --git a/test/src/indentation.hs.insert.indent b/test/src/indentation.hs.insert.indent index 4ef4d09..e9936c4 100644 --- a/test/src/indentation.hs.insert.indent +++ b/test/src/indentation.hs.insert.indent @@ -176,6 +176,16 @@ data Record2 = Record2 v 1 v 1 +data Record3 = Record3 String Text +2 v 1 + deriving (Show) +v 1 + +v 1 +data Record4 = Record3 String Text deriving (Show) +v + +v lists1 = [ foo 1 v , bar diff --git a/test/src/indentation.hs.layout b/test/src/indentation.hs.layout index 7e363b8..a252c8d 100644 --- a/test/src/indentation.hs.layout +++ b/test/src/indentation.hs.layout @@ -87,6 +87,11 @@ module Indentation where , fieldB :: String } +;data Record3 = Record3 String Text + deriving (Show) + +;data Record4 = Record3 String Text deriving (Show) + ;lists1 = [ foo , bar , [ blah diff --git a/test/src/indentation.hs.lexer b/test/src/indentation.hs.lexer index 16bbe91..cd8d2e8 100644 --- a/test/src/indentation.hs.lexer +++ b/test/src/indentation.hs.lexer @@ -87,6 +87,11 @@ VARID :: CONID , VARID :: CONID » +; data CONID = CONID CONID CONID +deriving « CONID » + +; data CONID = CONID CONID CONID deriving « CONID » + ; VARID = « VARID , VARID , « VARID diff --git a/test/src/indentation.hs.reindent b/test/src/indentation.hs.reindent index aac52c2..af1c5a31 100644 --- a/test/src/indentation.hs.reindent +++ b/test/src/indentation.hs.reindent @@ -176,7 +176,17 @@ data Record2 = Record2 } v 1 -v 2 1 +v 2 1 +data Record3 = Record3 String Text +1 v + deriving (Show) +v 1 + +v 1 +data Record4 = Record3 String Text deriving (Show) +v + +v 1 lists1 = [ foo 1 v , bar diff --git a/test/src/indentation.hs.sexps b/test/src/indentation.hs.sexps index 952103e..ee7ba3c 100644 --- a/test/src/indentation.hs.sexps +++ b/test/src/indentation.hs.sexps @@ -87,6 +87,11 @@ , (fieldB) (::) (String) })) +(data (Record3) = ((Record3) (String) (Text) + (deriving) ((Show)))) + +(data (Record4) = ((Record3) (String) (Text) (deriving) ((Show)))) + ((lists1) = ([ (foo) , (bar) , ([ (blah) diff --git a/test/src/indentation.hs.syntax b/test/src/indentation.hs.syntax index 4fbb203..7c8efad 100644 --- a/test/src/indentation.hs.syntax +++ b/test/src/indentation.hs.syntax @@ -87,6 +87,11 @@ wwww wwwwwww _ wwwwwww> . wwwwww __ wwwwww> )> > +wwww wwwwwww _ wwwwwww wwwwww wwww> + wwwwwwww (wwww)> +> +wwww wwwwwww _ wwwwwww wwwwww wwww wwwwwwww (wwww)> +> wwwwww _ ( www> . www> . ( wwww>