如何在Emacs Lisp中复制到剪贴板

时间:2010-02-01 17:55:12

标签: emacs elisp

我想将一个字符串复制到剪贴板(不是任何特定缓冲区的区域,只是一个普通的字符串)。如果它也被添加到杀死环中会很好。这是一个例子:

(copy-to-clipboard "Hello World")

这个功能存在吗?如果是这样,它叫什么,你是怎么找到它的?是否还有paste-from-clipboard函数?

我似乎无法在Lisp参考手册中找到这些内容,所以请告诉我你是如何找到它的。

4 个答案:

答案 0 :(得分:48)

您正在寻找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.

答案 1 :(得分:3)

我这样做:

(with-temp-buffer
  (insert "Hello World")
  (clipboard-kill-region (point-min) (point-max)))

将它放在剪贴板上。如果你想在杀戮戒指上添加一个kill-region表格。

答案 2 :(得分:0)

将您的选择放在窗口系统剪贴板上的命令是x-select-text。你可以给它一块文字来记住。因此,(buffer-substring (point) (mark))或其他内容应该为您提供传递给它的内容。在Joe的回答中,您可以看到interprogram-cut-function。看看如何找到它。

答案 3 :(得分:0)

在我的.emacs文件中,我使用了这个

(global-set-key "\C-V" 'yank)
(global-set-key "\C-cc" 'kill-ring-save)

我无法使用Ctrl-C(或系统副本),但这可能足以让旧习惯起作用。