Posts (summary)
Posts (full)

Emacs and python-mode

Some assholes decided around Emacs 24.1 it is a good idea if python-mode works completely different from the rest of Emacs, namely it automatically indents after RET. I tried to live with it, but after like 5 minutes, it was enough, and I was searching for a solution. Fortunately devs decided it’s something you don’t want to turn off using customize. Sigh. Anyway, add the following to .emacs, and it’ll work just like old times.

(defun python-mode-normalize ()
  (local-set-key (kbd "RET") 'newline)
  (local-set-key (kbd "<backspace>") 'backward-delete-char-untabify)
  (local-set-key (kbd "<delete>") 'delete-forward-char))
(add-hook 'python-mode-hook 'python-mode-normalize)

It also disables electric backspace and delete. If you do not want it, delete the <backspace> and <delete> bindings from the code above.