简体   繁体   English

如何让emacs自动缩进Python代码?

[英]How to make emacs automatically indent Python code?

I'm using emacs 24.3 and Ubuntu 12.04 LTS. 我正在使用emacs 24.3和Ubuntu 12.04 LTS。 How do I make emacs automatically indent lines in Python, like in IDLE? 如何让emacs自动缩进Python中的行,比如IDLE? Currently, it does not do that. 目前,它没有这样做。

Also, in general, how would I do this for any programming language, say, Java or c++? 另外,一般来说,我如何为任何编程语言(例如Java或c ++)执行此操作?

Try electric-indent-mode . 尝试electric-indent-mode It will be ebabled by default in Emacs-24.4. 默认情况下,它将在Emacs-24.4中出现。 But note that the version in 24.3 probably doesn't work too well in python-mode buffers. 但请注意,24.3中的版本可能在python模式缓冲区中不能很好地工作。

You can try other python modes, like emacs-for-python or elpy, as given by this doc: http://wikemacs.org/index.php/Python (though the default mode works fine for me on the same config). 您可以尝试其他python模式,如emacs-for-python或elpy,如此文档所给出的: http ://wikemacs.org/index.php/Python(虽然默认模式对我来说在同一个配置上运行正常)。

You can install them with package.el ( Mx package-install RET elpy RET ) and call them as explained. 您可以使用package.el( Mx package-install RET elpy RET )安装它们,并按照说明调用它们。

用Cj打开换行符,你应该得到缩进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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