在 Emacs 中编辑 Python

发布于 2024-10-15 20:24:49 字数 417 浏览 4 评论 0原文

我查看了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

老街孤人 2024-10-22 20:24:49

假设您已经使用 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 RET python RET),或者向 python-mode-hook 添加自定义函数。例如:

(add-hook 'python-mode-hook 'my-python-mode-hook)
(defun my-python-mode-hook ()
  (setq indent-tabs-mode nil
        py-smart-indentation nil
        py-indent-offset 4))

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, and py-smart-indentation (and perhaps also py-continuation-offset and py-honor-comment-indentation). As well as the normal indent-tabs-mode.

You can either Customize them (M-x customize-group RET python RET), or add a custom function to python-mode-hook. e.g.:

(add-hook 'python-mode-hook 'my-python-mode-hook)
(defun my-python-mode-hook ()
  (setq indent-tabs-mode nil
        py-smart-indentation nil
        py-indent-offset 4))
两仪 2024-10-22 20:24:49

将 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

飘逸的'云 2024-10-22 20:24:49
(custom-set-variables
   ...
   '(indent-tabs-mode nil)
   '(tab-stop-list (quote (4 8 16 24 32 40 48 56 64 72 80 88 96 104 112 120)))
   '(tab-width 4))

显然,这些是尊重它们的模式的全局设置(python-mode 就是这样做的)。我根本没有修改 python 模式的缩进设置。

(custom-set-variables
   ...
   '(indent-tabs-mode nil)
   '(tab-stop-list (quote (4 8 16 24 32 40 48 56 64 72 80 88 96 104 112 120)))
   '(tab-width 4))

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文