branch: elpa/haskell-tng-mode commit 9ec48419d88ce2029660cd68d5f4eb1fac51d0ae Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
meh indentation --- haskell-tng-smie.el | 29 +++++++++++++++++------------ test/haskell-tng-indent-test.el | 16 ++++++++++++++++ test/src/layout.hs.insert.indent | 4 ++-- test/src/medley.hs.insert.indent | 16 ++++++++-------- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el index bfec21e..adb3de1 100644 --- a/haskell-tng-smie.el +++ b/haskell-tng-smie.el @@ -85,21 +85,26 @@ ))) ;; https://www.gnu.org/software/emacs/manual/html_mono/elisp.html#SMIE-Indentation -;; -;; ideas for an indentation tester -;; https://github.com/elixir-editors/emacs-elixir/blob/master/test/test-helper.el#L52-L63 (defun haskell-tng-smie:rules (method arg) ;; see docs for `smie-rules-function' ;; FIXME implement prime indentation - (pcase (cons method arg) - (`(:elem . basic) smie-indent-basic) - (`(,_ . ",") (smie-rule-separator method)) - (`(:after . "=") smie-indent-basic) - (`(:before . ,(or `"(" `"{")) - (if (smie-rule-hanging-p) (smie-rule-parent))) - (`(:before . "if") - (and (not (smie-rule-bolp)) (smie-rule-prev-p "else") - (smie-rule-parent))))) +;; (message "INDENT %S %S" method arg) + (pcase method + (:elem + (pcase arg + ('basic smie-indent-basic) + )) + + (:after + (pcase arg + ((or "::" "=" "where" "let" "do" "of") + ;; TODO module where should have column 0 + ;; TODO wtf is happening with the line "class Get a s where" + smie-indent-basic) + )) + + ;; TODO :before rules + )) (defconst haskell-tng-smie:return '(newline-and-indent) "Users with custom newlines should add their command.") diff --git a/test/haskell-tng-indent-test.el b/test/haskell-tng-indent-test.el index 10622bb..acb6560 100644 --- a/test/haskell-tng-indent-test.el +++ b/test/haskell-tng-indent-test.el @@ -31,6 +31,22 @@ ;; TODO more tests ) +;; TODO enable this test and get it passing, which requires a TAB command that +;; will insert whitespace and move point to end. Workaround is to use abbrevs or +;; yasnippets for things like "import" that have fixed indentations. +;; +;; (ert-deftest haskell-tng-indent-custom-tests () +;; (with-temp-buffer +;; (insert-file-contents (testdata "src/medley.hs")) +;; (haskell-tng-mode) +;; ;; import TAB should jump to column 17 +;; (goto-char 511) +;; (ert-simulate-command '(forward-word)) +;; (ert-simulate-command '(indent-for-tab-command)) +;; (ert-simulate-command '(indent-for-tab-command)) +;; (should (equal (point) 528)) +;; )) + (defun current-line-string () (buffer-substring-no-properties (line-beginning-position) diff --git a/test/src/layout.hs.insert.indent b/test/src/layout.hs.insert.indent index a0aa39a..9133f2a 100644 --- a/test/src/layout.hs.insert.indent +++ b/test/src/layout.hs.insert.indent @@ -1,7 +1,7 @@ -- Figure 2.1 from the Haskell2010 report v module AStack( Stack, push, pop, top, size ) where -v +. v data Stack a = Empty . v | MkStack a (Stack a) @@ -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 diff --git a/test/src/medley.hs.insert.indent b/test/src/medley.hs.insert.indent index 475b574..501e073 100644 --- a/test/src/medley.hs.insert.indent +++ b/test/src/medley.hs.insert.indent @@ -17,9 +17,9 @@ module Foo.Bar.Main , module Bloo.Foo . . v ) where -v . +. v -v . +. v import Control.Applicative (many, optional, pure, (<*>), (<|>)) v import Data.Foldable (traverse_) @@ -83,19 +83,19 @@ foo = "wobble (wibble)" v class Get a s where -. v +. v get :: Set s -> a . . v . 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 @@ -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) @@ -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