gpt4 book ai didi

emacs - 在 Emacs 中使用 M-q 而不将我所有的代码变成注释

转载 作者:行者123 更新时间:2023-12-05 00:09:16 25 4
gpt4 key购买 nike

假设您编写了一些这样的代码(使用 ruby​​-mode,但我也看到在其他模式下也会发生这种情况):

# This is a comment.
def foo
puts "foo!"
end

如果你把这个点放在第一行并按 M-q,你会得到:
# This is a comment. def foo puts "foo!" end

我该如何避免呢?我使用的是 21.3 版。

澄清:当我在注释和代码之间添加一个空行时,不会发生这种情况。作为一种解决方法,当我想补充我的评论时,我经历了一个烦人的三步过程:
  • 我在前后加了一个空行
    评论段
  • QQ
  • 删除空行

  • 如果 M-q 无需添加和删除空白行就可以处理重新填充评论段落会更好。 Emacs 已经知道什么文本是注释文本,所以一定有办法做到这一点。

    最佳答案

    filladapt.el成功了。最新版本的 RubyMode .

    使用这两个包可以解决您看到的 M-q 问题。 (使用 GNU Emacs 22.1)

    查看 ruby​​-mode 的代码,看起来它已经自定义了变量来控制段落填充,如下所示:

    (make-local-variable 'paragraph-start)
    (setq paragraph-start (concat "$\\|" page-delimiter))
    (make-local-variable 'paragraph-separate)
    (setq paragraph-separate paragraph-start)
    (make-local-variable 'paragraph-ignore-fill-prefix)
    (setq paragraph-ignore-fill-prefix t)

    可以将其添加到当前 ruby​​ 的自定义钩子(Hook)中,或者添加到您希望填充行为按照您描述的方式运行的任何主要模式中 - 只要您使用 filladapt.el。

    关于emacs - 在 Emacs 中使用 M-q 而不将我所有的代码变成注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/683970/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com