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

Use*_*er1 34 emacs elisp

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

paste-from-clipboard

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

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

Joe*_*nte 52

你在找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.
Run Code Online (Sandbox Code Playgroud)

  • 实际上,描述中说它适​​用于kill-ring,它是一种内部结构,可能与剪贴板有关,也可能无关。特别是对我来说,`(kill-new "hello")` 不会修改剪贴板。 (3认同)
  • 好吧,(杀死了新的“ Hello World”)效果很好。谢谢! (2认同)

sco*_*zer 5

我这样做:

(with-temp-buffer
  (insert "Hello World")
  (clipboard-kill-region (point-min) (point-max)))
Run Code Online (Sandbox Code Playgroud)

这样就可以将其保存到剪贴板上。如果你想在杀戮环上添加一个kill-region表格。