Skip to content

Commit d412c0c

Browse files
committed
Merge pull request #387 from ikirill/fix-comment-fill-paragraph
Improve paragraph filling for nested comments.
2 parents 0f5434c + a3173e9 commit d412c0c

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

haskell-mode.el

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,11 @@ currently using.
674674
Additional Haskell mode modules can be hooked in via `haskell-mode-hook';
675675
see documentation for that variable for more details."
676676
:group 'haskell
677-
(set (make-local-variable 'paragraph-start) (concat "^$\\|" page-delimiter))
678-
(set (make-local-variable 'paragraph-separate) paragraph-start)
677+
;; paragraph-{start,separate} should treat comments as paragraphs as well.
678+
(set (make-local-variable 'paragraph-start)
679+
(concat " *{-\\| *-- |\\|" page-delimiter))
680+
(set (make-local-variable 'paragraph-separate)
681+
(concat " *$\\| *-- |\\| *\\({-\\|-}\\) *$\\|" page-delimiter))
679682
(set (make-local-variable 'fill-paragraph-function) 'haskell-fill-paragraph)
680683
;; (set (make-local-variable 'adaptive-fill-function) 'haskell-adaptive-fill)
681684
(set (make-local-variable 'adaptive-fill-mode) nil)
@@ -741,12 +744,22 @@ see documentation for that variable for more details."
741744
(let* ((comment-start-point (nth 8 syntax-values))
742745
(comment-end-point
743746
(save-excursion
744-
(re-search-forward "-}" (point-max) t comment-num)
747+
(goto-char comment-start-point)
748+
(forward-sexp)
749+
;; Find end of any comment even if forward-sexp
750+
;; fails to find the right braces.
751+
(backward-char 2)
752+
(re-search-forward "-}" nil t)
745753
(point)))
754+
(fill-start (+ 2 comment-start-point))
755+
(fill-end (- comment-end-point 2))
746756
(fill-paragraph-handle-comment nil))
747757
(save-restriction
748-
(narrow-to-region (+ 2 comment-start-point) (- comment-end-point 2))
749-
(fill-paragraph justify))))
758+
(narrow-to-region fill-start fill-end)
759+
(fill-paragraph justify)
760+
;; If no filling happens, whatever called us should not
761+
;; continue with standard text filling, so return t
762+
t)))
750763
((eolp)
751764
;; do nothing outside of a comment
752765
t)

0 commit comments

Comments
 (0)