GNU Info

Info Node: (emacs-lisp-intro.info)fwd-para between paragraphs

(emacs-lisp-intro.info)fwd-para between paragraphs


Next: fwd-para within paragraph Prev: fwd-para while Up: forward-paragraph
Enter node , (file) or (file)node

Between paragraphs
------------------

   First, let us look at the inner `while' loop.  This loop handles the
case when point is between paragraphs; it uses three functions that are
new to us: `prog1', `eobp' and `looking-at'.

   * `prog1' is similar to the `progn' special form, except that
     `prog1' evaluates its arguments in sequence and then returns the
     value of its first argument as the value of the whole expression.
     (`progn' returns the value of its last argument as the value of
     the expression.) The second and subsequent arguments to `prog1'
     are evaluated only for their side effects.

   * `eobp' is an abbreviation of `End Of Buffer P' and is a function
     that returns true if point is at the end of the buffer.

   * `looking-at' is a function that returns true if the text following
     point matches the regular expression passed `looking-at' as its
     argument.

   The `while' loop we are studying looks like this:

     (while (prog1 (and (not (eobp))
                        (looking-at paragraph-separate))
                   (forward-line 1)))

This is a `while' loop with no body!  The true-or-false-test of the
loop is the expression:

     (prog1 (and (not (eobp))
                 (looking-at paragraph-separate))
            (forward-line 1))

The first argument to the `prog1' is the `and' expression.  It has
within in it a test of whether point is at the end of the buffer and
also a test of whether the pattern following point matches the regular
expression for separating paragraphs.

   If the cursor is not at the end of the buffer and if the characters
following the cursor mark the separation between two paragraphs, then
the `and' expression is true.  After evaluating the `and' expression,
the Lisp interpreter evaluates the second argument to `prog1', which is
`forward-line'.  This moves point forward one line.  The value returned
by the `prog1' however, is the value of its first argument, so the
`while' loop continues so long as point is not at the end of the buffer
and is between paragraphs.  When, finally, point is moved to a
paragraph, the `and' expression tests false.  Note however, that the
`forward-line' command is carried out anyhow.  This means that when
point is moved from between paragraphs to a paragraph, it is left at
the beginning of the second line of the paragraph.


automatically generated by info2www version 1.2.2.9