Skip to content

Commit b3a9e1b

Browse files
committed
Fix module declaration indentation
1 parent 547ac4f commit b3a9e1b

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

haskell-indentation.el

+27-14
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ fixes up only indentation."
495495
("type" . haskell-indentation-data)
496496
("newtype" . haskell-indentation-data)
497497
("import" . haskell-indentation-import)
498+
("where" . haskell-indentation-toplevel-where)
498499
("class" . haskell-indentation-class-declaration)
499500
("instance" . haskell-indentation-class-declaration))
500501
"Alist of toplevel keywords with associated parsers.")
@@ -684,21 +685,32 @@ For example
684685
"Parse module declaration."
685686
(haskell-indentation-with-starter
686687
(lambda ()
687-
(let ((current-indent (current-column)))
688-
(haskell-indentation-read-next-token)
689-
(when (string= current-token "(")
690-
(haskell-indentation-list
691-
#'haskell-indentation-module-export
692-
")" ","))
693-
(when (eq current-token 'end-tokens)
694-
(haskell-indentation-add-indentation current-indent)
695-
(throw 'parse-end nil))
696-
(when (string= current-token "where")
688+
(haskell-indentation-read-next-token)
689+
(when (string= current-token "(")
690+
(haskell-indentation-list
691+
#'haskell-indentation-module-export
692+
")" ","))
693+
(if (string= current-token "where")
697694
(haskell-indentation-read-next-token)
698-
(when (eq current-token 'end-tokens)
699-
(haskell-indentation-add-layout-indent)
695+
696+
(when (eq current-token 'end-tokens)
697+
(when (member following-token '(value no-following-token "("))
698+
(haskell-indentation-add-indentation
699+
(+ starter-indent haskell-indentation-starter-offset))
700+
(haskell-indentation-add-indentation
701+
(+ left-indent haskell-indentation-starter-offset))
700702
(throw 'parse-end nil))
701-
(haskell-indentation-layout #'haskell-indentation-toplevel))))))
703+
(haskell-indentation-add-layout-indent)
704+
(throw 'parse-end nil))))))
705+
706+
(defun haskell-indentation-toplevel-where ()
707+
"Parse 'where' that we may hit as a standalone in module
708+
declaration."
709+
(haskell-indentation-read-next-token)
710+
711+
(when (eq current-token 'end-tokens)
712+
(haskell-indentation-add-layout-indent)
713+
(throw 'parse-end nil)))
702714

703715
(defun haskell-indentation-module-export ()
704716
"Parse export list."
@@ -938,7 +950,8 @@ layout starts."
938950
(haskell-indentation-expression-token-p following-token))
939951
(string= following-token ";")
940952
(and (equal layout-indent 0)
941-
(member following-token (mapcar #'car haskell-indentation-toplevel-list))))
953+
(member following-token (mapcar #'car haskell-indentation-toplevel-list))
954+
(not (string= following-token "where"))))
942955
(haskell-indentation-add-layout-indent))
943956
(throw 'return nil))
944957
(t (throw 'return nil))))))

tests/haskell-indentation-tests.el

+4-4
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ newtype instance T Char = TC Bool"
898898
(3 0)
899899
(4 0 26))
900900

901-
(hindent-test "52a* module simplest case two lines" "
901+
(hindent-test "52a module simplest case two lines" "
902902
module A.B
903903
where"
904904
(1 0)
@@ -910,7 +910,7 @@ module A.B where"
910910
(1 0)
911911
(2 0))
912912

913-
(hindent-test "52c* module with exports" "
913+
(hindent-test "52c module with exports" "
914914
module A.B
915915
( x
916916
, y
@@ -958,7 +958,7 @@ module
958958
(1 0)
959959
(2 2))
960960

961-
(hindent-test "57* module continued" "
961+
(hindent-test "57 module continued" "
962962
module X"
963963
(1 0)
964964
(2 2))
@@ -968,7 +968,7 @@ module X where"
968968
(1 0)
969969
(2 0))
970970

971-
(hindent-test "59* module where same line" "
971+
(hindent-test "59 module where same line" "
972972
module X
973973
where"
974974
(1 0)

0 commit comments

Comments
 (0)