Add the system clipboard to the Emacs kill-ring

This post was originally titled “Prevent Emacs wiping the system clipboard”, which was a rubbish description of what this tip actually covers, so I renamed it! Apologies if you see it twice in your RSS reader.

I wrote previously about adding mouse selections in Emacs to the system clipboard, and here is another tip to integrate the system clipboard more nicely with Emacs. This comes from the fantastic Emacs operating system set of configuration files, which are full of gems like this (thanks to Irreal for pointing me to EOS).

By default, if you copy something to the system clipboard (e.g. some text in firefox) and then copy or kill some text in Emacs, then the text from firefox is lost. If you set the option below in your emacs config file then copying or killing text in Emacs will add the system clipboard text to the kill-ring so that you can find it when you cycle through your clipboard history in Emacs.

;; Save whatever’s in the current (system) clipboard before
;; replacing it with the Emacs’ text.
(setq save-interprogram-paste-before-kill t)


  1. Hm, apparently `(setq x-select-enable-clipboard t)` defaults to `t` since emacs 24.1. It is a good change, from the “just do what the user wants” point of view.

    Maybe its sister variable `save-interprogram-paste-before-kill` could use a more sensible default as well…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s