Skip to content

Commit a3173e9

Browse files
committed
Improve paragraph filling for nested comments.
Change paragraph-start and paragraph-separate so that haddock (-- |) and nested comments become paragraphs; only empty lines used to be paragraph separators. This also makes forward/backward-paragraph more helpful. Change haskell-fill-paragraph to recognize nested comments slightly more accurately using forward-sexp. Also, if fill-paragraph was called in a nested and no actual filling is necessary, make sure non-comment-aware filling does not happen instead.
1 parent 5e4e627 commit a3173e9

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
@@ -488,8 +488,11 @@ currently using.
488488
Additional Haskell mode modules can be hooked in via `haskell-mode-hook';
489489
see documentation for that variable for more details."
490490
:group 'haskell
491-
(set (make-local-variable 'paragraph-start) (concat "^$\\|" page-delimiter))
492-
(set (make-local-variable 'paragraph-separate) paragraph-start)
491+
;; paragraph-{start,separate} should treat comments as paragraphs as well.
492+
(set (make-local-variable 'paragraph-start)
493+
(concat " *{-\\| *-- |\\|" page-delimiter))
494+
(set (make-local-variable 'paragraph-separate)
495+
(concat " *$\\| *-- |\\| *\\({-\\|-}\\) *$\\|" page-delimiter))
493496
(set (make-local-variable 'fill-paragraph-function) 'haskell-fill-paragraph)
494497
;; (set (make-local-variable 'adaptive-fill-function) 'haskell-adaptive-fill)
495498
(set (make-local-variable 'adaptive-fill-mode) nil)
@@ -555,12 +558,22 @@ see documentation for that variable for more details."
555558
(let* ((comment-start-point (nth 8 syntax-values))
556559
(comment-end-point
557560
(save-excursion
558-
(re-search-forward "-}" (point-max) t comment-num)
561+
(goto-char comment-start-point)
562+
(forward-sexp)
563+
;; Find end of any comment even if forward-sexp
564+
;; fails to find the right braces.
565+
(backward-char 2)
566+
(re-search-forward "-}" nil t)
559567
(point)))
568+
(fill-start (+ 2 comment-start-point))
569+
(fill-end (- comment-end-point 2))
560570
(fill-paragraph-handle-comment nil))
561571
(save-restriction
562-
(narrow-to-region (+ 2 comment-start-point) (- comment-end-point 2))
563-
(fill-paragraph justify))))
572+
(narrow-to-region fill-start fill-end)
573+
(fill-paragraph justify)
574+
;; If no filling happens, whatever called us should not
575+
;; continue with standard text filling, so return t
576+
t)))
564577
((eolp)
565578
;; do nothing outside of a comment
566579
t)

0 commit comments

Comments
 (0)