linux - 将Emacs复制/粘贴与系统复制/粘贴集成

我的.emacs中有(cua模式t),所以c-c是复制的,c-v是粘贴的,就像桌面上的大多数其他程序(ubuntu、gnome、linux)一样。但是,emacs似乎没有与其他程序共享剪贴板/复制缓冲区。
例如,如果在firefox中使用i c-c,我可以将s-c-v粘贴到终端中,或者将c-v粘贴到gedit中。但是,如果在emacs中使用i c-v(或c-y),我就无法从firefox中得到我复制的内容。
有什么方法可以使这个工作吗?是否可以使用其他命令访问系统的复制粘贴缓冲区?


最佳答案:

这在我的机器上工作:

;; 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))))