Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a 'set paste' option in Emacs to paste paste from external clipboard?

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?

like image 977
Hongxu Chen Avatar asked Sep 09 '13 05:09

Hongxu Chen


2 Answers

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)))))
like image 176
Stefan Avatar answered Nov 03 '22 00:11

Stefan


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.

like image 25
edt_devel Avatar answered Nov 03 '22 00:11

edt_devel