Skip to content

Commit 51b0144

Browse files
committed
Merge pull request #956 from gracjan/pr-do-inside-a-list
Fix indent for do inside a list
2 parents 1f229c9 + 5eb14ed commit 51b0144

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

haskell-indentation.el

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ Skip the keyword or parenthesis." ; FIXME: better description needed
756756
(starter-indent (min starter-column current-indent))
757757
(left-indent
758758
(if end
759-
(+ current-indent haskell-indentation-starter-offset)
759+
(+ starter-indent haskell-indentation-starter-offset)
760760
left-indent)))
761761
(funcall parser)
762762
(cond ((eq current-token 'end-tokens)
@@ -926,7 +926,9 @@ l = [ 1
926926
(throw 'return nil))
927927
(separator-column ; on the beginning of the line
928928
(setq current-indent (current-column))
929-
(setq starter-indent separator-column)))))
929+
(setq starter-indent separator-column)
930+
(setq left-indent
931+
(+ starter-indent haskell-indentation-starter-offset))))))
930932

931933
(defun haskell-indentation-implicit-layout-list (parser)
932934
"An implicit layout list, elements are parsed with PARSER.
@@ -1119,7 +1121,6 @@ line."
11191121
(when (= (current-column) (haskell-indentation-current-indentation))
11201122
;; on a new line
11211123
(setq current-indent (current-column))
1122-
(setq left-indent (current-column))
11231124
(setq parse-line-number (+ parse-line-number 1)))
11241125
(cond ((and implicit-layout-active
11251126
(> layout-indent (current-column)))

tests/haskell-indentation-tests.el

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ macro quotes them for you."
145145
function = Record
146146
{ field = 123 }"
147147
((1 0) 0)
148-
((2 0) 0 11)
149-
((3 0) 0 7))
148+
((2 0) 0 11))
150149

151150
(hindent-test "2 Handle underscore in identifiers""
152151
function = do
@@ -719,4 +718,32 @@ a = ( 1
719718
((2 0) 4)
720719
((2 2) 6))
721720

721+
(hindent-test "41 open do inside a list" "
722+
x = asum [ withX $ do
723+
return ()
724+
]
725+
"
726+
((2 0) 13))
727+
728+
(hindent-test "42 open do inside a list second element" "
729+
x = asum [ mzero
730+
, withX $ do
731+
return ()
732+
]
733+
"
734+
((3 0) 13))
735+
736+
(hindent-test "43 open do inside a list second element, reset alignment" "
737+
x = asum [ mzero
738+
, withX $ do
739+
return ()
740+
]
741+
"
742+
((3 0) 17))
743+
744+
(hindent-test "44 expression continues, reset alignment" "
745+
function = abc
746+
def
747+
xyz"
748+
((3 0) 0 7))
722749
;;; haskell-indentation-tests.el ends here

0 commit comments

Comments
 (0)