I have a lengthy xml output from a rest endpoint, I copied if from chrome dev tools to clipboard and on pasting it into an org mode buffer inside an xml source block freezes emacs for a while.

I guess this is because of emacs trying to syntax highlight the xml data.

Pasting the same data with mode changed to fundamental mode works without any issue.

How can I advice emacs to not parse long lines while pasting from clipboard.

  • If you could provide an example of a lengthy xml file which produces this problem, probable more people can help.
    – Name
    Commented Jan 20, 2018 at 20:22

1 Answer 1



It uses either Emacs internal API or third party CLI tool to insert the text. So syntax highlighting thing is skipped.

You can use simpleclip's default setup. But I recommend re-assign a more convenient key for pasting.

simpleclip doesn't work in certain scenario. See https://github.com/rolandwalker/simpleclip/issues/6 for details.

So my current solution combines simpleclip and my own code. It covers more scenarios than simpleclip (For example, access Windows 10 clipboard inside Linux Subsystem).

Insert below code into ~/.emacs and run M-x paste-from-x-clipboard to paste from clipboard:

(unless (featurep 'simpleclip) (require 'simpleclip))
(defun test-simpleclip ()
      (let (retval)
        (condition-case ex
              (simpleclip-set-contents "testsimpleclip!")
              (setq retval
                    (string= "testsimpleclip!"
           (message (format "Please install %s to support clipboard from terminal."
                             (or (eq system-type 'gnu/linux)
                                 (eq system-type 'linux)
                                 (eq system-type 'usg-unix-v)
                                 (eq system-type 'berkeley-unix))
                             ((or (eq system-type 'cygwin) (eq system-type 'windows-nt))
                              "cygutils-extra from Cygwin")
                              "CLI clipboard tools"))))
           (setq retval nil)))
(setq simpleclip-works (test-simpleclip))

(defun my-gclip ()
   ((eq system-type 'darwin)
      (with-current-buffer standard-output
        (call-process "/usr/bin/pbpaste" nil t nil "-Prefer" "txt"))))
   ((eq system-type 'cygwin)
      (with-current-buffer standard-output
        (call-process "getclip" nil t nil))))
   ((memq system-type '(gnu gnu/linux gnu/kfreebsd))
    (let* ((powershell-program (executable-find "powershell.exe")))
             ;; PowerLine adds extra white space character at the end of text
                (with-current-buffer standard-output
                  (call-process powershell-program nil t nil "-command" "Get-Clipboard")))))
               (with-current-buffer standard-output
                 (call-process "xsel" nil t nil "--clipboard" "--output")))))))))

(defun paste-from-x-clipboard()
  "Paste from clipboard."
  (interactive "P")
  ;; paste after the cursor in evil normal state
  (when (and (functionp 'evil-normal-state-p)
             (functionp 'evil-move-cursor-back)
             (not (eolp))
             (not (eobp)))
  (insert (my-gclip)))

The setup I post here is simplified version. See https://github.com/wangchen/redguardtoo-emacs.d/blob/master/lisp/init-clipboard.el for my real world setup.


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.