5

I am using Emacs on a remote machine which has no X-window through putty. The problem is that the copy/paste from external clipboard(Shift+Ins) is quite slow.

In Vim, there is an option set paste when I need to paste, then is there any similar function for Emacs?

I am currently trying some workarounds: before pasting, I change the major-mode into fundamental-mode, then I disable the minor modes displayed in modeline to make the side effect as minimal as possible. However it is still much slower than when started with emacs -Q. And in the display area(minibuffer), there are messages starting with "matches ... "(parentheses, etc.).

So how to solve it properly?

2 Answers 2

5

I don't know of such a "paste mode" for Emacs. You could start with something like the following (new version, using a separate buffer, so that the current buffer's *-change-functions only get called once at the end):

(defvar ttypaste-mode nil)
(add-to-list 'minor-mode-alist '(ttypaste-mode " Paste"))

(defun ttypaste-mode ()
  (interactive)
  (let ((buf (current-buffer))
        (ttypaste-mode t))
    (with-temp-buffer
      (let ((stay t)
            (text (current-buffer)))
        (redisplay)
        (while stay
          (let ((char (let ((inhibit-redisplay t)) (read-event nil t 0.1))))
            (unless char
              (with-current-buffer buf (insert-buffer-substring text))
              (erase-buffer)
              (redisplay)
              (setq char (read-event nil t)))
            (cond
             ((not (characterp char)) (setq stay nil))
             ((eq char ?\r) (insert ?\n))
             ((eq char ?\e)
              (if (sit-for 0.1 'nodisp) (setq stay nil) (insert ?\e)))
             (t (insert char)))))
        (insert-buffer-substring text)))))
4
  • It's really much faster! Would you please explain a bit about this snippet? Seems that there is still space to improve it:-) Sep 10, 2013 at 1:53
  • 1
    I updated the code with a slightly faster version (in a c-mode buffer, the difference is very significant). I haven't been able to speed this up any further tho (30s for 900KB on an AMD-E350). Maybe skipping the (eq char ?\r) test and doing a subst-char-in-region at the end would help, but I doubt the difference will be large.
    – Stefan
    Sep 11, 2013 at 15:31
  • Thanks so much, works fine; and I'll try to understand the code. Sep 12, 2013 at 5:53
  • BTW, in recent Emacsen, a similar piece of code is used automatically (at least in those text-terminals which support the "bracketed paste" feature), so you shouldn't need any of that gymnastics any more.
    – Stefan
    Jan 4, 2018 at 22:58
1

If you prefer something a bit more tested and used:

;; enable clipboard interaction between emacs and system
(setq x-select-enable-clipboard t)

It works for me. A simple C-y and you are good to go! Hope that helps.

2
  • No, I do not. Sorry I oversaw that detail. Did you try using C-S-v to use your Terminal clipboard? I tried that and it works with emacsclient -t on my system. If that is not satisfactory you could try something like xsel to have an external X clipboard manager for terminal usage. If that is still unsatisfactory you could try somthing like these methods. Please tell if these work for you.
    – edt_devel
    Sep 10, 2013 at 9:31
  • I'm sorry but it doesn't work since I am using putty connecting to a remote machine, which doesn't have X-window server. Also, C-S-v doesn't respond(at least Shift is eaten). Sep 10, 2013 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.