Go to the first, previous, next, last section, table of contents.

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-s
Center a line.

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.

To refill many paragraphs, use M-x fill-region, which divides the region into paragraphs and fills each of them.

M-q and fill-region use the same criteria as M-h for finding paragraph boundaries (see section Paragraphs). For more control, you can use M-x fill-region-as-paragraph, which refills everything between point and mark. 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 causes 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 justification text property; see section Justification in Formatted Text.

The fill commands can deduce the proper fill prefix for a paragraph automatically in certain cases: either whitespace or certain punctuation characters at the beginning of a line are treated as a fill prefix. They take the fill prefix from the paragraph's second line, unless the paragraph has just one line. You can turn off this feature by setting adaptive-fill-mode to nil.

Some major modes, including Text mode, treat whitespace at the beginning of a line as a signal that this line starts a new paragraph. It would be a mistake to copy text which implies the start of a paragraph onto each line of the paragraph when filling it. Therefore, adaptive filling does not accept a fill prefix from a line which is a paragraph-starter. In particular, adaptive filling in Text mode does not accept a fill prefix consisting of just whitespace.

However, other modes including Indented Text mode (see section Text Mode) do not consider whitespace as a signal to start a new paragraph. In these modes, adaptive filling does accept a fill prefix consisting of just whitespace, if the first or second line of a paragraph begins with whitespace.

The variable adaptive-fill-regexp determines what kinds of line beginnings can serve as a fill prefix: any characters at the start of the line which match this regular expression are used.

You can specify more complex ways of choosing a fill prefix automatically by setting the variable adaptive-fill-function to a function. This function is called with point after the left margin of a line, and it should return the appropriate fill prefix based on that line. If it returns nil, that means it sees no fill prefix in that line.

The command 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.

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 section Local Variables. The easiest way to set 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 sentence-end-double-space is nil, the 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 section Sentences.

If the variable colon-double-space is non-nil, the fill commands put two spaces after a colon.


Go to the first, previous, next, last section, table of contents.