GNU Info

Info Node: (emacs-lisp-intro.info)zap-to-char interactive

(emacs-lisp-intro.info)zap-to-char interactive


Next: zap-to-char body Prev: Complete zap-to-char Up: zap-to-char
Enter node , (file) or (file)node

The `interactive' Expression
----------------------------

   The interactive expression in the `zap-to-char' command looks like
this:

     (interactive "*p\ncZap to char: ")

   The part within quotation marks, `"*p\ncZap to char: "', specifies
three different things.  First, and most simply, the asterisk, `*',
causes an error to be signalled if the buffer is read-only.  This means
that if you try `zap-to-char' in a read-only buffer you will not be
able to remove text, and you will receive a message that says "Buffer is
read-only"; your terminal may beep at you as well.

   The version 21 implementation does not have the asterisk, `*'.  The
function works the same as in version 19: in both cases, it cannot
remove text from a read-only buffer but the function does copy the text
that would have been removed to the kill ring.  Also, in both cases,
you see an error message.

   However, the version 19 implementation copies text from a read-only
buffer only because of a mistake in the implementation of
`interactive'.  According to the documentation for `interactive', the
asterisk, `*', should prevent the `zap-to-char' function from doing
anything at all when the buffer is read only.  The function should not
copy the text to the kill ring.  It is a bug that it does.

   In version 21, `interactive' is implemented correctly.  So the
asterisk, `*', had to be removed from the interactive specification.
If you insert an `*' and evaluate the function definition, then the
next time you run the `zap-to-char' function on a read-only buffer, you
will not copy any text.

   That change aside, and a change to the documentation, the two
versions of the  `zap-to-char' function are identical.

   Let us continue with the interactive specification.

   The second part of `"*p\ncZap to char: "' is the `p'.  This part is
separated from the next part by a newline, `\n'.  The `p' means that
the first argument to the function will be passed the value of a
`processed prefix'.  The prefix argument is passed by typing `C-u' and
a number, or `M-' and a number.  If the function is called
interactively without a prefix, 1 is passed to this argument.

   The third part of `"*p\ncZap to char: "' is `cZap to char: '.  In
this part, the lower case `c' indicates that `interactive' expects a
prompt and that the argument will be a character.  The prompt follows
the `c' and is the string `Zap to char: ' (with a space after the colon
to make it look good).

   What all this does is prepare the arguments to `zap-to-char' so they
are of the right type, and give the user a prompt.


automatically generated by info2www version 1.2.2.9