Emacs and remote X Windows

I work at home occasionally, using plain old SSH to VPN in to work. I forward X Windows over SSH, so I can run shells and Emacs on my work machine and display them locally on my laptop.

This works ok, but it can be dog slow at times. The biggest annoyance is the kill ring. Whenever Emacs kills or yanks text, it synchronizes itself with the X Windows clipboard so you can copy and paste between Emacs and other apps. However, I don’t do that much, and it causes a noticeable lag if you’re displaying remotely. So, I turn it off with this elisp in my .emacs:

(setq interprogram-cut-function nil)
(setq interprogram-paste-function nil)

Of course, the obvious drawback is that you suddently can’t copy or paste between Emacs and other programs. When I need to, I use this elisp:

(global-set-key [(escape) (meta w)]
  (lambda ()
    (interactive)
    (eval-expression
      '(setq interprogram-cut-function
             'x-select-text))
    (kill-ring-save (region-beginning) (region-end))
    (eval-expression
      '(setq interprogram-cut-function nil))))

(global-set-key [(escape) (control y)]
  (lambda ()
    (interactive)
    (eval-expression
      '(setq interprogram-paste-function
             'x-cut-buffer-or-selection-value))
    (yank)
    (eval-expression
      '(setq interprogram-paste-function nil))))

This binds Esc M-w to copy to the X selection and Esc C-y to paste from the X selection or cut buffer.

One thought on “Emacs and remote X Windows

  1. Thanks for this little tidbit of info. No more twiddling my thumbs on ctrl-k’s :-)

    Oh, btw, at least in XEmacs you can use C-insert (copy) and Sh-insert (paste) to use the clipboard-sharing copy feature. Don’t know if this works in Emacs, though.

    /TT

Leave a Reply

Your email address will not be published. Required fields are marked *