elisp: Kill Functions
31.8.2 Functions for Killing
----------------------------
‘kill-region’ is the usual subroutine for killing text. Any command
that calls this function is a kill command (and should probably have
‘kill’ in its name). ‘kill-region’ puts the newly killed text in a new
element at the beginning of the kill ring or adds it to the most recent
element. It determines automatically (using ‘last-command’) whether the
previous command was a kill command, and if so appends the killed text
to the most recent entry.
The commands described below can filter the killed text before they
save it in the kill ring. They call ‘filter-buffer-substring’ (
Buffer Contents) to perform the filtering. By default, there’s no
filtering, but major and minor modes and hook functions can set up
filtering, so that text saved in the kill ring is different from what
was in the buffer.
-- Command: kill-region start end &optional region
This function kills the stretch of text between START and END; but
if the optional argument REGION is non-‘nil’, it ignores START and
END, and kills the text in the current region instead. The text is
deleted but saved in the kill ring, along with its text properties.
The value is always ‘nil’.
In an interactive call, START and END are point and the mark, and
REGION is always non-‘nil’, so the command always kills the text in
the current region.
If the buffer or text is read-only, ‘kill-region’ modifies the kill
ring just the same, then signals an error without modifying the
buffer. This is convenient because it lets the user use a series
of kill commands to copy text from a read-only buffer into the kill
ring.
-- User Option: kill-read-only-ok
If this option is non-‘nil’, ‘kill-region’ does not signal an error
if the buffer or text is read-only. Instead, it simply returns,
updating the kill ring but not changing the buffer.
-- Command: copy-region-as-kill start end &optional region
This function saves the stretch of text between START and END on
the kill ring (including text properties), but does not delete the
text from the buffer. However, if the optional argument REGION is
non-‘nil’, the function ignores START and END, and saves the
current region instead. It always returns ‘nil’.
In an interactive call, START and END are point and the mark, and
REGION is always non-‘nil’, so the command always saves the text in
the current region.
The command does not set ‘this-command’ to ‘kill-region’, so a
subsequent kill command does not append to the same kill ring
entry.