Skip to content

Fix module declaration indentation #1275

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 2 commits into from
Apr 10, 2016
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
41 changes: 27 additions & 14 deletions haskell-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ fixes up only indentation."
("type" . haskell-indentation-data)
("newtype" . haskell-indentation-data)
("import" . haskell-indentation-import)
("where" . haskell-indentation-toplevel-where)
("class" . haskell-indentation-class-declaration)
("instance" . haskell-indentation-class-declaration))
"Alist of toplevel keywords with associated parsers.")
Expand Down Expand Up @@ -684,21 +685,32 @@ For example
"Parse module declaration."
(haskell-indentation-with-starter
(lambda ()
(let ((current-indent (current-column)))
(haskell-indentation-read-next-token)
(when (string= current-token "(")
(haskell-indentation-list
#'haskell-indentation-module-export
")" ","))
(when (eq current-token 'end-tokens)
(haskell-indentation-add-indentation current-indent)
(throw 'parse-end nil))
(when (string= current-token "where")
(haskell-indentation-read-next-token)
(when (string= current-token "(")
(haskell-indentation-list
#'haskell-indentation-module-export
")" ","))
(if (string= current-token "where")
(haskell-indentation-read-next-token)
(when (eq current-token 'end-tokens)
(haskell-indentation-add-layout-indent)

(when (eq current-token 'end-tokens)
(when (member following-token '(value no-following-token "("))
(haskell-indentation-add-indentation
(+ starter-indent haskell-indentation-starter-offset))
(haskell-indentation-add-indentation
(+ left-indent haskell-indentation-starter-offset))
(throw 'parse-end nil))
(haskell-indentation-layout #'haskell-indentation-toplevel))))))
(haskell-indentation-add-layout-indent)
(throw 'parse-end nil))))))

(defun haskell-indentation-toplevel-where ()
"Parse 'where' that we may hit as a standalone in module
declaration."
(haskell-indentation-read-next-token)

(when (eq current-token 'end-tokens)
(haskell-indentation-add-layout-indent)
(throw 'parse-end nil)))

(defun haskell-indentation-module-export ()
"Parse export list."
Expand Down Expand Up @@ -938,7 +950,8 @@ layout starts."
(haskell-indentation-expression-token-p following-token))
(string= following-token ";")
(and (equal layout-indent 0)
(member following-token (mapcar #'car haskell-indentation-toplevel-list))))
(member following-token (mapcar #'car haskell-indentation-toplevel-list))
(not (string= following-token "where"))))
(haskell-indentation-add-layout-indent))
(throw 'return nil))
(t (throw 'return nil))))))
Expand Down
27 changes: 25 additions & 2 deletions tests/haskell-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ newtype instance T Char = TC Bool"
(3 0)
(4 0 26))

(hindent-test "52a* module simplest case two lines" "
(hindent-test "52a module simplest case two lines" "
module A.B
where"
(1 0)
Expand All @@ -910,7 +910,7 @@ module A.B where"
(1 0)
(2 0))

(hindent-test "52c* module with exports" "
(hindent-test "52c module with exports" "
module A.B
( x
, y
Expand Down Expand Up @@ -952,6 +952,29 @@ data Foo = Bar
(2 9)
(3 9))

(hindent-test "56 module name on next line" "
module
X"
(1 0)
(2 2))

(hindent-test "57 module continued" "
module X"
(1 0)
(2 2))

(hindent-test "58 module where same line" "
module X where"
(1 0)
(2 0))

(hindent-test "59 module where same line" "
module X
where"
(1 0)
(2 0)
(3 0))

(ert-deftest haskell-indentation-ret-indents ()
(with-temp-switch-to-buffer
(haskell-mode)
Expand Down