When you paste some text into a terminal, the application sees it just as if you had typed the clipboard content. Depending on the software involved (operating system, clipboard mechanism, terminal emulator, Emacs and the system libraries that it uses), this can result in text being lost, or in text being changed because some inputs trigger special behavior. A common kind of special behavior is automatic indentation after line breaks, which increases whatever indentation is in what you paste.
A sure-fire way to avoid trouble is to not paste through the terminal. You can obviously do that by running a GUI Emacs, but it may be possible even in a terminal Emacs. I think that on macOS, as long as Emacs is running locally (as opposed to remotely, e.g. via SSH), you can run the pbpaste
command to output the clipboard content.
M-1 M-! pbpaste RET
The analog on systems using X11 is M-1 M-! xsel -b RET
or M-1 M-! xclip -sel c RET
(for what X11 calls the clipbard; plain xsel
or xclip -o
gives you the text selected with the mouse but not explicitly copied). This works in a terminal Emacs as long as the environment variables to connect to the X11 display are set (DISPLAY
and if needed XAUTHORITY
), which is typically the case if you always work in a GUI session, but may not be the case if Emacs is running under Screen or Tmux.
emacs -Q
(no init file).