14

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

是否有增强的 python-mode.el 在某个地方包含这个?

4

4 回答 4

4

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

于 2012-01-11T22:35:08.687 回答
3

仅稍作测试:

(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)))

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

于 2012-01-11T23:02:20.300 回答
3

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)
            ))
于 2015-05-20T04:26:39.903 回答
1

当前的 python-mode.el 提供

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

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

而对于代码值的fill-column使用。

于 2015-05-20T05:35:41.997 回答