Node:fwd-para no fill prefix, Next:fwd-para with fill prefix, Previous:fwd-para within paragraph, Up:forward-paragraph
It is simplest to look at the code for the case when there is no fill
prefix first. This code consists of yet another inner if
expression, and reads as follows:
(if (re-search-forward paragraph-start nil t) (goto-char (match-beginning 0)) (goto-char (point-max)))
This expression actually does the work that most people think of as
the primary purpose of the forward-paragraph
command: it causes
a regular expression search to occur that searches forward to the
start of the next paragraph and if it is found, moves point there; but
if the start of another paragraph if not found, it moves point to the
end of the accessible region of the buffer.
The only unfamiliar part of this is the use of match-beginning
.
This is another function that is new to us. The
match-beginning
function returns a number specifying the
location of the start of the text that was matched by the last regular
expression search.
The match-beginning
function is used here because of a
characteristic of a forward search: a successful forward search,
regardless of whether it is a plain search or a regular expression
search, will move point to the end of the text that is found. In this
case, a successful search will move point to the end of the pattern for
paragraph-start
, which will be the beginning of the next
paragraph rather than the end of the current one.
However, we want to put point at the end of the current paragraph, not at the beginning of the next one. The two positions may be different, because there may be several blank lines between paragraphs.
When given an argument of 0, match-beginning
returns the position
that is the start of the text that the most recent regular
expression search matched. In this case, the most recent regular
expression search is the one looking for paragraph-start
, so
match-beginning
returns the beginning position of the pattern,
rather than the end of the pattern. The beginning position is the end
of the paragraph.
(Incidentally, when passed a positive number as an argument, the
match-beginning
function will place point at that parenthesized
expression in the last regular expression. It is a useful function.)