25.6.2 Explicit Fill Commands
M-q
Fill current paragraph ( fill-paragraph
).
C-x f
Set the fill column ( set-fill-column
).
M-x fill-region
Fill each paragraph in the region ( fill-region
).
M-x fill-region-as-paragraph
Fill the region, considering it as one paragraph.
M-x center-line
Center a line.
The command M-q
( fill-paragraph
) fills the
current paragraph. It redistributes the line breaks within the
paragraph, and deletes any excess space and tab characters occurring
within the paragraph, in such a way that the lines end up fitting
within a certain maximum width. Like Auto Fill mode, this and other
filling commands usually break lines at space characters, but for CJK
characters these commands can break a line between almost any two
characters, and they can also obey the kinsoku rules. See Auto Fill Mode.
Normally, M-q
acts on the paragraph where point is, but if
point is between paragraphs, it acts on the paragraph after point. If
the region is active, it acts instead on the text in the region. You
can also call M-x fill-region
to specifically fill the text in
the region.
M-q
and fill-region
use the usual Emacs criteria 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
.)
The maximum line width for filling is specified by the buffer-local
variable fill-column
. The default value (see Local Variables) is
70. The easiest way to set fill-column
in the current buffer
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.
The command M-x 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).
By default, Emacs considers 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, not the end of a sentence. Accordingly,
the fill commands will not break a line after a period followed by
just one space. If you set the variable
sentence-end-double-space
to nil
, the fill commands will
break a line after a period followed by one space, and put just one
space after each period. See Sentences, for other effects and
possible drawbacks of this.
If the variable colon-double-space
is non- nil
, the
fill commands put two spaces after a colon.
To specify additional conditions where line-breaking is not allowed,
customize the abnormal hook variable fill-nobreak-predicate
(see Hooks). Each function in this hook is called with no
arguments, with point positioned where Emacs is considering breaking a
line. If a function returns a non- nil
value, Emacs will not
break the line there. Functions you can use there include:
fill-single-word-nobreak-p
(don’t break after the first word of
a sentence or before the last); fill-single-char-nobreak-p
(don’t break after a one-letter word preceded by a whitespace
character); fill-french-nobreak-p
(don’t break after ‘ (
’
or before ‘ )
’, ‘ :
’ or ‘ ?
’); and
fill-polish-nobreak-p
(don’t break after a one letter word,
even if preceded by a non-whitespace character).
Emacs can display an indicator in the fill-column
position
using the Display fill column indicator mode (see display-fill-column-indicator).