Search code examples
emacsclipboardcopy-paste

Elisp programmatically copy to clipboard clipboard


I am trying to copy the result some elisp code execution to my clipboard. I am looking for something that i could use like that.

(defun generate-string-to-my-clipboard ()
  (magic-function (foo-generate-string)))

After execution, i would be able to paste in my system the result of (foo-generate-string)

I have seen solution using kill-region or clipboard-kill-ring-save, but it needs a region or the string somewhere in a buffer, to select it. It could work, but feel a little far fetched.


Solution

  • You can use kill-new:

    (kill-new "this is copied to clipboard")
    

    (Assuming that x-select-enable-clipboard is set to its default value t.)