【问题标题】:How to turn on emacs auto-fill-mode only for code comments?如何仅为代码注释打开emacs自动填充模式?
【发布时间】:2011-05-27 12:22:09
【问题描述】:

我试过了

(set (make-local-variable 'comment-auto-fill-only-comments) t)

还有

(auto-fill-mode 0)

虽然令人惊讶的是,在 emacs 重新启动后,这些都不起作用。

我正在使用eschulte's emacs starter kit

使用 M-x 自动填充模式切换它可以正常工作。


更新

结合使用(感谢 Rémi):

(auto-fill-mode 1)
(setq comment-auto-fill-only-comments t) 

它在有 cmets 的编程文件中完美运行。但是,在文本模式下,它会自动填充所有位置。

如何在文本文档中完全关闭自动填充模式?

【问题讨论】:

  • Emacs 有详细的在线文档。使用describe-functiondescribe-variable 了解如何使用函数、变量可能会有所帮助。
  • 试试describe-variable,它可能会告诉你comment-auto-fill-only-comments不是你想的那样。如果是这种情况,那么在你设置值之后可能会有一个钩子在运行,它会踩到你的值。

标签: emacs dot-emacs autofill


【解决方案1】:

如果您希望 Emacs 自动填充 cmets,则不能将 comment-auto-fill-only-cmets 设为局部变量:

(setq comment-auto-fill-only-comments t)

如果你只希望它在某种模式下而不是全部,你必须将它添加到正确的钩子中:

(add-hook 'ruby-mode-hook 
          (lambda () ((set (make-local-variable 'comment-auto-fill-only-comments) t)))

更新答案

要从文本模式中删除自动填充,您必须使用钩子:

(add-hook 'text-mode-hook 
          (lambda () (auto-fill-mode -1)))

请注意,这也会改变从文本模式派生的模式中的自动填充状态(乳胶模式是一个例子,还有很多其他这样的模式)

【讨论】:

  • 谢谢 - 我的问题上已经发布了对此的更新 - 它已部分解决,但仍然存在一些问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-13
  • 1970-01-01
  • 2011-12-26
  • 2023-03-27
  • 1970-01-01
相关资源
最近更新 更多