Skip to content

Case expression indentation fix #1024

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
Dec 11, 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
25 changes: 16 additions & 9 deletions haskell-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ indentation points to the right, we switch going to the left."
("type" . haskell-indentation-data)
("newtype" . haskell-indentation-data)
("if" . haskell-indentation-if)
("case" . haskell-indentation-case)
("let" .
,(apply-partially 'haskell-indentation-phrase
'(haskell-indentation-declaration-layout
Expand All @@ -532,10 +533,6 @@ indentation points to the right, we switch going to the left."
("rec" .
,(apply-partially 'haskell-indentation-with-starter
'haskell-indentation-expression-layout))
("case" .
,(apply-partially 'haskell-indentation-phrase
'(haskell-indentation-expression
"of" haskell-indentation-case-layout)))
("\\" .
,(apply-partially 'haskell-indentation-with-starter
'haskell-indentation-lambda-maybe-lambdacase))
Expand Down Expand Up @@ -576,7 +573,7 @@ indentation points to the right, we switch going to the left."

(defun haskell-indentation-case-layout ()
"Parse layout list with case expressions."
(haskell-indentation-layout #'haskell-indentation-case))
(haskell-indentation-layout #'haskell-indentation-case-item))

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

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

(defun haskell-indentation-case ()
(defun haskell-indentation-case-item ()
"" ; FIXME
(haskell-indentation-expression)
(cond ((eq current-token 'end-tokens)
(haskell-indentation-add-indentation current-indent))
((string= current-token "|")
(haskell-indentation-with-starter
(apply-partially #'haskell-indentation-separated
#'haskell-indentation-case-alternative "|" nil)
#'haskell-indentation-case-item-alternative "|" nil)
nil))
((string= current-token "->")
(haskell-indentation-statement-right #'haskell-indentation-expression))
Expand Down Expand Up @@ -953,14 +950,24 @@ layout starts."
(haskell-indentation-with-starter
(lambda ()
(haskell-indentation-separated
#'haskell-indentation-case-alternative "|" nil))
#'haskell-indentation-case-item-alternative "|" nil))
nil)
(haskell-indentation-phrase-rest
'(haskell-indentation-expression
"then" haskell-indentation-expression
"else" haskell-indentation-expression))))
nil))

(defun haskell-indentation-case ()
"" ; FIXME
(haskell-indentation-with-starter
(lambda ()
(haskell-indentation-expression)
(when (string= current-token "of")
(haskell-indentation-with-starter
#'haskell-indentation-case-layout)))
nil))

(defun haskell-indentation-phrase (phrase)
"" ; FIXME
(haskell-indentation-with-starter
Expand Down
6 changes: 3 additions & 3 deletions tests/haskell-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ function =
"
(84 4))

(hindent-test "46* case expression with paths on their own lines" "
(hindent-test "46 case expression with paths on their own lines" "
fact n =
case n of
0 -> 1
Expand All @@ -861,8 +861,8 @@ fact n =
(1 0)
(2 2)
(3 4)
(4 0 2 4 9)
(5 0 2 4 9))
(4 0 2 4 6)
(5 0 2 4 6))

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