简体   繁体   中英

Enable auto-indent in python-mode (python.el) in Emacs 24?

I've recently declared emacs bankruptcy and in rebuilding my config switched from the old python-mode.el to the built-in python.el .

One thing that's I'm missing is the old behaviour of auto-indenting to the correct level when hitting RET . Is there any way to re-enable this?

Try this:

(add-hook 'python-mode-hook 'my-python-hook)

(defun my-python-hook ()
  (define-key python-mode-map (kbd "RET") 'newline-and-indent))

In upcoming Emacs 24.4 auto-indendation is enabled by default thanks to electric-indent-mode . Since Emacs 24.4 has been in feature-freeze for quite some time now, there should be no major breaking bugs left, so you could already make a switch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM