Skip to content

Improve paragraph filling for nested comments. #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions haskell-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,11 @@ currently using.
Additional Haskell mode modules can be hooked in via `haskell-mode-hook';
see documentation for that variable for more details."
:group 'haskell
(set (make-local-variable 'paragraph-start) (concat "^$\\|" page-delimiter))
(set (make-local-variable 'paragraph-separate) paragraph-start)
;; paragraph-{start,separate} should treat comments as paragraphs as well.
(set (make-local-variable 'paragraph-start)
(concat " *{-\\| *-- |\\|" page-delimiter))
(set (make-local-variable 'paragraph-separate)
(concat " *$\\| *-- |\\| *\\({-\\|-}\\) *$\\|" page-delimiter))
(set (make-local-variable 'fill-paragraph-function) 'haskell-fill-paragraph)
;; (set (make-local-variable 'adaptive-fill-function) 'haskell-adaptive-fill)
(set (make-local-variable 'adaptive-fill-mode) nil)
Expand Down Expand Up @@ -555,12 +558,22 @@ see documentation for that variable for more details."
(let* ((comment-start-point (nth 8 syntax-values))
(comment-end-point
(save-excursion
(re-search-forward "-}" (point-max) t comment-num)
(goto-char comment-start-point)
(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)))
(fill-start (+ 2 comment-start-point))
(fill-end (- comment-end-point 2))
(fill-paragraph-handle-comment nil))
(save-restriction
(narrow-to-region (+ 2 comment-start-point) (- comment-end-point 2))
(fill-paragraph justify))))
(narrow-to-region fill-start fill-end)
(fill-paragraph justify)
;; If no filling happens, whatever called us should not
;; continue with standard text filling, so return t
t)))
((eolp)
;; do nothing outside of a comment
t)
Expand Down