在 Emacs 中编辑 Python
我查看了 python-mode 和 python.el。我正在使用 python-mode.el。我还使用绳索和ropemacs。我正在寻找一些对我有帮助的文档,或者另一个 elisp 包或其他东西。
我当前的问题是我给出的代码的缩进大小不一致。对于某些块,它是两个,对于某些块,它是 4。我想清理它,但出于某种原因,当我告诉 emacs“修复缩进”时,它基本上只是在每一行上点击制表符,这会搞砸代码。我想要的是保持相同的相对缩进,但标准化为 4 个空格。有什么能让我轻松做到这一点吗?
我想我可以找到每个错误缩进的实例,将其阻止,然后查询将 2 个空格替换为 4 个空格。但这有点过于依赖我的精确度,注意应该在哪里完成此操作。此外,它的代码很多。
有人告诉我自行车修理工可以解决这个问题,但现在已经没有开发了好几年了......还有其他建议吗?
谢谢。
I've looked at python-mode and python.el. I'm using python-mode.el. I'm also using rope and ropemacs. I'm looking either for some documentation on these that helps me, or another elisp package or something.
My current problem is that the code I'm given has inconsistent indentation sizes. For some blocks it will be two, for some it will be 4. I want to clean this up, but For some reason, when I tell emacs "fix indentation" it just hits tab on every line basically, which screws up the code. What I want is to keep the same relative indentation, but standardize on 4 spaces. Will anything let me do this easily?
I suppose I could find each instance of bad indentation, block it, and query-replace 2 spaces with 4 spaces. But that relies a bit too much on my precision, noticing where this should be done. Also, it's a lot of code.
Someone told me that bicycle repairman would solve this, but that's been out of developement for several years now... Any other suggestions?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您已经使用 Sven Marnach 的注释来清理代码库,我猜您只需要让 python-mode.el 使用您喜欢的缩进样式即可?
查看变量 py-indent-offset 和 py-smart-indentation(也许还有 py-continuation-offset 和 py-smart-indentation) py-honor-comment-indentation)。以及普通的
indent-tabs-mode
。您可以自定义它们(Mx
customize-group
RETpython
RET),或者向python-mode-hook
添加自定义函数。例如:Assuming you've used Sven Marnach's comment to clean up the code base, I'm guessing you just need to make python-mode.el use the indentation style that you prefer?
Look at the variables
py-indent-offset
, andpy-smart-indentation
(and perhaps alsopy-continuation-offset
andpy-honor-comment-indentation
). As well as the normalindent-tabs-mode
.You can either Customize them (M-x
customize-group
RETpython
RET), or add a custom function topython-mode-hook
. e.g.:将 py-smart-indentation 设置为“t”
当前的 python-mode.el 应该可以做到。
http://launchpad.net/python-mode
如果出现错误,请在那里报告
with py-smart-indentation set to `t'
current python-mode.el should do it.
http://launchpad.net/python-mode
In case of a bug, please report there
显然,这些是尊重它们的模式的全局设置(python-mode 就是这样做的)。我根本没有修改 python 模式的缩进设置。
Obviously these are global settings for modes that honor them (which python-mode does). I didn't fudge around with python-mode's indentation settings at all.