diff --git a/haskell-indentation.el b/haskell-indentation.el index 18021e755..7d24cc099 100644 --- a/haskell-indentation.el +++ b/haskell-indentation.el @@ -969,60 +969,63 @@ layout starts." (apply-partially #'haskell-indentation-phrase-rest phrase) nil)) -(defun haskell-indentation-phrase-rest (phrase) +(defun haskell-indentation-phrase-rest (phrase1) "" ; FIXME - (let ((starter-line parse-line-number)) - (let ((current-indent (current-column))) - (funcall (car phrase))) - (cond - ((eq current-token 'end-tokens) - (cond ((null (cdr phrase))) ;; fallthrough - ((equal following-token (cadr phrase)) - (haskell-indentation-add-indentation starter-indent) - (throw 'parse-end nil)) - ((string= (cadr phrase) "in") - (when (= left-indent layout-indent) - (haskell-indentation-add-layout-indent) - (throw 'parse-end nil))) - (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 + (while phrase1 + (let ((starter-line parse-line-number) + (phrase phrase1)) + (setq phrase1 nil) + (let ((current-indent (current-column))) + (funcall (car phrase))) + (cond + ((eq current-token 'end-tokens) + (cond ((null (cdr phrase))) ;; fallthrough + ((equal following-token (cadr phrase)) + (haskell-indentation-add-indentation starter-indent) + (throw 'parse-end nil)) + ((string= (cadr phrase) "in") + (when (= left-indent layout-indent) + (haskell-indentation-add-layout-indent) + (throw 'parse-end nil))) + (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 - (if on-new-line - (+ left-indent haskell-indentation-starter-offset) - left-indent))))) - (throw 'parse-end nil)) - (haskell-indentation-phrase-rest (cddr phrase)))) - ((string= (cadr phrase) "in"))))) + (+ 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)))) + ((string= (cadr phrase) "in")))))) (defun haskell-indentation-add-indentation (indent) "" ; FIXME diff --git a/tests/haskell-indentation-tests.el b/tests/haskell-indentation-tests.el index b9ab31f8e..0bf6bf448 100644 --- a/tests/haskell-indentation-tests.el +++ b/tests/haskell-indentation-tests.el @@ -764,7 +764,7 @@ function = abc xyz" ((3 0) 0 7)) -(hindent-test "45* phrase should not eat whole stack" " +(hindent-test "45 phrase should not eat whole stack" " function = if True then True @@ -847,44 +847,8 @@ function = if True then True else - if True - then True - else - if True - then True - else - if True - then True - else - if True - then True - else - if True - then True - else - if True - then True - else - if True - then True - else - if True - then True - else - if True - then True - else - if True - then True - else - if True - then True - else - if True - then True - else " - ((118 0) 0 4)) + ((84 0) 4)) (ert-deftest haskell-indentation-ret-indents ()