Skip to content

Fill paragraph in block ({- ... -}) comments is generates sometimes several comment opens ({-) #354

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

Closed
jyp opened this issue Oct 8, 2014 · 3 comments

Comments

@jyp
Copy link

jyp commented Oct 8, 2014

Calling fill-paragraph on this snippet:

f x = x {- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sed risus ipsum. -}

yields (if the current point is between "Lorem" and "sed"):

f x = x {- Lorem ipsum dolor sit amet, consectetur adipiscing
        {- elit. Donec sed
risus ipsum.-}

I have developed a replacement for haskell-fill-paragraph which
consistently generates:

f x = x {- Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Donec sed risus ipsum. -}

Which, I believe, is a correct behaviour.

The function follows.

(defun haskell-fill-paragraph (justify)
    (save-excursion
      ;; Fill paragraph should only work in comments.
      ;; The -- comments are handled properly by default
      ;; The {- -} comments are handled specially here.
      (let* ((syntax-values (syntax-ppss))
             (comment-num (nth 4 syntax-values)))
        (cond
         ((eq t comment-num)
          ;; standard fill works wonders inside a non-nested comment
          (fill-comment-paragraph justify))

         ((integerp comment-num)
          ;; we are in a nested comment. lets narrow to comment content
          ;; and use plain paragraph fill for that
          (let* ((comment-start-point (nth 8 syntax-values))
                 (comment-end-point
                  (save-excursion
                    (goto-char comment-start-point)
                    (forward-comment 1)
                    (point)))
                 (paragraph-start-point (save-excursion (backward-paragraph) (point)))
                 (paragraph-end-point (save-excursion (forward-paragraph) (point))))
            ;; If a nested comment is broken into several paragraphs, then fill only the current one.
            (fill-region (max paragraph-start-point comment-start-point)
                         (min paragraph-end-point comment-end-point)
                         justify))
          t ;; return t so that fill-paragraph does not keep
            ;; going. (This route was successfull regardless the
            ;; output of fill-region)
          )
         ((eolp)
          ;; do nothing outside of a comment
          t)
         (t
          ;; go to end of line and try again
          (end-of-line)
          (haskell-fill-paragraph justify))))))
@ivan-m
Copy link
Contributor

ivan-m commented Oct 9, 2014

Ideally, I think the comment block should be indented, but I've tried doing this in the past and couldn't get it to work.

@gracjan
Copy link
Contributor

gracjan commented Dec 26, 2015

The function suggested here is already incorporated so closing this issue. The are other specific requests about the functionality tracked in #225.

@gracjan gracjan closed this as completed Dec 26, 2015
@jyp
Copy link
Author

jyp commented Dec 29, 2015

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants