I am setting the fill column (80) to specify the maximum width of a line before it should be automatically wrapped or broken into multiple lines.

Although this setting is useful for ensuring consistent line lengths in the code and text documents, making them more readable and easier to manage, I want that comments use a fill column at a value of 72.

What can I do to format comment blocks only to line lengths of 72. Have a function that formats a particular comment block to 72 ? How would I code something like that ?

2 Answers 2


You can fill a paragraph to a specific fill column, using the following expression:

(let ((fill-column 72)) (fill-paragraph))

So you can position your cursor at the beginning of a comment paragraph and say M-: (let ((fill-column 72)) (fill-paragraph)) to fill it. You only have to type it once because for subsequent comment paragraphs, you can recall the expression from history: M-: M-p (assuming that you have evaluated no other expressions in this way, since they are going to be added to the history: if you have, repeat M-p until you get the expression you want).

If that's too much typing, define a function and bind it to a key:

(defun fill-comment-paragraph ()
   (let ((fill-column 72))

(global-set-key (kbd "C-c z") #'fill-comment-paragraph)

Add this to your init file and restart Emacs.

Now C-c z will reformat a paragraph with fill-column set to 72.

The key sequence C-c z is generally undefined in the global map, so it is probably safe to use here, but you can use another key sequence if you prefer, although you have to be careful not to clobber something useful. Also make sure that the modes you are interested in do not shadow this key binding.


There’s no option for that as far as I know, though you should consult the documentation for the specific mode you are using in case it has one. Barring that, you’ll have to write the code yourself.

  • That's what I need help with. I thought to applying to a comment block but seems hard to do. Apply the operation to a paragraph would be better. What function call can be used to wrap the paragraph up to column 72 ?
    – Dilna
    Commented Oct 1, 2023 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.