eintr: append interactive
4.4.1 The ‘append-to-buffer’ Interactive Expression
---------------------------------------------------
Since the ‘append-to-buffer’ function will be used interactively, the
function must have an ‘interactive’ expression. (For a review of
‘interactive’, see Making a Function Interactive Interactive.)
The expression reads as follows:
(interactive
(list (read-buffer
"Append to buffer: "
(other-buffer (current-buffer) t))
(region-beginning)
(region-end)))
This expression is not one with letters standing for parts, as described
earlier. Instead, it starts a list with these parts:
The first part of the list is an expression to read the name of a
buffer and return it as a string. That is ‘read-buffer’. The function
requires a prompt as its first argument, ‘"Append to buffer: "’. Its
second argument tells the command what value to provide if you don’t
specify anything.
In this case that second argument is an expression containing the
function ‘other-buffer’, an exception, and a ‘t’, standing for true.
The first argument to ‘other-buffer’, the exception, is yet another
function, ‘current-buffer’. That is not going to be returned. The
second argument is the symbol for true, ‘t’. that tells ‘other-buffer’
that it may show visible buffers (except in this case, it will not show
the current buffer, which makes sense).
The expression looks like this:
(other-buffer (current-buffer) t)
The second and third arguments to the ‘list’ expression are
‘(region-beginning)’ and ‘(region-end)’. These two functions specify
the beginning and end of the text to be appended.
Originally, the command used the letters ‘B’ and ‘r’. The whole
‘interactive’ expression looked like this:
(interactive "BAppend to buffer: \nr")
But when that was done, the default value of the buffer switched to was
invisible. That was not wanted.
(The prompt was separated from the second argument with a newline,
‘\n’. It was followed by an ‘r’ that told Emacs to bind the two
arguments that follow the symbol ‘buffer’ in the function’s argument
list (that is, ‘start’ and ‘end’) to the values of point and mark. That
argument worked fine.)