繁体   English   中英

自动扩展emacs中的注释块

[英]Auto expanding blocks of comments in emacs

我希望任何评论都显示在自己的行上。 我不喜欢在代码所在的行上添加注释。 在某些语言中,您可以编写注释块,例如:

/**
 * 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。 我只是想知道是否有人有一些聪明的解决方案,以便他们可以打开注释框并开始输入内容。 当注释行的宽度太大时,不必担心必须按回车键才能跳到下一行。 当您希望在注释块中插入时,不必重新整体整理注释。 有任何想法吗?

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

谢谢

auto-fill-mode似乎可以满足您的需求。 当行的长度超过fill-column的值时,它将中断该行并插入新的注释行。

但是,它不是完全自动的,如果在之间插入了文本,则必须按Mq才能重新填充。

[编辑:这是一种智能化“空格”命令的方法。 每次按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)

这对您有用吗?

这有点不合常规,但您不仅限于使用字符串作为文档字符串的注释。 将它们作为第一项的唯一神奇之处在于,它们将被分配给对象__doc__方法。 虽然它们可以在任何地方使用,但完全不会影响效率

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

您会看到生成的代码没有对两个字符串中的任何一个进行任何引用。

我之所以仅提及这是因为文档字符串似乎具有您所要求的所有功能。 尽管我个人认为它没有问题,但它有些不规范。 多行注释会很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM