Python.el 错误处理了我在文档字符串上的 M-q 缩进

标签 python emacs

给定一个函数

def foo():
  """
  etc
  stuff
  """
  pass

当我运行 M-q 来分段我的文档字符串时,emacs(24.3.1,python.el)将像这样重新格式化 foo:

def foo():
  """etc
  stuff
  """
  pass

我如何告诉 python.el 不要管它? (我知道这种行为是新的,另一台计算机(我无权访问)上的旧 emacs 没有这样做)。

最佳答案

python.el 所做的实际上是 Python 约定(尽管第一行后没有空行)- 参见 PEP-0257的例子:

def complex(real=0.0, imag=0.0):
    """Form a complex number.

    Keyword arguments:
    real -- the real part (default 0.0)
    imag -- the imaginary part (default 0.0)
    """
    if imag == 0.0 and real == 0.0:
        return complex_zero

查看the source code for python.el ,改变此行为的参数是 'python-fill-docstring-style',默认为 pep-257 但提供了一些替代方案:

:type '(choice
          (const :tag "Don't format docstrings" nil)
          (const :tag "Django's coding standards style." django)
          (const :tag "One newline and start and Two at end style." onetwo)
          (const :tag "PEP-257 with 2 newlines at end of string." pep-257)
          (const :tag "PEP-257 with 1 newline at end of string." pep-257-nn)
          (const :tag "Symmetric style." symmetric))

关于Python.el 错误处理了我在文档字符串上的 M-q 缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23765887/

相关文章:

python - Pydoc 弄乱了 -*- 编码 : utf-8 -*-

python - 未知后端 : No event loop integration for u'inline' when enable inline matplotlib in emacs python notebook

perl - 在 Emacs 中执行 Perl,最基本的

python - 处理pandas中的多列和groupby/agg(无需手动分配所有聚合函数)

python - pygame中的鼠标按钮按下处理

python - os.walk() 没有获取我的文件名

emacs - 在 sml 模式下发送缓冲区到 REPL 失败

shell - 在 Emacs 中调整终端大小

python - Pandas.read_csv 类型转换如何工作?

python - 在 asyncio 中的 KeyboardInterrupt 之后等待任务完成