To refill a paragraph, use the command M-q
fill-paragraph). This operates on the paragraph that point is
inside, or the one after point if point is between paragraphs.
Refilling works by removing all the line-breaks, then inserting new
ones where necessary. When there is an active region, this command
operates on the text within the region like
To refill many paragraphs, use M-x fill-region, which finds the paragraphs in the region and fills each of them.
fill-region use the same criteria as M-h
for finding paragraph boundaries (see Paragraphs). For more
control, you can use M-x fill-region-as-paragraph, which refills
everything between point and mark as a single paragraph. This command
deletes any blank lines within the region, so separate blocks of text
end up combined into one block.
A numeric argument to M-q tells it to justify the text
as well as filling it. This means that extra spaces are inserted to
make the right margin line up exactly at the fill column. To remove
the extra spaces, use M-q with no argument. (Likewise for
fill-region.) Another way to control justification, and choose
other styles of filling, is with the
property; see Format Justification.
The command M-o M-s (
center-line) centers the current line
within the current fill column. With an argument n, it centers
n lines individually and moves past them. This binding is
made by Text mode and is available only in that and related modes
(see Text Mode).
The maximum line width for filling is in the variable
fill-column. Altering the value of
fill-column makes it
local to the current buffer; until that time, the default value is in
effect. The default is initially 70. See Locals. The easiest way
fill-column is to use the command C-x f
set-fill-column). With a numeric argument, it uses that as the
new fill column. With just C-u as argument, it sets
fill-column to the current horizontal position of point.
Emacs commands normally consider a period followed by two spaces or by a newline as the end of a sentence; a period followed by just one space indicates an abbreviation and not the end of a sentence. To preserve the distinction between these two ways of using a period, the fill commands do not break a line after a period followed by just one space.
If the variable
fill commands expect and leave just one space at the end of a sentence.
Ordinarily this variable is
t, so the fill commands insist on
two spaces for the end of a sentence, as explained above. See Sentences.
If the variable
colon-double-space is non-
fill commands put two spaces after a colon.
fill-nobreak-predicate is a hook (an abnormal
hook, see Hooks) specifying additional conditions where
line-breaking is not allowed. Each function is called with no
arguments, with point at a place where Emacs is considering breaking
the line. If a function returns a non-
nil value, then that's
a bad place to break the line. Two standard functions you can use are
fill-single-word-nobreak-p (don't break after the first word of
a sentence or before the last) and
break after ‘(’ or before ‘)’, ‘:’ or ‘?’).