5

I just setup the latest Spacemacs. I'm pasting python code from here https://raw.githubusercontent.com/jpmens/mosquitto-auth-plug/master/examples/http-auth-be.py into a new buffer.

When I do this it indents almost every single line relative to the last. I'm using spacemacs from iTerm2 on OSX. I'm using Evil mode. I've tried toggling the value electric-indent-mode but ti doesn't help. I've also tried the command :set paste, but it gives me the error State paste cannot be set as initial Evil state.

So firstly, how do I stop the auto indentation? Secondly, what does the error message mean about the initial Evil state and how do I correct it?

1
  • Inside terminals is tougher, as Emacs doesn't “know” you're pasting vs typing. I believe Emacs 25 is better about it but I haven't tested it.
    – amitp
    Oct 22, 2016 at 4:30

3 Answers 3

5

Because you're using Emacs inside of a terminal emulator, it can't generally tell the difference between something that was typed in and something that is pasted in. You do have some options, though.

You could run Emacs directly, rather than running it inside of a terminal emulator. As a gui app Emacs can tell the difference and act accordingly.

If you're using Emacs 24 (or earlier), and your terminal supports the "bracketed paste" feature, then you can install the bracketed-paste Emacs package. If your terminal supports this feature, then it will surround your pastes with escape sequences. The bracketed-paste package uses these escape sequences to turn off indentation and other automatic behaviours for the duration of the paste.

If you're using Emacs 25, then you don't need to install any packages; bracketed pastes are supported out of the box. Perhaps iTerm2 doesn't support them, or perhaps you have to enable them first.

2
  • I didn't have any luck enabling bracketed paste with emacs 24.5. I upgraded to 25.1 and now the code pastes correctly without any extra commands. Thanks!
    – LaserJesus
    Oct 24, 2016 at 0:10
  • Worked perfectly for Emacs 24.4.1 under Debian Linux. Jan 18, 2017 at 18:04
1

What I've done is get out of emacs.

cat <somefile

paste the contents into the terminal

type EOF

Then read the file with emacs.

Ken

-1

The following works for me, works with both keyboard or mouse copy-pasting:

- emacs in a terminal
- remember your current mode
- copy
- go to text-mode   M-x text-mode
- paste
- go back to the mode you were in before
1
  • Probably quicker to simply unindent using rectangle cut.
    – RichieHH
    Feb 17, 2020 at 14:19

Your Answer

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

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