If I paste a piece of code from the browser to emacs -nw
with middle mouse button, or Ctrl+Shift+v (in gnome-terminal paste from clipboard), it's incorrectly indented.
Original code:
for (i=0; i<=10; i++) {
j = j + i;
print j;
}
Becomes:
for (i=0; i<=10; i++) {
j = j + i;
print j;
}
In vim one would turn off auto-indent. In emacs I tried 2 ways that doesn't work:
Method 1:
Configure ctrl+y to use PRIMARY selection in ~/.emacs
(setq x-select-enable-primary t)
And try to paste with Ctrl-y instead of middle-mouse-key or Ctrl+Shift+V. Result: ctrl-y only pastes from emacs' kill ring, not from external selection.
Method 2: Unmap RET from newline-and-indent
:
(add-hook 'lisp-mode-hook '(lambda ()
(local-set-key (kbd "RET") 'newline)))
It works for typing RET (no indent), but for middle-mouse-key or Ctrl+Shift+V auto-indent is applied anyway.
Autoindentation occurs in emacs when the newline character is encountered. You can use
electric-indent-local-mode
andelectric-indent-mode
to toggle this setting.From http://emacsredux.com/blog/2013/03/29/automatic-electric-indentation/