The fill prefix feature allows paragraphs to be filled so that each line starts with a special string of characters (such as a sequence of spaces, giving an indented paragraph). You can specify a fill prefix explicitly; otherwise, Emacs tries to deduce one automatically (see Adaptive Filling).
Set the fill prefix (
Fill a paragraph using current fill prefix (
Fill the region, considering each change of indentation as starting a new paragraph.
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 type C-x . (
set-fill-prefix). (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 of the paragraph before filling, and insert it on each line after filling. (The beginning of the first line of the paragraph is left unchanged, since often that is intentionally different.) Auto Fill mode also inserts the fill prefix automatically when it makes a new line (see Auto Fill Mode). 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 that paragraph.
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 Local Variables.
indentation text property provides another way to control
the amount of indentation paragraphs receive. See Indentation in Enriched Text.