Skip to content

Align -> and => with :: in type declaration #680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions haskell-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ the current buffer."
;; tokens in type declarations
(defconst haskell-indentation-type-list
'(("::" . (lambda () (haskell-indentation-with-starter
(lambda () (haskell-indentation-separated #'haskell-indentation-type "->")))))
(lambda () (haskell-indentation-separated #'haskell-indentation-type '("->" "=>"))))))
("(" . (lambda () (haskell-indentation-list #'haskell-indentation-type ")" ",")))
("[" . (lambda () (haskell-indentation-list #'haskell-indentation-type "]" ",")))
("{" . (lambda () (haskell-indentation-list #'haskell-indentation-type "}" ",")))))
Expand Down Expand Up @@ -634,7 +634,7 @@ the current buffer."
("where" . (lambda () (haskell-indentation-with-starter
#'haskell-indentation-declaration-layout nil t)))
("::" . (lambda () (haskell-indentation-with-starter
(lambda () (haskell-indentation-separated #'haskell-indentation-type "->")))))
(lambda () (haskell-indentation-separated #'haskell-indentation-type '("->" "=>"))))))
("=" . (lambda () (haskell-indentation-statement-right #'haskell-indentation-expression)))
("<-" . (lambda () (haskell-indentation-statement-right #'haskell-indentation-expression)))
("(" . (lambda () (haskell-indentation-list #'haskell-indentation-expression ")" '(list "," "->"))))
Expand Down Expand Up @@ -699,7 +699,7 @@ the current buffer."
((eq current-token 'end-tokens)
(when (member following-token
'(value operator no-following-token
"->" "(" "[" "{" "::"))
"(" "[" "{" "::"))
(haskell-indentation-add-indentation current-indent))
(throw 'return nil))
(t (let ((parser (assoc current-token haskell-indentation-type-list)))
Expand Down Expand Up @@ -1164,7 +1164,7 @@ the current buffer."
(match-string-no-properties 1))
((looking-at "[][(){}[,;]")
(match-string-no-properties 0))
((looking-at "\\(\\\\\\|->\\|→\\|<-\\|←\\|::\\|∷\\|=\\||\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
((looking-at "\\(\\\\\\|->\\|=>\\|→\\|<-\\|←\\|::\\|∷\\|=\\||\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
(match-string-no-properties 1))
((looking-at "\\(→\\|←\\|∷\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
(let ((tok (match-string-no-properties 1)))
Expand Down
29 changes: 29 additions & 0 deletions tests/haskell-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,32 @@ Example of lines:
(haskell-indentation-check
"fun = \x ->"
" ^"))

(ert-deftest haskell-indentation-check-17a ()
"A type for a function"
(haskell-indentation-check
"fun :: Int"
" -> Int"
" ^"))

(ert-deftest haskell-indentation-check-17b ()
"A type for a function with context"
(haskell-indentation-check
"fun :: Monad m"
" => Int"
" ^"))

(ert-deftest haskell-indentation-check-17c ()
"A type for a function with complicated context"
(haskell-indentation-check
"fun :: (Monad m, MonadBaseControl IO m, MyMonad (A v) m)"
" => MyMonad (A v) m"
" ^"))

(ert-deftest haskell-indentation-check-17d ()
"A type for a function with param and a complicated context"
(haskell-indentation-check
"fun :: (Monad m, MonadBaseControl IO m, MyMonad (A v) m)"
" => MyMonad (A v) m"
" -> m (Maybe a)"
" ^"))