将 Emacs 复制/粘贴与系统复制/粘贴集成 [英] Integrate Emacs copy/paste with System copy/paste
问题描述
我的 .emacs 中有 (cua-mode t),所以 C-c 是复制的,C-v 是粘贴的,就像我桌面上的大多数其他程序(Ubuntu、Gnome、Linux)一样.但是,Emacs 似乎不与其他程序共享剪贴板/复制缓冲区.
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.
例如,如果我在 Firefox 中使用 C-c 我可以 S-C-v 粘贴到终端或 C-v 粘贴到 gedit.但是,如果我在 emacs 中使用 C-v(或 C-y),我不会得到从 Firefox 复制的内容.
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?
推荐答案
这适用于我的机器:
;; 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屋!