Skip to content

Commit 745fa18

Browse files
committed
Simplify haskell-indentation-phrase-rest
1 parent 6df1bc0 commit 745fa18

File tree

2 files changed

+12
-48
lines changed

2 files changed

+12
-48
lines changed

haskell-indentation.el

+8-44
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,6 @@
4949
:group 'haskell
5050
:prefix "haskell-indentation-")
5151

52-
(defcustom haskell-indentation-indent-leftmost t
53-
"Indent to the left margin after certain keywords.
54-
For example after \"let .. in\", \"case .. of\"). If set to t it
55-
will only indent to the left. If nil only relative to the
56-
containing expression. If set to the symbol 'both then both
57-
positions are allowed."
58-
:type 'symbol
59-
:group 'haskell-indentation)
60-
6152
(defcustom haskell-indentation-layout-offset 2
6253
"Extra indentation to add before expressions in a Haskell layout list."
6354
:type 'integer
@@ -995,41 +986,14 @@ layout starts."
995986
(t (throw 'parse-end nil))))
996987
((null (cdr phrase)))
997988
((equal (cadr phrase) current-token)
998-
(let* ((on-new-line (= (current-column)
999-
(haskell-indentation-current-indentation)))
1000-
(lines-between (- parse-line-number starter-line))
1001-
(left-indent (if (<= lines-between 0)
1002-
left-indent
1003-
starter-indent)))
1004-
(haskell-indentation-read-next-token)
1005-
(when (eq current-token 'end-tokens)
1006-
(cond ((member (cadr phrase) '("then" "else"))
1007-
(haskell-indentation-add-indentation
1008-
(+ starter-indent haskell-indentation-ifte-offset)))
1009-
1010-
((member (cadr phrase) '("in" "->"))
1011-
;; expression ending in another expression
1012-
(when (or (not haskell-indentation-indent-leftmost)
1013-
(eq haskell-indentation-indent-leftmost 'both))
1014-
(haskell-indentation-add-indentation
1015-
(+ starter-indent haskell-indentation-starter-offset)))
1016-
(when haskell-indentation-indent-leftmost
1017-
(haskell-indentation-add-indentation
1018-
(if on-new-line
1019-
(+ left-indent haskell-indentation-starter-offset)
1020-
left-indent))))
1021-
(t
1022-
(when (or (not haskell-indentation-indent-leftmost)
1023-
(eq haskell-indentation-indent-leftmost 'both))
1024-
(haskell-indentation-add-indentation
1025-
(+ starter-indent haskell-indentation-starter-offset)))
1026-
(when haskell-indentation-indent-leftmost
1027-
(haskell-indentation-add-indentation
1028-
(if on-new-line
1029-
(+ left-indent haskell-indentation-starter-offset)
1030-
left-indent)))))
1031-
(throw 'parse-end nil))
1032-
(setq phrase1 (cddr phrase))))
989+
(haskell-indentation-read-next-token)
990+
(when (eq current-token 'end-tokens)
991+
(haskell-indentation-add-indentation
992+
(+ starter-indent haskell-indentation-starter-offset))
993+
(haskell-indentation-add-indentation
994+
(+ left-indent haskell-indentation-starter-offset))
995+
(throw 'parse-end nil))
996+
(setq phrase1 (cddr phrase)))
1033997
((string= (cadr phrase) "in"))))))
1034998

1035999
(defun haskell-indentation-add-indentation (indent)

tests/haskell-indentation-tests.el

+4-4
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ fun = \\x -> do"
368368
(hindent-test "16a A lambda""
369369
fun = \\x ->"
370370
(1 0)
371-
(2 2))
371+
(2 2 8))
372372

373373
(hindent-test "16u Lambda and a do block""
374374
fun = \\x → do"
@@ -378,7 +378,7 @@ fun = \\x → do"
378378
(hindent-test "16au A lambda""
379379
fun = \\x →"
380380
(1 0)
381-
(2 2))
381+
(2 2 8))
382382

383383
(hindent-test "17a* A type for a function""
384384
fun :: Int
@@ -514,7 +514,7 @@ x = let y
514514
z"
515515
(1 0)
516516
(2 4)
517-
(3 6))
517+
(3 2 6))
518518

519519
(hindent-test "19c* \"let\" in a \"do\"""
520520
x = do
@@ -826,7 +826,7 @@ fact n = case n of
826826
_ | n > 0
827827
, True == True -> n * fact (n - 1)"
828828
(1 0)
829-
(2 2)
829+
(2 2 11)
830830
;; returns (0 2 2 6), to investigate
831831
(3 0 2 6)
832832
(4 4)

0 commit comments

Comments
 (0)