I have this defined:

(setq electric-pair-pairs                                                                                                                                                                                                                     
        (?\" . ?\")                                                                                                                                                                                                                           
        (?\{ . ?\})                                                                                                                                                                                                                           
        (?\' . ?\')                                                                                                                                                                                                                           
        (?\< . ?\>)                                                                                                                                                                                                                           

If I paste this into emacs:

(global-set-key (kbd "C-x g") 'magit-status)

I get:

(global-set-key (kbd "C-x g") 'magit-status) ')

I foresee this will become a problem;)

1 Answer 1


You don't say so specifically, but I am going to guess that you are using Emacs inside a terminal. Outside of a terminal, Emacs explicitly knows when a paste is happening (because it is initiated as a paste and Emacs explicitly requests the content of the paste from the OS or X Windows or whatever). Thus Emacs can insert the pasted text into the buffer without triggering things like electric-pair-mode that should only activate on typed characters`

Inside a terminal things are more complicated. In principle, Emacs has only the incoming stream of characters and no idea that some of them were pasted rather than typed. However, many years ago everyone realized that this was a problem and a solution was devised. Your terminal emulator knows when you are pasting, and it can send an escape sequence before and after the pasted text. Emacs sees the escape sequence and treats all incoming data as part of a paste instead of type characters until it sees the correct escape sequence to go back to normal. This is frequently called "bracketed paste mode", although there's no specific mode in Emacs that you need to enable.

Instead, you probably need to upgrade or configure your terminal emulator so that it uses bracketed pastes. There's an outside chance that you need to upgrade Emacs; support for bracketed pastes was added in Emacs 25.

Either that or you need to describe your situation more completely.

  • Thanks;), yes, I'm in gnome-terminal. I couldn't quickly find a way to enable bracketed pastes, but I can also be open to running other terminals;). Another thing would probably be to have emacs talk to the clipboard. Sep 2, 2020 at 8:00
  • Emacs running in a terminal isn't going to also talk to X Windows. You could just run the Emacs gui instead.
    – db48x
    Sep 2, 2020 at 8:11
  • Emacs can talk to xclip, which talks to the clipboard. I always run Emacs in terminal to be able to use it over ssh. elpa.gnu.org/packages/xclip.html Sep 2, 2020 at 8:46

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.