2021-01-11 Deleting last entry from the kill ring

The Emacs’ kill ring is a brilliant and extremely useful concept. It has some drawbacks, too, though. Probably the biggest one is that the entries there persist for quite some time. This is, after all, what it’s for – but sometimes you explicitly want some entry to disappear. This is of course the case when you have some password or a similar thing you copy to e.g. config files.

I did a quick search, and came up with this Stack Overflow question. The (pop kill-ring) answer is actually not the best one, since it leaves kill-ring-yank-pointer unchanged. So, it’s better to use this one, or just install the browse-kill-ring package from MELPA. It allows, well, to browse the kill ring, delete entries from it and even edit them! Really nice.

One thing that is definitely worth mentioning is that the (pop kill-ring) trick (or, equivalently, (when kill-ring (setq kill-ring (cdr kill-ring)))) deletes the newest entry in the kill ring – even if some other one was selected using M-y. In my use-case (removing passwords) this is precisely what I want, but if your needs are different, probably the browse-kill-ring package is a better idea. It also avoids resetting kill-ring-yank-pointer like the linked answer does.

CategoryEnglish, CategoryBlog, CategoryEmacs