emacs终端模式:如何有效地复制和粘贴

gal*_*ica 11 emacs copy-paste

我很难让这个emacs -nw在终端模式下有效工作(emacs -nw).一些设置信息:工作服务器通过SSH连接,emacs正在服务器上运行.通常我使用SSH连接和"emacs -nw"来处理我的文件.

emacs配置来自:https://hugoheden.wordpress.com/2009/03/08/copypaste-with-emacs-in-terminal/

;; make mouse selection to be emacs region marking
(require 'mouse)
(xterm-mouse-mode t)
(defun track-mouse (e)) 
(setq mouse-sel-mode t)

;; enable clipboard in emacs
(setq x-select-enable-clipboard t)

;; enable copy/paste between emacs and other apps (terminal version of emacs)
(unless window-system
 (when (getenv "DISPLAY")
  ;; Callback for when user cuts
  (defun xsel-cut-function (text &optional push)
    ;; Insert text to temp-buffer, and "send" content to xsel stdin
    (with-temp-buffer
      (insert text)
      ;; I prefer using the "clipboard" selection (the one the
      ;; typically is used by c-c/c-v) before the primary selection
      ;; (that uses mouse-select/middle-button-click)
      (call-process-region (point-min) (point-max) "xsel" nil 0 nil "--clipboard" "--input")))
  ;; Call back for when user pastes
  (defun xsel-paste-function()
    ;; Find out what is current selection by xsel. If it is different
    ;; from the top of the kill-ring (car kill-ring), then return
    ;; it. Else, nil is returned, so whatever is in the top of the
    ;; kill-ring will be used.
    (let ((xsel-output (shell-command-to-string "xsel --clipboard --output")))
      (unless (string= (car kill-ring) xsel-output)
        xsel-output )))
  ;; Attach callbacks to hooks
  (setq interprogram-cut-function 'xsel-cut-function)
  (setq interprogram-paste-function 'xsel-paste-function)
  ;; Idea from
  ;; http://shreevatsa.wordpress.com/2006/10/22/emacs-copypaste-and-x/
  ;; http://www.mail-archive.com/help-gnu-emacs@gnu.org/msg03577.html
 ))
Run Code Online (Sandbox Code Playgroud)

有原因:

 (require 'mouse)
 (xterm-mouse-mode t)
 (defun track-mouse (e)) 
 (setq mouse-sel-mode t)
Run Code Online (Sandbox Code Playgroud)

是在文本上启用鼠标选择,使文本区域突出显示为标记区域的"Cx SPC".然后我可以使用"Mx w"复制和"Cx y"在emacs中以及emacs和其他应用之间粘贴文本.

一切看起来都很完美,除了与X相关的任何操作真的很慢!我与远程服务器的连接很顺利 - 延迟通常低于100毫秒.但要使用"Cx k"杀死一行文本,需要约5秒钟!粘贴它需要5秒钟!

当有时复制/粘贴时,这变得非常烦人.我认为这与X服务器消息传递有关,但不确定是否有好的方法来解决这个问题.

有任何想法吗?谢谢!

gal*_*ica 5

这本身并不是一个理想的解决方案,但是我想出了一种比以前更好的感觉。

这样做的目的是摆脱X,这会导致严重的延迟问题,即仅保留以下内容:

;; enable clipboard in emacs
(setq x-select-enable-clipboard t)
Run Code Online (Sandbox Code Playgroud)

结果是:

  1. 在Emacs中复制/粘贴非常简单快捷。

  2. 从其他应用复制到Emacs:Ctrl + Shift + v

  3. 从Emacs复制到其他应用程序:鼠标选择现在位于X Selection上,因此右键单击并复制会将文本复制到Selection中。请注意,“ Mw”现在不会将任何内容复制到Selection或系统剪贴板中。

这再次是一种折衷而不是解决方案,但是考虑到我比应用程序间操作更频繁地复制/粘贴,这一点目前是可以接受的。

仍然期待一个好的解决方案!