Reputation: 1440
it is said in the manual that if you use kill-region sequentially, the texts you kill will be concatenated into one in the kill-ring.
I'm just confused how this works. So I tried to eval this in the scratch buffer:
(progn
(kill-region 1 5) ; this kills ";; T"
(kill-region 1 5)); this kills "his "
what I expect is that, since I use kill-region 2 times, the killed texts should be concatenated as one in the kill-ring.
but when I use C-y, I get only "his ".
So I have 2 questions here:
in lisp, how to invoke kill-region several times so that the killed texts are concatenated?
using keyboard C-w, how to invoke kill-region several times so that the killed texts are concatenated? since the typical workflow is kill-region(C-w), then move-cursor, then kill-region again.
here is the doc string of kill region. isn't the 2nd paragraph and the last paragraph contradictory?
"Kill (\"cut\") text between point and mark.
This deletes the text from the buffer and saves it in the kill ring.
The command \\[yank] can retrieve it from there.
\(If you want to save the region without killing it, use \\[kill-ring-save].)
If you want to append the killed region to the last killed text,
use \\[append-next-kill] before \\[kill-region].
If the buffer is read-only, Emacs will beep and refrain from deleting
the text, but put the text in the kill ring anyway. This means that
you can use the killing commands to copy text from a read-only buffer.
Lisp programs should use this function for killing text.
(To delete text, use `delete-region'.)
Supply two arguments, character positions indicating the stretch of text
to be killed.
Any command that calls this function is a \"kill command\".
If the previous command was also a kill command,
the text killed this time appends to the text killed last time
to make one entry in the kill ring."
Upvotes: 3
Views: 376
Reputation: 17707
The documentation refers to commands, not functions. A command is a function that initiates the command loop.
Any command that calls this function is a \"kill command\". If the previous command was also a kill command, the text killed this time appends to the text killed last time to make one entry in the kill ring.
This does not mean kill-region
per se. It's saying any command that calls the
kill-region
function becomes a "kill command" (including kill-region
itself). E.g. kill-line
kill-word
, etc
Use kill-append
.
(progn
(kill-region 1 5) ; this kills ";; T"
(kill-region 1 5)); this kills "his "
what I expect is that, since I use kill-region 2 times, the killed texts should be concatenated as one in the kill-ring.
You called kill-region twice but not as commands. Both these calls happen within the same command loop run.
Upvotes: 4