Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy to clipboard in Emacs Lisp

Tags:

emacs

elisp

I want to copy a string to the clipboard (not a region of any particular buffer, just a plain string). It would be nice if it were also added to the kill-ring. Here's an example:

(copy-to-clipboard "Hello World") 

Does this function exist? If so, what is it called and how did you find it? Is there also a paste-from-clipboard function?

I can't seem to find this stuff in the Lisp Reference Manual, so please tell me how you found it.

like image 773
User1 Avatar asked Feb 01 '10 17:02

User1


People also ask

How do I copy from emacs to clipboard?

An Emacs copy is the command kill-ring-save (usually bound to M-w ). A system copy is what you typically get from pressing C-c (or choosing "Edit->Copy" in a application window). An X copy is "physically" highlighting text with the mouse cursor. An Emacs paste is the command yank (usually bound to C-y ).

How do you copy in emacs terminal?

When you copy and paste text, the terminal does it : you're taking the text that the terminal displays and not the text that is in your emacs app. That's why you have to use terminal keybindings : Ctrl-Shift-C and Ctrl-Shift-V to copy and paste text.

Is Emacs Lisp the same as Lisp?

By default, Common Lisp is lexically scoped, that is, every variable is lexically scoped except for special variables. By default, Emacs Lisp files are dynamically scoped, that is, every variable is dynamically scoped.


1 Answers

You're looking for kill-new.

kill-new is a compiled Lisp function in `simple.el'.  (kill-new string &optional replace yank-handler)  Make string the latest kill in the kill ring. Set `kill-ring-yank-pointer' to point to it. If `interprogram-cut-function' is non-nil, apply it to string. Optional second argument replace non-nil means that string will replace the front of the kill ring, rather than being added to the list.  Optional third arguments yank-handler controls how the string is later inserted into a buffer; see `insert-for-yank' for details. When a yank handler is specified, string must be non-empty (the yank handler, if non-nil, is stored as a `yank-handler' text property on string).  When the yank handler has a non-nil PARAM element, the original string argument is not used by `insert-for-yank'.  However, since Lisp code may access and use elements from the kill ring directly, the string argument should still be a "useful" string for such uses. 
like image 131
Joe Casadonte Avatar answered Sep 24 '22 23:09

Joe Casadonte