Skip to content

Commit af34d4e

Browse files
committed
Merge pull request #441 from gracjan/pr-fill-comment
M-q fix and tests
2 parents e3ab3de + d7a973c commit af34d4e

File tree

2 files changed

+156
-4
lines changed

2 files changed

+156
-4
lines changed

haskell-mode.el

+4-4
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,11 @@ see documentation for that variable for more details."
748748
(forward-sexp)
749749
;; Find end of any comment even if forward-sexp
750750
;; fails to find the right braces.
751-
(backward-char 2)
752-
(re-search-forward "-}" nil t)
753-
(point)))
751+
(backward-char 3)
752+
(re-search-forward "[ \t]?-}" nil t)
753+
(match-beginning 0)))
754754
(fill-start (+ 2 comment-start-point))
755-
(fill-end (- comment-end-point 2))
755+
(fill-end comment-end-point)
756756
(fill-paragraph-handle-comment nil))
757757
(save-restriction
758758
(narrow-to-region fill-start fill-end)

tests/haskell-mode-tests.el

+152
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,156 @@
129129
(insert "Äöèąċōïá")
130130
(string= "Äöèąċōïá" (haskell-ident-at-point)))))
131131

132+
(defun check-fill (expected initial)
133+
"Check using ERT if `fill-paragraph' over `initial' gives
134+
`expected' result. Cursor fill be positioned at '@' character or at
135+
the beginning of the buffer.
136+
137+
`fill-column' will be set to 10 so that it is easy to spot issues."
138+
(should (equal expected
139+
(with-temp-buffer
140+
(haskell-mode)
141+
(setq fill-column 10)
142+
(dolist (line initial)
143+
(insert line)
144+
(insert "\n"))
145+
(goto-char (point-min))
146+
(skip-chars-forward "^@")
147+
(if (eobp)
148+
(goto-char (point-min))
149+
(delete-char 1))
150+
(fill-paragraph nil)
151+
(split-string (buffer-substring-no-properties (point-min) (1- (point-max))) "\n")))))
152+
153+
(ert-deftest fill-comment-1 ()
154+
(check-fill '("{- a -}")
155+
'("{- @a -}")))
156+
157+
(ert-deftest fill-comment-2 ()
158+
(check-fill '("{- a b c d e"
159+
"f g h i j"
160+
"k -}")
161+
'("{- @a b c d e f g h i j k -}")))
162+
163+
(ert-deftest fill-comment-3 ()
164+
(check-fill '("{-"
165+
"a"
166+
"-}")
167+
'("{-"
168+
"@a"
169+
"-}")))
170+
171+
(ert-deftest fill-comment-4 ()
172+
(check-fill '("{-"
173+
"a b c d e"
174+
"f g h i-}")
175+
'("{-"
176+
"@a"
177+
"b"
178+
"c"
179+
"d e f g h i-}")))
180+
181+
(ert-deftest fill-comment-5 ()
182+
(check-fill '(" {-"
183+
" a b c d e"
184+
"f g h i"
185+
" -}")
186+
'(" {-" " @a b c d e f g h i" " -}")))
187+
188+
(ert-deftest fill-comment-6 ()
189+
(check-fill '(" -- a b c"
190+
" -- d e f"
191+
" -- g h i"
192+
" -- j k l"
193+
" -- m n o"
194+
" -- p q r"
195+
" -- s t u"
196+
" -- v")
197+
'(" -- @a b c d e f g h i j k l m n o p q r s t u v")))
198+
199+
(ert-deftest fill-comment-7 ()
200+
(check-fill '(" -- a b"
201+
" -- c d"
202+
" -- e f"
203+
" -- g h"
204+
" -- i j")
205+
'(" -- @a b c d e f g h i j ")))
206+
207+
(ert-deftest fill-comment-8 ()
208+
"Note: first letter of second line should be in the same column
209+
as first letter in the first line.
210+
211+
Also should respect 10 column fill."
212+
:expected-result :failed
213+
(check-fill '(" {- a b"
214+
" c d"
215+
" e f"
216+
" g h"
217+
" i j"
218+
" -}")
219+
'(" {- @a b c d e f g h i j"
220+
" -}")))
221+
222+
(ert-deftest fill-comment-9 ()
223+
"Note: first letter in the second line position should be kept
224+
as defined, just the content should move properly.
225+
226+
Also should respect 10 column fill."
227+
:expected-result :failed
228+
(check-fill '(" {- a b"
229+
" c d e"
230+
" f g h"
231+
" i j"
232+
" -}")
233+
'(" {- @a"
234+
" b c d e f g h i j"
235+
" -}")))
236+
237+
(ert-deftest fill-comment-10 ()
238+
"Note: first letter in the second line position should be kept
239+
as defined, just the content should move properly. Following
240+
lines should take position from second line.
241+
242+
Also should respect 10 column fill."
243+
:expected-result :failed
244+
(check-fill '(" {- a b"
245+
" c d e"
246+
" f g h"
247+
" i j"
248+
" -}")
249+
'(" {- @a"
250+
" b c d e"
251+
" f g h"
252+
" i j"
253+
" -}")))
254+
255+
(ert-deftest fill-comment-11 ()
256+
"Note: first letter in the second line position should be kept
257+
as defined, just the content should move properly.
258+
259+
Also should respect 10 column fill."
260+
:expected-result :failed
261+
(check-fill '(" -- a b"
262+
" -- c d e"
263+
" -- f g h"
264+
" -- i j")
265+
'(" -- @a"
266+
" -- b c d e f g h i j")))
267+
268+
(ert-deftest fill-comment-12 ()
269+
"Note: first letter in the second line position should be kept
270+
as defined, just the content should move properly. Following
271+
lines should take position from second line.
272+
273+
Also should respect 10 column fill."
274+
:expected-result :failed
275+
(check-fill '(" -- a b"
276+
" -- c d e"
277+
" -- f g h"
278+
" -- i j")
279+
'(" -- @a"
280+
" -- b c d e"
281+
"--f g h"
282+
" -- i j")))
283+
132284
(provide 'haskell-mode-tests)

0 commit comments

Comments
 (0)