Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Emacs to write comments with proper indentation, line-length, and wrapping?

I'm tired of writing comments that look like this

{
    # bla bla blabla bla blabla bla blabla
    # bla bla blabla bla blabla bla blabla bla blabla bla blabla bla bla
    # blaaa bla
}

I have to manually wrap the lines and take care of the # as well. How do emacs pros make the editor work for them?

like image 874
Samuel Danielson Avatar asked Feb 06 '10 18:02

Samuel Danielson


2 Answers

Selecting the comment and hitting M-q will usually reformat it.

M-q is generally mapped to fill-paragraph, c-fill-paragraph, or some other mode-specific variant.

like image 61
Kristopher Johnson Avatar answered Nov 19 '22 18:11

Kristopher Johnson


Use auto-fill-mode together with comment-auto-fill-only-comments (the latter is from newcomment.el).

like image 31
Joe Casadonte Avatar answered Nov 19 '22 18:11

Joe Casadonte