diff --git a/haskell-indentation.el b/haskell-indentation.el index 296178ee7..51808404f 100644 --- a/haskell-indentation.el +++ b/haskell-indentation.el @@ -49,15 +49,6 @@ :group 'haskell :prefix "haskell-indentation-") -(defcustom haskell-indentation-indent-leftmost t - "Indent to the left margin after certain keywords. -For example after \"let .. in\", \"case .. of\"). If set to t it -will only indent to the left. If nil only relative to the -containing expression. If set to the symbol 'both then both -positions are allowed." - :type 'symbol - :group 'haskell-indentation) - (defcustom haskell-indentation-layout-offset 2 "Extra indentation to add before expressions in a Haskell layout list." :type 'integer @@ -73,11 +64,6 @@ positions are allowed." :type 'integer :group 'haskell-indentation) -(defcustom haskell-indentation-ifte-offset 2 - "Extra indentation after the keywords \"if\", \"then\", or \"else\"." - :type 'integer - :group 'haskell-indentation) - (defcustom haskell-indentation-where-pre-offset 2 "Extra indentation before the keyword \"where\"." :type 'integer @@ -520,7 +506,6 @@ fixes up only indentation." ("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 @@ -534,6 +519,10 @@ fixes up only indentation." ("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)) @@ -574,7 +563,7 @@ fixes up only indentation." (defun haskell-indentation-case-layout () "Parse layout list with case expressions." - (haskell-indentation-layout #'haskell-indentation-case-item)) + (haskell-indentation-layout #'haskell-indentation-case)) (defun haskell-indentation-lambda-maybe-lambdacase () "Parse lambda or lambda-case expression. @@ -761,7 +750,7 @@ Skip the keyword or parenthesis." ; FIXME: better description needed ((equal current-token end) (haskell-indentation-read-next-token)))))) -(defun haskell-indentation-case-item-alternative () +(defun haskell-indentation-case-alternative () "" ; FIXME (setq left-indent (current-column)) (haskell-indentation-separated #'haskell-indentation-expression "," nil) @@ -772,7 +761,7 @@ Skip the keyword or parenthesis." ; FIXME: better description needed ;; otherwise fallthrough )) -(defun haskell-indentation-case-item () +(defun haskell-indentation-case () "" ; FIXME (haskell-indentation-expression) (cond ((eq current-token 'end-tokens) @@ -780,7 +769,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-item-alternative "|" nil) + #'haskell-indentation-case-alternative "|" nil) nil)) ((string= current-token "->") (haskell-indentation-statement-right #'haskell-indentation-expression)) @@ -957,7 +946,7 @@ layout starts." (haskell-indentation-with-starter (lambda () (haskell-indentation-separated - #'haskell-indentation-case-item-alternative "|" nil)) + #'haskell-indentation-case-alternative "|" nil)) nil) (haskell-indentation-phrase-rest '(haskell-indentation-expression @@ -965,16 +954,6 @@ 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 @@ -1002,41 +981,14 @@ layout starts." (t (throw 'parse-end nil)))) ((null (cdr phrase))) ((equal (cadr phrase) current-token) - (let* ((on-new-line (= (current-column) - (haskell-indentation-current-indentation))) - (lines-between (- parse-line-number starter-line)) - (left-indent (if (<= lines-between 0) - left-indent - starter-indent))) - (haskell-indentation-read-next-token) - (when (eq current-token 'end-tokens) - (cond ((member (cadr phrase) '("then" "else")) - (haskell-indentation-add-indentation - (+ starter-indent haskell-indentation-ifte-offset))) - - ((member (cadr phrase) '("in" "->")) - ;; expression ending in another expression - (when (or (not haskell-indentation-indent-leftmost) - (eq haskell-indentation-indent-leftmost 'both)) - (haskell-indentation-add-indentation - (+ starter-indent haskell-indentation-starter-offset))) - (when haskell-indentation-indent-leftmost - (haskell-indentation-add-indentation - (if on-new-line - (+ left-indent haskell-indentation-starter-offset) - left-indent)))) - (t - (when (or (not haskell-indentation-indent-leftmost) - (eq haskell-indentation-indent-leftmost 'both)) - (haskell-indentation-add-indentation - (+ starter-indent haskell-indentation-starter-offset))) - (when haskell-indentation-indent-leftmost - (haskell-indentation-add-indentation - (if on-new-line - (+ left-indent haskell-indentation-starter-offset) - left-indent))))) - (throw 'parse-end nil)) - (setq phrase1 (cddr phrase)))) + (haskell-indentation-read-next-token) + (when (eq current-token 'end-tokens) + (haskell-indentation-add-indentation + (+ starter-indent haskell-indentation-starter-offset)) + (haskell-indentation-add-indentation + (+ left-indent haskell-indentation-starter-offset)) + (throw 'parse-end nil)) + (setq phrase1 (cddr phrase))) ((string= (cadr phrase) "in")))))) (defun haskell-indentation-add-indentation (indent) diff --git a/tests/haskell-indentation-tests.el b/tests/haskell-indentation-tests.el index 176a9fd47..f4d362cde 100644 --- a/tests/haskell-indentation-tests.el +++ b/tests/haskell-indentation-tests.el @@ -368,7 +368,7 @@ fun = \\x -> do" (hindent-test "16a A lambda"" fun = \\x ->" (1 0) - (2 2)) + (2 2 8)) (hindent-test "16u Lambda and a do block"" fun = \\x → do" @@ -378,7 +378,7 @@ fun = \\x → do" (hindent-test "16au A lambda"" fun = \\x →" (1 0) - (2 2)) + (2 2 8)) (hindent-test "17a* A type for a function"" fun :: Int @@ -514,7 +514,7 @@ x = let y z" (1 0) (2 4) - (3 6)) + (3 2 6)) (hindent-test "19c* \"let\" in a \"do\""" x = do @@ -826,7 +826,7 @@ fact n = case n of _ | n > 0 , True == True -> n * fact (n - 1)" (1 0) - (2 2) + (2 2 11) ;; returns (0 2 2 6), to investigate (3 0 2 6) (4 4)