search-forward function is used to locate the
zap-to-char. If the search is
search-forward leaves point immediately after the
last character in the target string. (In
target string is just one character long.
zap-to-char uses the
char-to-string to ensure that the computer treats that
character as a string.) If the search is backwards,
search-forward leaves point just before the first character in
the target. Also,
t for true.
(Moving point is therefore a side effect.)
search-forward function looks like this:
(search-forward (char-to-string char) nil nil arg)
search-forward function takes four arguments:
As it happens, the argument passed to
zap-to-char is a single
character. Because of the way computers are built, the Lisp
interpreter may treat a single character as being different from a
string of characters. Inside the computer, a single character has a
different electronic format than a string of one character. (A single
character can often be recorded in the computer using exactly one
byte; but a string may be longer, and the computer needs to be ready
for this.) Since the
search-forward function searches for a
string, the character that the
zap-to-char function receives as
its argument must be converted inside the computer from one format to
the other; otherwise the
search-forward function will fail.
char-to-string function is used to make this conversion.
nilas the third argument causes the function to signal an error when the search fails.
search-forwardis the repeat count—how many occurrences of the string to look for. This argument is optional and if the function is called without a repeat count, this argument is passed the value 1. If this argument is negative, the search goes backwards.
In template form, a
search-forward expression looks like this:
(search-forward "target-string" limit-of-search what-to-do-if-search-fails repeat-count)
We will look at