www.delorie.com/gnu/docs/emacs-lisp-intro/emacs-lisp-intro_196.html   search  
Buy the book!

Programming in Emacs Lisp

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.

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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003