branch: elpa/haskell-tng-mode commit 8e4f438dc4ed8feabd89d9f2d423e35cf3b6ef59 Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
don't continue indenting one liner types --- haskell-tng-rx.el | 2 ++ haskell-tng-smie.el | 13 ++++++++++++- test/haskell-tng-indent-test.el | 3 --- test/src/indentation.hs.append.indent | 8 ++++---- test/src/indentation.hs.insert.indent | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/haskell-tng-rx.el b/haskell-tng-rx.el index b745715..6feb315 100644 --- a/haskell-tng-rx.el +++ b/haskell-tng-rx.el @@ -59,6 +59,8 @@ give false positives." `(| (: symbol-start "--" (+ (not (any ?\n))) ?\n)) "Newline or line comment.") +;; TODO consider using rx's eval to reuse forms instead of backticks + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Compiled regexps ;; diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el index 595095b..641c30d 100644 --- a/haskell-tng-smie.el +++ b/haskell-tng-smie.el @@ -236,7 +236,9 @@ information, to aid in the creation of new rules." (not (equal prev "}")))) "|") - ((member parent '("::" "=>")) + ((and (member parent '("::" "=>")) + (not (haskell-tng-smie:search-prev-line + (rx (>= 2 (+ anything) "->"))))) "=>") ((equal parent "deriving") @@ -381,6 +383,7 @@ BEFORE is t if the line appears before the indentation." (let ((start (point)) relevant) (while (< (point) bound) + ;; TODO we the lexer instead of regexps, we're not barbarians (when (not (looking-at (rx (* space) (| "where" "do") word-end))) @@ -451,6 +454,14 @@ Inspired by `smie-indent--parent', which can only be used in (cons tok (haskell-tng-smie:ancestors (- n 1))) (list tok)))) +(defun haskell-tng-smie:search-prev-line (regexp) + "Search forward on the previous non-empty line" + (save-excursion + (beginning-of-line) + (forward-comment (- (point))) + (beginning-of-line) + (re-search-forward regexp (line-end-position) t))) + ;; SMIE wishlist, in order of desirability: ;; ;; 1. if the lexer could return lists of tokens. diff --git a/test/haskell-tng-indent-test.el b/test/haskell-tng-indent-test.el index a7909d4..f068a4f 100644 --- a/test/haskell-tng-indent-test.el +++ b/test/haskell-tng-indent-test.el @@ -77,9 +77,6 @@ ;; at point-max, so add some whitespace at the end. ;; ;; TODO fix the bug properly, in SMIE. - ;; - ;; TODO maybe we can have a better workaround by presenting tokens -1 - ;; from the end and enforcing a trailing newline. (save-excursion (insert "\n\n")))) (while (pcase mode diff --git a/test/src/indentation.hs.append.indent b/test/src/indentation.hs.append.indent index 9eaada9..fe7b3c6 100644 --- a/test/src/indentation.hs.append.indent +++ b/test/src/indentation.hs.append.indent @@ -247,9 +247,9 @@ v 1 v 1 typesig :: a -> b -> c -1 v +v -1 v +v types1 :: 1 v Monad m @@ -277,6 +277,6 @@ types3 :: (Monad m, MonadReader Foo m) => (?log :: HasLogger m) => 1 v a -> b -> c -1 v +v 1 -1 v \ No newline at end of file +v 1 \ No newline at end of file diff --git a/test/src/indentation.hs.insert.indent b/test/src/indentation.hs.insert.indent index 9b29da9..82df418 100644 --- a/test/src/indentation.hs.insert.indent +++ b/test/src/indentation.hs.insert.indent @@ -247,7 +247,7 @@ v 1 v 1 typesig :: a -> b -> c -1 v +v v types1 ::