From 6feda234c77ff69315f97ea1df0c4a219cee7d08 Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Fri, 11 Dec 2015 22:43:05 +0100 Subject: [PATCH 1/2] Handle case expressions properly --- haskell-indentation.el | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/haskell-indentation.el b/haskell-indentation.el index 80e566c4d..b282ff546 100644 --- a/haskell-indentation.el +++ b/haskell-indentation.el @@ -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 @@ -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)) @@ -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. @@ -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) @@ -770,7 +767,7 @@ 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) @@ -778,7 +775,7 @@ Skip the keyword or parenthesis." ; FIXME: better description needed ((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)) @@ -953,7 +950,7 @@ 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 @@ -961,6 +958,16 @@ layout starts." "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 From 089c941ddae9f334f181a1bb9c08944d754b6d3d Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Fri, 11 Dec 2015 22:43:25 +0100 Subject: [PATCH 2/2] Handle case expressions properly, tests --- tests/haskell-indentation-tests.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/haskell-indentation-tests.el b/tests/haskell-indentation-tests.el index c0e3a78f1..158e7b6f0 100644 --- a/tests/haskell-indentation-tests.el +++ b/tests/haskell-indentation-tests.el @@ -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 @@ -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"))