views:

50

answers:

2

I learned that copy something to kill buffer, I can use the kill-new buffer

(kill-new (file-truename buffer-file-name))

How about copying the content to clipboard? Does emacs/elisp provide the function?

ADDED

I got 2 answers, but the answer seems to apply X windows system. As I use Aquamacs, it may not be a universal solution that can be applied to my problem.

+2  A: 
(x-set-selection nil (file-truename buffer-file-name))

Documentation for x-set-selection says:

This function sets a “selection” in the X server. It takes two arguments: a selection type type, and the value to assign to it, data. If data is nil, it means to clear out the selection. Otherwise, data may be a string, a symbol, an integer (or a cons of two integers or list of two integers), an overlay, or a cons of two markers pointing to the same buffer. An overlay or a pair of markers stands for text in the overlay or between the markers.

The argument data may also be a vector of valid non-vector selection values.

Each possible type has its own selection value, which changes independently. The usual values of type are PRIMARY, SECONDARY and CLIPBOARD; these are symbols with upper-case names, in accord with X Window System conventions. If type is nil, that stands for PRIMARY.

Trey Jackson
+1  A: 

You can configure Emacs to automatically copy to the system clipboard as well as to the kill ring. The function kill-new calls interprogram-cut-function, which typically copies to a system clipboard if there is one. Under X Window, the variable x-select-enable-clipboard controls whether the primary selection or the clipboard is used.

Gilles
@Gilles : I'm using Aquamacs on Mac. What would be the code to test if the tip works? Putting (x-select-enable-clipboard 1) in .emacs?
prosseek
It's a variable, so `(setq x-select-enable-clipboard t)`. Or better (although it doesn't matter in this particular case), since it's a customization option, set it through the Customize interface. But I don't think it exists in Aquamacs, since that's not running under X.
Gilles