Go to the previous, next section.

The body of the  progn expression

The body of the  progn consists of two expressions. Spread out to delineate the different parts more clearly, and with comments added, the  progn expression looks like this:


  (goto-char                ; First expression in  progn .
        (if (> arg 0)       ; If  arg  is positive,
            (1- (point))    ;   move back one character;
          (1+ (point))))    ;   else move forward one character.

  (point))                  ; Second expression in  progn :
                            ;   return position of point.

The  progn expression does this: when the search is forward ( arg is positive), Emacs leaves point just after the searched-for character. By moving point back one position, the character is uncovered. In this case, the expression in the  progn reads as follows:  (goto-char (1- (point))) . This moves point one character back. (The  1- function subtracts one from its argument, just as  1+ adds ones to its argument.) On the other hand, if the argument to  zap-to-character is negative, the search will be backwards. The  if detects this and the expression reads:  (goto-char (1+ (point))) . (The  1+ function adds one to its argument.)

The second and last argument to  progn is the expression  (point) . This expression returns the value of the position to which point is moved by the first argument to  progn . This value is then returned by the  if expression of which it is a part and is passed to  kill-region as  kill-region 's second argument.

In brief, the function works like this: the first argument to  kill-region is the position of the cursor when the  zap-to-char command is given--the value of point at that time. The search function then moves point if the search is successful. The  progn expression moves point just enough so the zapped to character is not removed, and returns the value of point after all this is done. The  kill-region function then removes the region.

Finally, the else-part of the  if expression takes care of the situation in which the zapped-towards character is not found. If the argument to the  zap-to-char function is positive (or if none is given) and the zapped-to character is not found, all the text is removed from the current position of point to the end of the accessible region of the buffer (the end of the buffer if there is no narrowing). If the  arg is negative and the zapped-to character is not found, the operation goes to the beginning of the accessible region. The code for this is a simple  if clause:

(if (> arg 0) (point-max) (point-min))

This says that if  arg is a positive number, return the value of  point-max , otherwise, return the value of  point-min .

For review, here is the code involving  kill-region , with comments:

 (point)                    ; beginning-of-region
 (if (search-forward
      (char-to-string char) ; target
      nil                   ; limit-of-search: none
      t                     ; Return  nil  if fail.
      arg)                  ; repeat-count.
     (progn                 ; then-part
        (if (> arg 0)
            (1- (point))
          (1+ (point))))
   (if (> arg 0)            ; else-part

As you can see, the version 19 implementation does slightly less than the version 18 implementation, but is much simpler.

Go to the previous, next section.