Here is the complete text of the version 22
(defun copy-region-as-kill (beg end) "Save the region as if killed, but don't kill it. In Transient Mark mode, deactivate the mark. If `interprogram-cut-function' is non-nil, also save the text for a window system cut and paste." (interactive "r")
(if (eq last-command 'kill-region) (kill-append (filter-buffer-substring beg end) (< end beg)) (kill-new (filter-buffer-substring beg end)))
(if transient-mark-mode (setq deactivate-mark t)) nil)
As usual, this function can be divided into its component parts:
(defun copy-region-as-kill (argument-list) "documentation…" (interactive "r") body…)
The arguments are
end and the function is
"r", so the two arguments must refer to the
beginning and end of the region. If you have been reading through this
document from the beginning, understanding these parts of a function is
almost becoming routine.
The documentation is somewhat confusing unless you remember that the
word ‘kill’ has a meaning different from usual. The ‘Transient Mark’
interprogram-cut-function comments explain certain
After you once set a mark, a buffer always contains a region. If you wish, you can use Transient Mark mode to highlight the region temporarily. (No one wants to highlight the region all the time, so Transient Mark mode highlights it only at appropriate times. Many people turn off Transient Mark mode, so the region is never highlighted.)
Also, a windowing system allows you to copy, cut, and paste among
different programs. In the X windowing system, for example, the
interprogram-cut-function function is
which works with the windowing system’s equivalent of the Emacs kill
The body of the
copy-region-as-kill function starts with an
if clause. What this clause does is distinguish between two
different situations: whether or not this command is executed
immediately after a previous
kill-region command. In the first
case, the new region is appended to the previously copied text.
Otherwise, it is inserted into the beginning of the kill ring as a
separate piece of text from the previous piece.
The last two lines of the function prevent the region from lighting up if Transient Mark mode is turned on.
The body of
copy-region-as-kill merits discussion in detail.