Fill all comments in a buffer?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Fill all comments in a buffer?

Jack Bates
Is there a way to fill (reflow) all comments in a buffer? Similar to how
I can spellcheck all comments with ispell-comments-and-strings?

I can go to each comment and type M-q -- I'd like to do it all at once.

Thanks!

Reply | Threaded
Open this post in threaded view
|

Re: Fill all comments in a buffer?

Emanuel Berg-4
Jack Bates wrote:

> Is there a way to fill (reflow) all comments
> in a buffer? Similar to how I can spellcheck
> all comments with
> ispell-comments-and-strings?
>
> I can go to each comment and type M-q -- I'd
> like to do it all at once.

Is that a good idea? It happens that people
have code blocs commented out. That code will
be screwed if filled.

Can't you do it manually? If you can't (too
much), probably you have too long files!

Anyway, try this.

Change the "^;;" to the syntax of your
language(s) or get it from Emacs (careful!).
Beware one line comments, like this

    i++; // increase i by 1

should not be filled, so stick to the ^ is what
I'd (not) do :)

(defun fill-all-comments ()
  (interactive)
  (goto-char (point-min))
  (while (search-forward-regexp "^;;" (point-max) t) ; NOERROR
    (let ((start (point)))
      (fill-comment-paragraph) )))

--
underground experts united
http://user.it.uu.se/~embe8573


Reply | Threaded
Open this post in threaded view
|

Re: Fill all comments in a buffer?

Emanuel Berg-4
In reply to this post by Jack Bates
YT wrote:

> (defun fill-all-comments ()
>   (interactive)
>   (goto-char (point-min))
>   (while (search-forward-regexp "^;;" (point-max) t) ; NOERROR
>     (let ((start (point)))
>       (fill-comment-paragraph) )))

Wait, what does the 5th line do?

Try

    (defun fill-all-comments ()
      (interactive)
      (goto-char (point-min))
      (while (search-forward-regexp "^;;" (point-max) t) ; NOERROR
        (fill-comment-paragraph) ))

--
underground experts united
http://user.it.uu.se/~embe8573