我想将一个字符串复制到剪贴板(不是任何特定缓冲区的区域,只是一个普通的字符串)。如果能将它添加到kill-ring,那就更好了。以下是一个示例:
(copy-to-clipboard "Hello World")
这个函数存在吗?如果存在,它被称为什么,你是如何找到它的?还有一个名为paste-from-clipboard
的函数吗?
我在Lisp参考手册中似乎找不到这些内容,请告诉我你是如何找到它的。
我想将一个字符串复制到剪贴板(不是任何特定缓冲区的区域,只是一个普通的字符串)。如果能将它添加到kill-ring,那就更好了。以下是一个示例:
(copy-to-clipboard "Hello World")
这个函数存在吗?如果存在,它被称为什么,你是如何找到它的?还有一个名为paste-from-clipboard
的函数吗?
我在Lisp参考手册中似乎找不到这些内容,请告诉我你是如何找到它的。
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.
(kill-new "hello")
并不会修改剪贴板。 - Hi-AngelI do this:
(with-temp-buffer
(insert "Hello World")
(clipboard-kill-region (point-min) (point-max)))
这将把它复制到剪贴板上。如果你想要它在kill-ring中,也要添加一个kill-region
表单。
copy-region-as-kill
可以一次性将文本复制到剪贴板和 kill-ring 中:copy-region-as-kill
是 simple.el
中一个交互式的编译 Lisp 函数。(copy-region-as-kill beg end)将选定区域保存为已删除的文本,但不要删除它。
在瞬时标记模式下,取消标记。
如果 interprogram-cut-function
不为 nil,则还将文本保存到窗口系统的剪切板中。 - Joe Casadonte(global-set-key "\C-V" 'yank)
(global-set-key "\C-cc" 'kill-ring-save)
我不能使用Ctrl-C(或系统复制),但如果旧习惯发作,这可能已经足够了。
x-select-text
。您可以给它一个文本块来记住。因此,(buffer-substring (point) (mark))
或类似的东西应该为您提供需要传递给它的内容。在Joe的答案中,您可以看到interprogram-cut-function。查找有关如何找到它的信息。