Skip to content

Commit b8ca636

Browse files
committed
Merge pull request #1024 from gracjan/pr-case-indents
Case expression indentation fix
2 parents d99af72 + 089c941 commit b8ca636

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

haskell-indentation.el

+16-9
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ indentation points to the right, we switch going to the left."
519519
("type" . haskell-indentation-data)
520520
("newtype" . haskell-indentation-data)
521521
("if" . haskell-indentation-if)
522+
("case" . haskell-indentation-case)
522523
("let" .
523524
,(apply-partially 'haskell-indentation-phrase
524525
'(haskell-indentation-declaration-layout
@@ -532,10 +533,6 @@ indentation points to the right, we switch going to the left."
532533
("rec" .
533534
,(apply-partially 'haskell-indentation-with-starter
534535
'haskell-indentation-expression-layout))
535-
("case" .
536-
,(apply-partially 'haskell-indentation-phrase
537-
'(haskell-indentation-expression
538-
"of" haskell-indentation-case-layout)))
539536
("\\" .
540537
,(apply-partially 'haskell-indentation-with-starter
541538
'haskell-indentation-lambda-maybe-lambdacase))
@@ -576,7 +573,7 @@ indentation points to the right, we switch going to the left."
576573

577574
(defun haskell-indentation-case-layout ()
578575
"Parse layout list with case expressions."
579-
(haskell-indentation-layout #'haskell-indentation-case))
576+
(haskell-indentation-layout #'haskell-indentation-case-item))
580577

581578
(defun haskell-indentation-lambda-maybe-lambdacase ()
582579
"Parse lambda or lambda-case expression.
@@ -759,7 +756,7 @@ Skip the keyword or parenthesis." ; FIXME: better description needed
759756
((equal current-token end)
760757
(haskell-indentation-read-next-token))))))
761758

762-
(defun haskell-indentation-case-alternative ()
759+
(defun haskell-indentation-case-item-alternative ()
763760
"" ; FIXME
764761
(setq left-indent (current-column))
765762
(haskell-indentation-separated #'haskell-indentation-expression "," nil)
@@ -770,15 +767,15 @@ Skip the keyword or parenthesis." ; FIXME: better description needed
770767
;; otherwise fallthrough
771768
))
772769

773-
(defun haskell-indentation-case ()
770+
(defun haskell-indentation-case-item ()
774771
"" ; FIXME
775772
(haskell-indentation-expression)
776773
(cond ((eq current-token 'end-tokens)
777774
(haskell-indentation-add-indentation current-indent))
778775
((string= current-token "|")
779776
(haskell-indentation-with-starter
780777
(apply-partially #'haskell-indentation-separated
781-
#'haskell-indentation-case-alternative "|" nil)
778+
#'haskell-indentation-case-item-alternative "|" nil)
782779
nil))
783780
((string= current-token "->")
784781
(haskell-indentation-statement-right #'haskell-indentation-expression))
@@ -953,14 +950,24 @@ layout starts."
953950
(haskell-indentation-with-starter
954951
(lambda ()
955952
(haskell-indentation-separated
956-
#'haskell-indentation-case-alternative "|" nil))
953+
#'haskell-indentation-case-item-alternative "|" nil))
957954
nil)
958955
(haskell-indentation-phrase-rest
959956
'(haskell-indentation-expression
960957
"then" haskell-indentation-expression
961958
"else" haskell-indentation-expression))))
962959
nil))
963960

961+
(defun haskell-indentation-case ()
962+
"" ; FIXME
963+
(haskell-indentation-with-starter
964+
(lambda ()
965+
(haskell-indentation-expression)
966+
(when (string= current-token "of")
967+
(haskell-indentation-with-starter
968+
#'haskell-indentation-case-layout)))
969+
nil))
970+
964971
(defun haskell-indentation-phrase (phrase)
965972
"" ; FIXME
966973
(haskell-indentation-with-starter

tests/haskell-indentation-tests.el

+3-3
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ function =
852852
"
853853
(84 4))
854854

855-
(hindent-test "46* case expression with paths on their own lines" "
855+
(hindent-test "46 case expression with paths on their own lines" "
856856
fact n =
857857
case n of
858858
0 -> 1
@@ -861,8 +861,8 @@ fact n =
861861
(1 0)
862862
(2 2)
863863
(3 4)
864-
(4 0 2 4 9)
865-
(5 0 2 4 9))
864+
(4 0 2 4 6)
865+
(5 0 2 4 6))
866866

867867
(ert-deftest haskell-indentation-ret-indents ()
868868
(switch-to-buffer (get-buffer-create "source.hs"))

0 commit comments

Comments
 (0)