在 emacs Python 模式下,如何为文档字符串和代码设置不同的自动填充宽度?

发布于 2024-12-26 09:51:18 字数 173 浏览 2 评论 0原文

我希望将代码部分的自动填充设置为 79 列,将文档字符串设置为 72 列,以获得自动 PEP8 合规性。似乎有一个选项可以为 Lisp 模式(emacs-lisp-docstring-fill-column)执行此操作,但不能为 Python 执行此操作。

是否有一个增强的 python-mode.el 包含这个?

I would like to have auto-fill set to 79 columns for code sections and 72 for docstrings to get automatic PEP8 compliance. There seems to be an option to do this for Lisp mode (emacs-lisp-docstring-fill-column) but not for Python.

Is there an enhanced python-mode.el around somewhere that includes this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

若水般的淡然安静女子 2025-01-02 09:51:18

我不知道该怎么做,但我从来没有觉得有必要。使用 Cx f 更改填充列非常简单。您只需点击 Mp 即可重复使用您输入的最后一个值。只需 Cx f Mp --- 3 次按键。

I don't know how to do that, but I've never felt the need. It is so easy to use C-x f to change the fill column. And you can just hit M-p to reuse the last value you entered. Just C-x f M-p --- 3 keystrokes.

走过海棠暮 2025-01-02 09:51:18

仅进行了轻微测试:

(defadvice current-fill-column (around handle-docstring activate)
  (flet ((docp (p) (let ((q (get-text-property p 'face))
                         (r 'font-lock-string-face))
                     (or (eq r q) (memq r q)))))
    (if (or (docp (point)) (docp (point-at-bol)) (docp (point-at-eol)))
        (setq ad-return-value 72)
      ad-do-it)))

这取决于启用字体锁定模式来检测文档字符串。

Only slightly tested:

(defadvice current-fill-column (around handle-docstring activate)
  (flet ((docp (p) (let ((q (get-text-property p 'face))
                         (r 'font-lock-string-face))
                     (or (eq r q) (memq r q)))))
    (if (or (docp (point)) (docp (point-at-bol)) (docp (point-at-eol)))
        (setq ad-return-value 72)
      ad-do-it)))

This depends on font-lock-mode being enabled to detect the docstrings.

蛮可爱 2025-01-02 09:51:18

使用当前的 python.el 模式与 Emacs 24.3 一起分发,您可以按如下方式重新定义 python-fill-string (在本示例中,我还设置了 fill -column 更改为 85 并更改 python-fill-docstring-style):

;; Python customizations
(defun my-python-fill-string (&optional justify)
  (let ((old-fill-column fill-column))
    (setq fill-column 72)
    (python-fill-string justify)
    (setq fill-column old-fill-column)
  ))

(add-hook 'python-mode-hook
          (lambda () (interactive)
            (setq python-fill-docstring-style 'pep-257-nn)
            (set-fill-column 85)
            (setq python-fill-string-function my-python-fill-string)
            ))

With the current python.el mode as dstributed with Emacs 24.3 you can redefine the python-fill-string as follows (in this example, I also set the fill-column to 85 and change the python-fill-docstring-style):

;; Python customizations
(defun my-python-fill-string (&optional justify)
  (let ((old-fill-column fill-column))
    (setq fill-column 72)
    (python-fill-string justify)
    (setq fill-column old-fill-column)
  ))

(add-hook 'python-mode-hook
          (lambda () (interactive)
            (setq python-fill-docstring-style 'pep-257-nn)
            (set-fill-column 85)
            (setq python-fill-string-function my-python-fill-string)
            ))
微暖i 2025-01-02 09:51:18

当前的 python-mode.el 提供了

(defcustom py-docstring-fill-column 72 [...]

(defcustom py-comment-fill-column 79 [...]

使用 fill-column 的代码值。

Current python-mode.el provides

(defcustom py-docstring-fill-column 72 [...]

(defcustom py-comment-fill-column 79 [...]

while for code value of fill-column is used.

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