集成Emacs复制/粘贴与系统复制/粘贴 [英] Integrate Emacs copy/paste with System copy/paste

查看:180
本文介绍了集成Emacs复制/粘贴与系统复制/粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.emacs中有(cua-mode t),所以C-c是复制的,C-v就像我桌面上的大多数其他程序一样粘贴(Ubuntu,Gnome,Linux)。但是,Emacs似乎没有与其他程序共享剪贴板/复制缓冲区。



例如,如果我在Firefox中的Cc可以将SCv粘贴到终端或Cv粘贴到gedit。然而,如果我在emacs中的C-v(或C-y),我没有得到我从Firefox复制的东西。



有没有办法使这项工作?是否有另一个命令可以用来访问系统的复制粘贴缓冲区?

解决方案

这在我的机器上有效:

  ;; CUA OS copypasta甚至在ncurses模式
(case system-type
('darwin(除非window-system
(setq interprogram-cut-function
(lambda(text& optional push)
(let *((process-connection-type nil)
(pbproxy(start-processpbcopypbcopy/ usr / bin / pbcopy)))
process-send-string pbproxy text)
(process-send-eof pbproxy))))))
('gnu / linux(progn
(setq x-select-enable-clipboard t )
(defun xsel-cut-function(text& optional push)
(with-temp-buffer
(insert text)
(call-process-region(point- min)(point-max)xselnil 0 nil--clipboard--input)))
(defun xsel-paste-function()

(let (xsel-output(shell-command-to-stringxsel --clipboard --output)))
(除非(string =(car kill-ring)xsel-output)
xsel-output)))
(setq interprogram-cut-function'xsel-cut-function)
(setq interprogram -paste-function'xsel-paste-function))))


I have (cua-mode t) in my .emacs, so that C-c is copy and C-v is paste just like most other programs on my desktop (Ubuntu, Gnome, Linux). However, Emacs does not seem to share the clipboard/copy buffer with other programs.

For example, if I C-c in Firefox I can S-C-v to paste into a terminal or C-v to paste into gedit. However, if I C-v (or C-y) in emacs, I do not get what I copied from Firefox.

Is there any way to make this work? Is there another command I can use to access the system's copy-paste buffer?

解决方案

This works on my machine:

;; CUA OS copypasta even in ncurses mode
(case system-type
  ('darwin (unless window-system
             (setq interprogram-cut-function
                   (lambda (text &optional push)
                     (let* ((process-connection-type nil)
                            (pbproxy (start-process "pbcopy" "pbcopy" "/usr/bin/pbcopy")))
                       (process-send-string pbproxy text)
                       (process-send-eof pbproxy))))))
  ('gnu/linux (progn
                (setq x-select-enable-clipboard t)
                (defun xsel-cut-function (text &optional push)
                  (with-temp-buffer
                    (insert text)
                    (call-process-region (point-min) (point-max) "xsel" nil 0 nil "--clipboard" "--input")))
                (defun xsel-paste-function()

                  (let ((xsel-output (shell-command-to-string "xsel --clipboard --output")))
                    (unless (string= (car kill-ring) xsel-output)
                      xsel-output )))
                (setq interprogram-cut-function 'xsel-cut-function)
                (setq interprogram-paste-function 'xsel-paste-function))))

这篇关于集成Emacs复制/粘贴与系统复制/粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆