Skip to content
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
107 changes: 55 additions & 52 deletions haskell-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 2 additions & 38 deletions tests/haskell-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ()
Expand Down