关闭Magit模式下的提交格式化

4
最近版本的Magit(输入“M-x magit-version”命令显示“magit-20131222.850”)会强制实施某些令人烦恼的提交信息属性,并以奇怪的颜色进行标记。具体来说,它会在一定长度处自动换行并将第一行标记为绿色。
是否有任何方法可以禁用此功能并使其像旧的简单提交信息窗口一样运行?我在“M-x customize-mode”中没有看到任何相关的设置,因此我认为解决方案将涉及一些“elisp”代码。

当您在提交缓冲区时,如果执行 C-h m,它会显示什么主模式?M-x magit-version 的输出是什么? - Chris
@Chris - 在问题中添加了版本信息。C-h mgit-commit-mode 命名为提交缓冲区的主要模式。 - Inaimathi
2个回答

7

将以下内容添加到你的.emacs文件中:

(add-hook 'git-commit-mode-hook
          '(lambda () (auto-fill-mode 0))
          ;; append rather than prepend to git-commit-mode-hook, since the
          ;; thing that turns auto-fill-mode on in the first place is itself
          ;; another hook on git-commit-mode.
          t)

关于字体颜色,我建议您将光标移动到所需文本上,执行M-x customize-face,然后使用对话框进行设置。
但是,您也可以通过原始的elisp代码实现类似的效果:
(set-face-foreground 'git-commit-summary-face "white")

通常情况下,您可以将光标移动到感兴趣的文本上,然后执行M-x describe-face命令来了解要修改的 face(面)是哪个。

运行得非常好。我需要自定义的三个面是 git-commit-nonempty-second-line-facegit-commit-overlong-summary-facegit-commit-summary-face - Inaimathi
我正在使用 magit 2.6.0,我不得不使用 (add-hook 'git-commit-setup-hook 'turn-off-auto-fill t)。此外,(setq git-commit-summary-max-length 999) 可以防止文本着色并在摘要行过长时发出警告。 - 0x5453

6
在最新的 Magit 版本中(我正在使用 Magit 20190122.503),您需要使用 git-commit-setup-hook 来使其工作:
(add-hook 'git-commit-setup-hook 'turn-off-auto-fill
          ;; append to end of git-commit-setup-hook to ensure our hook trumps others.
          t)

谢谢!很奇怪,它甚至不需要询问就会自动格式化你的文本... - Ricky Robinson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接