代码之家  ›  专栏  ›  技术社区  ›  User1

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

  •  26
  • User1  · 技术社区  · 15 年前

    我想将一个字符串复制到剪贴板(不是任何特定缓冲区的区域,只是一个普通字符串)。如果它也被添加到杀死戒指里,那就太好了。下面是一个例子:

    (copy-to-clipboard "Hello World")

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

    我似乎在Lisp参考手册中找不到这些东西,请告诉我你是怎么找到的。

    4 回复  |  直到 8 年前
        1
  •  44
  •   Adobe    8 年前

    你在找 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.
    
        2
  •  3
  •   scottfrazer    15 年前

    我这样做:

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

    把它放在剪贴板上。如果你想在杀人戒指上加一个 kill-region 形式也。

        3
  •  0
  •   Noufal Ibrahim    15 年前

    将所选内容放入窗口系统剪贴板的命令是 x-select-text . 你可以给它一块文字来记住。所以A (buffer-substring (point) (mark)) 或者一些东西应该给你你需要传递的东西。在乔的回答中,您可以看到程序间切割功能。看看怎么找到这个。

        4
  •  0
  •   Markus Barthlen    10 年前

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

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

    我不能使用ctrl-c(或系统拷贝),但这可能足以防止旧习惯的出现。