Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在emacs中自动扩展注释块_Python_Emacs_Comments - Fatal编程技术网

Python 在emacs中自动扩展注释块

Python 在emacs中自动扩展注释块,python,emacs,comments,Python,Emacs,Comments,我喜欢任何评论出现在自己的行中。我不喜欢把注释放在代码所在的同一行上。在某些语言中,您可以编写注释块,例如: /** * I am a comment block. This comment block will be automatically expanded by the * IDE such that it can contain all of the text in this block. **/ 我喜欢这样。我喜欢注释块在我添加更多文本时不断增加行数的方式。我喜欢在块中的某个任

我喜欢任何评论出现在自己的行中。我不喜欢把注释放在代码所在的同一行上。在某些语言中,您可以编写注释块,例如:

/**
 * I am a comment block. This comment block will be automatically expanded by the
 * IDE such that it can contain all of the text in this block.
**/
我喜欢这样。我喜欢注释块在我添加更多文本时不断增加行数的方式。我喜欢在块中的某个任意点插入文本,随后的文本将向下移动,以便文本不会超出右侧的某个点。我使用Python。Python没有多行块注释。我想你最接近的可能是:

# I am a comment block.  This comment block will NOT be automatically expanded by
# the IDE, because it does not recognize these two comment lines as being joined.
我也使用emacs。我只是想知道是否有人想出了一些聪明的解决方案,这样他们就可以打开一个评论块,然后开始打字。当注释行的宽度太大时,不必担心必须按return键才能跳到下一行。当您希望在注释块中插入注释时,无需将注释作为一个整体重新洗牌。有什么想法吗

小结:我正在寻找一种在emacs中进行多行连续注释(对于Python)的方法,而不必手动格式化注释块本身中的文本


谢谢

自动填充模式
似乎可以满足您的需求。当行的长度超过
fill column
的值时,它会打断该行并插入新的注释行

但它不是全自动的,如果文本插入中间,则必须按M-q重新填充

[编辑:这里有一种将“空格”命令智能化的方法。每次按SPC时,您的注释块都将被重新填充:

(defun refill-when-in-comment ()
  (interactive)
  (let ((curr-face (get-char-property (point) 'face)))
    (if (member "comment" (split-string (prin1-to-string curr-face) "-"))
        (fill-paragraph t)
      )
    )
  )

(defun smart-space (arg)
  (interactive "P")
  (refill-when-in-comment)
  (self-insert-command (prefix-numeric-value arg))
  )

(global-set-key " " 'smart-space)

这对你有用吗?

这有点不正统,但你并不局限于仅将字符串用作docstring的注释。将它们作为第一项的唯一神奇之处在于,它们将被分配到对象
\uuuu doc\uuuu
方法。尽管它们可以在任何地方使用,而且不会影响效率

>>> import dis
>>> def test():
...     """This is a standard doc string"""
...     a = 3  # This will get compiled
...     """This is a non standard doc string and will not get compiled"""
... 
>>> dis.dis(test)
  3           0 LOAD_CONST               1 (3)
              3 STORE_FAST               0 (a)

  4           6 LOAD_CONST               2 (None)
              9 RETURN_VALUE
您可以看到生成的代码没有引用这两个字符串中的任何一个


我之所以提到这一点,是因为文档字符串似乎具有您所要求的所有功能。这有点不标准,尽管我个人认为它没有问题。多行注释会很好。

+1.将您的注释键入纯文本,标记它,然后执行
M-q
填充。另请参阅,重新填充模式以自动完成重新填充从v21.2开始,它就一直是emacs的一部分。我没有尝试在代码注释中使用它。我唯一担心的是,除了填充注释外,它还会“填充”实际代码。显然这是不好的。