Note #2024-09-24-001

Srijan Choudhary Srijan Choudhary

#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

  • Fabio Natali

    Oh my!! This is a life-changing #Emacs #TIL.

    tl;dr:

    (setq save-interprogram-paste-before-kill t)

    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. 🙏

    Reply
  • Ian Z
    Ian Z

    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 and clipboard-yank to interact with the system clipboard from emacs).
    To be explicit, yes I'm talking about a graphical (X11) emacs, on Linux.

    --
    Ian

    Reply