From 7e9b61f4c76c2d41e26329ceed0ff7d225a7882c Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Tue, 20 Jan 2015 20:44:55 +0100 Subject: [PATCH 1/2] Keep final space after fill-paragraph. Before this commit {- a -} got paragraph filled as {- a-} (notice missing space). Now this space is kept in place properly. --- haskell-mode.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/haskell-mode.el b/haskell-mode.el index 1b01cc1b3..4ddc56092 100644 --- a/haskell-mode.el +++ b/haskell-mode.el @@ -748,11 +748,11 @@ see documentation for that variable for more details." (forward-sexp) ;; Find end of any comment even if forward-sexp ;; fails to find the right braces. - (backward-char 2) - (re-search-forward "-}" nil t) - (point))) + (backward-char 3) + (re-search-forward "[ \t]?-}" nil t) + (match-beginning 0))) (fill-start (+ 2 comment-start-point)) - (fill-end (- comment-end-point 2)) + (fill-end comment-end-point) (fill-paragraph-handle-comment nil)) (save-restriction (narrow-to-region fill-start fill-end) From d7a973c33b8b12cc94fb9ed072e8cf582cdae6d3 Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Tue, 20 Jan 2015 20:46:35 +0100 Subject: [PATCH 2/2] Tests for fill-comment. ERT tests for working and not working cases of paragraph filling in Haskell comments. --- tests/haskell-mode-tests.el | 152 ++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/tests/haskell-mode-tests.el b/tests/haskell-mode-tests.el index 7e9d50ce4..c3668d326 100644 --- a/tests/haskell-mode-tests.el +++ b/tests/haskell-mode-tests.el @@ -129,4 +129,156 @@ (insert "Äöèąċōïá") (string= "Äöèąċōïá" (haskell-ident-at-point))))) +(defun check-fill (expected initial) + "Check using ERT if `fill-paragraph' over `initial' gives +`expected' result. Cursor fill be positioned at '@' character or at +the beginning of the buffer. + +`fill-column' will be set to 10 so that it is easy to spot issues." + (should (equal expected + (with-temp-buffer + (haskell-mode) + (setq fill-column 10) + (dolist (line initial) + (insert line) + (insert "\n")) + (goto-char (point-min)) + (skip-chars-forward "^@") + (if (eobp) + (goto-char (point-min)) + (delete-char 1)) + (fill-paragraph nil) + (split-string (buffer-substring-no-properties (point-min) (1- (point-max))) "\n"))))) + +(ert-deftest fill-comment-1 () + (check-fill '("{- a -}") + '("{- @a -}"))) + +(ert-deftest fill-comment-2 () + (check-fill '("{- a b c d e" + "f g h i j" + "k -}") + '("{- @a b c d e f g h i j k -}"))) + +(ert-deftest fill-comment-3 () + (check-fill '("{-" + "a" + "-}") + '("{-" + "@a" + "-}"))) + +(ert-deftest fill-comment-4 () + (check-fill '("{-" + "a b c d e" + "f g h i-}") + '("{-" + "@a" + "b" + "c" + "d e f g h i-}"))) + +(ert-deftest fill-comment-5 () + (check-fill '(" {-" + " a b c d e" + "f g h i" + " -}") + '(" {-" " @a b c d e f g h i" " -}"))) + +(ert-deftest fill-comment-6 () + (check-fill '(" -- a b c" + " -- d e f" + " -- g h i" + " -- j k l" + " -- m n o" + " -- p q r" + " -- s t u" + " -- v") + '(" -- @a b c d e f g h i j k l m n o p q r s t u v"))) + +(ert-deftest fill-comment-7 () + (check-fill '(" -- a b" + " -- c d" + " -- e f" + " -- g h" + " -- i j") + '(" -- @a b c d e f g h i j "))) + +(ert-deftest fill-comment-8 () + "Note: first letter of second line should be in the same column +as first letter in the first line. + +Also should respect 10 column fill." + :expected-result :failed + (check-fill '(" {- a b" + " c d" + " e f" + " g h" + " i j" + " -}") + '(" {- @a b c d e f g h i j" + " -}"))) + +(ert-deftest fill-comment-9 () + "Note: first letter in the second line position should be kept +as defined, just the content should move properly. + +Also should respect 10 column fill." + :expected-result :failed + (check-fill '(" {- a b" + " c d e" + " f g h" + " i j" + " -}") + '(" {- @a" + " b c d e f g h i j" + " -}"))) + +(ert-deftest fill-comment-10 () + "Note: first letter in the second line position should be kept +as defined, just the content should move properly. Following +lines should take position from second line. + +Also should respect 10 column fill." + :expected-result :failed + (check-fill '(" {- a b" + " c d e" + " f g h" + " i j" + " -}") + '(" {- @a" + " b c d e" + " f g h" + " i j" + " -}"))) + +(ert-deftest fill-comment-11 () + "Note: first letter in the second line position should be kept +as defined, just the content should move properly. + +Also should respect 10 column fill." + :expected-result :failed + (check-fill '(" -- a b" + " -- c d e" + " -- f g h" + " -- i j") + '(" -- @a" + " -- b c d e f g h i j"))) + +(ert-deftest fill-comment-12 () + "Note: first letter in the second line position should be kept +as defined, just the content should move properly. Following +lines should take position from second line. + +Also should respect 10 column fill." + :expected-result :failed + (check-fill '(" -- a b" + " -- c d e" + " -- f g h" + " -- i j") + '(" -- @a" + " -- b c d e" + "--f g h" + " -- i j"))) + (provide 'haskell-mode-tests)