Making Aquamacs kill and yank work with the clipboard

by Thomas Beutel

My favorite editor on the Mac is Aquamacs (me and Emacs go waaay back) and something that has long been a productivity killer for me was the different actions of C-y and CMD-V.

This is due to there being two clipboards, the one belonging to the Mac and the one in Emacs (the kill ring).

Often I would use one or the other and get the wrong pasted contents. Then I’d have to stop, back up, and find the original contents and do it again. Worse, sometimes the contents would be cut or killed, meaning that I would have to undo the cut/kill, redo the cut/kill, then yank/paste.

Well, I finally had enough and looked for ways to harmonize the two clipboards via the .emacs file. Here is what I came up with:

(defun swap-and-kill ()
"Swap point and mark, then clipboard kill region"
(clipboard-kill-region (region-beginning) (region-end))
(global-set-key "\C-w" 'swap-and-kill)
(global-set-key "\M-w" 'clipboard-kill-ring-save)
(global-set-key "\C-y" 'clipboard-yank)

Now everything goes to the Mac clipboard, even if I use my beloved mark and point with C-w.

I found most of the clues for this solution here: