Maintaining the System Clipboard Over an Emacs Kill

Ben Maughan has a nice tip for Clipboard/Emacs Kill Ring interaction. In recent versions of Emacs at least, you can yank the value of the system clipboard as long as nothing has been put in the kill ring since the time that the value in the clipboard was set. That works well and I often use it to copy some text from, say, a Web page and then yank it into an Emacs buffer.

The problem is that if you kill something in Emacs in the meantime, the clipboard value is lost because it’s not actually added to the kill ring. Maughan gives us a one-line fix that causes the clipboard to be pushed onto the kill ring if necessary. That means that you can still retrieve it even if there’s an intervening kill. That’s really handy. I often copy text from the browser, return to Emacs, do some editing that involves a kill, and then end up having to copy the text from the browser again. With this fix, it’s still in the kill ring and retrievable. Very nice. I wish I’d known about this sooner.

This entry was posted in General and tagged . Bookmark the permalink.