2018-02-12 append-next-kill

Today I’d like to share a simple trick which I learned a few days ago. It is well-known that if you perform a few killing commands in a row (like C-k or M-d), only one entry is put into the kill ring. Sometimes, however, I want to kill things in different places and still combine them into one kill ring entry. Enter C-M-w, or M-x append-next-kill. It makes the next killing command append its prey to the last kill ring entry. (If you do something, erm, non-lethal after append-next-kill, it has no effect.)

Actually, it does even more. If the next kill command kills backward, then the killed text is prepended to the kill ring entry. And in case of C-w (kill-region), the “direction” of killing is determined using the relation of point and mark: if the point is after the mark, the kill is considered a forward one, and if the point is before the mark, a backward one.

You may wonder how all this is actually implemented. It turns out that append-next-kill is actually very simple. Go look up its definition, it’s very instructive. (In particular, it utilizies a nice way of determining whether it was run interactively and acting accordingly. If not for that, it would actually be a one-liner!)

What can I say? Happy killing! ;-)

CategoryEnglish, CategoryBlog, CategoryEmacs