Note #2024-09-24-001
#Emacs #TIL : I learned about save-interprogram-paste-before-kill
- which saves the existing system clipboard text into the kill ring before replacing it. This ensures that Emacs kill operations do not irrevocably overwrite existing clipboard text.
A common workflow for me is to copy some text from a different application and paste it inside Emacs. But, if I want to first delete a word or region to replace, the deleted word or region goes to the system clipboard and replaces my copied text. This config saves the previous entry in the system clipboard so I can do a C-p
after paste to choose the previous paste.
Interactions
👍 8 likes
🔁 5 reposts
Oh my!! This is a life-changing #Emacs #TIL.
tl;dr:
I live in Emacs and #EXWM. I can copy text from anywhere (including graphical applications) and yank it to an Emacs buffer. However, when text was copied from a graphical app, it could then get overwritten (and lost) by a subsequent Emacs kill.
save-interprogram-paste-before-kill
makes the kill/yank behaviour consistent across buffers and graphical applications.Thanks @srijan for the original post and @sacha for RT. 🙏
I don't understand. How do emacs kill operations affect the system clipboard at all? In my experience, they don't (and I have to use special commands like
clipboard-kill-region
andclipboard-yank
to interact with the system clipboard from emacs).To be explicit, yes I'm talking about a graphical (X11) emacs, on Linux.
--
Ian
At least newer versions of emacs copy to the system clipboard on regular kill. You might have an old Emacs, or a config somewhere that disables this behavior.
Please check https://www.gnu.org/software/emacs/manual/html_node/emacs/Clipboard.html for details.
I see, it's
select_enable_clipboard
. Now that I think about it, I do in fact prefer it this way. I want emacs to be a separate little playground with narrow and controlled pathways to the world beyond.--
Ian