30.5.4 The Fill Prefix
To fill a paragraph in which each line starts with a special marker
(which might be a few spaces, giving an indented paragraph), you can use
the fill prefix feature. The fill prefix is a string that Emacs
expects every line to start with, and which is not included in filling.
You can specify a fill prefix explicitly; Emacs can also deduce the
fill prefix automatically (see Adaptive Fill).
- C-x .
- Set the fill prefix (
- Fill a paragraph using current fill prefix (
- M-x fill-individual-paragraphs
- Fill the region, considering each change of indentation as starting a
- M-x fill-nonuniform-paragraphs
- Fill the region, considering only paragraph-separator lines as starting
a new paragraph.
To specify a fill prefix for the current buffer, move to a line that
starts with the desired prefix, put point at the end of the prefix,
and give the command C-x . (
That's a period after the C-x. To turn off the fill prefix,
specify an empty prefix: type C-x . with point at the
beginning of a line.
When a fill prefix is in effect, the fill commands remove the fill
prefix from each line before filling and insert it on each line after
filling. (The beginning of the first line is left unchanged, since
often that is intentionally different.) Auto Fill mode also inserts
the fill prefix automatically when it makes a new line. The C-o
command inserts the fill prefix on new lines it creates, when you use
it at the beginning of a line (see Blank Lines). Conversely, the
command M-^ deletes the prefix (if it occurs) after the newline
that it deletes (see Indentation).
For example, if
fill-column is 40 and you set the fill prefix
to ‘;; ’, then M-q in the following text
;; This is an
;; example of a paragraph
;; inside a Lisp-style comment.
;; This is an example of a paragraph
;; inside a Lisp-style comment.
Lines that do not start with the fill prefix are considered to start
paragraphs, both in M-q and the paragraph commands; this gives
good results for paragraphs with hanging indentation (every line
indented except the first one). Lines which are blank or indented once
the prefix is removed also separate or start paragraphs; this is what
you want if you are writing multi-paragraph comments with a comment
delimiter on each line.
You can use M-x fill-individual-paragraphs to set the fill
prefix for each paragraph automatically. This command divides the
region into paragraphs, treating every change in the amount of
indentation as the start of a new paragraph, and fills each of these
paragraphs. Thus, all the lines in one “paragraph” have the same
amount of indentation. That indentation serves as the fill prefix for
M-x fill-nonuniform-paragraphs is a similar command that divides
the region into paragraphs in a different way. It considers only
paragraph-separating lines (as defined by
starting a new paragraph. Since this means that the lines of one
paragraph may have different amounts of indentation, the fill prefix
used is the smallest amount of indentation of any of the lines of the
paragraph. This gives good results with styles that indent a paragraph's
first line more or less that the rest of the paragraph.
The fill prefix is stored in the variable
fill-prefix. Its value
is a string, or
nil when there is no fill prefix. This is a
per-buffer variable; altering the variable affects only the current buffer,
but there is a default value which you can change as well. See Locals.
indentation text property provides another way to control
the amount of indentation paragraphs receive. See Format Indentation.