fill-paragraph and visual-line-mode

I’ve got so used to using visual-line-mode in Emacs that I sometimes need reminding there are other ways of setting out work.  Well, that’s what the Emacs Work-Out is all about…
visual-line-mode wraps words at the boundaries of the editor, rather like a word processor does. This can sometimes be a nuisance, particularly when embedding source code in documents.
One solution is to go back to using fill-paragraph. I’m going to set the fill column to 50, for no good reason.

C-x f 50        Set fill column to 50
Now write or copy some text into Emacs.  I'm going
to use this paragraph.  When I finish typing this
sentence I hit M-q right about now...

..and the paragraph is automatically wrapped at the extent of the fill column. You’ll notice I didn’t hit M-q for this paragraph.
What about all those extra carriage returns that get added? Well, if they bother you that much you can use this function and key definition written by Stefan Monnier to unfill-paragraphs.
The chances are, however you won’t need it very often. Most of the stuff I write is exported using org-export before it’s published (see My Emacs Writing Setup for more details)
Export ignores single returns so

a
b
c

becomes a b c on export. In other words, filled paragraphs are exported as, well, paragraphs.
If you can’t be bothered hitting M-q all the time, try setting auto-fill-mode or refill-mode.
Don’t forget you can use whitespace-mode to see non-printing characters and get a better idea of what’s going on.

M-x refill-mode
M-x whitespace-mode
Fill prefixes are an old fashioned method of
;; writing comments in code.  I've set a fill
;; prefix of ;; on this paragraph and hit M-q.
;; Note how the first line isn't prefixed
C-x .      Set fill prefix as text up to the point.
C-o        Add fill prefix to line

Lastly, you can left, right, fully and centre justify paragraphs, rather like this, if you really see the need.

M-x set-justification-full
M-x set-justification-left
M-x set-justification-center
M-x set-justification-right
M-x set-justification-none

Leave a Reply

Your email address will not be published. Required fields are marked *