如何仅为代码注释打开emacs自动填充模式?

tob*_*ced 12 emacs autofill dot-emacs

我试过了

(set (make-local-variable 'comment-auto-fill-only-comments) t)
Run Code Online (Sandbox Code Playgroud)

并且

(auto-fill-mode 0)
Run Code Online (Sandbox Code Playgroud)

虽然令人惊讶,但在重新启动emacs之后,这些都不起作用.

我正在使用eschulte的emacs入门套件

使用Mx自动填充模式切换它可以正常工作.


UPDATE

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

(auto-fill-mode 1)
(setq comment-auto-fill-only-comments t) 
Run Code Online (Sandbox Code Playgroud)

它在编程文件中完美地工作,其中有注释.但是,在文本模式下,它会自动填充到处.

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

Rém*_*émi 12

如果您希望Emacs自动填充注释,则不得对本地变量进行注释 - 自动填充 - 注释:

(setq comment-auto-fill-only-comments t)
Run Code Online (Sandbox Code Playgroud)

如果只想在某种模式下使用它而不是全部,则必须将其添加到正确的钩子中:

(add-hook 'ruby-mode-hook 
          (lambda () ((set (make-local-variable 'comment-auto-fill-only-comments) t)))
Run Code Online (Sandbox Code Playgroud)

更新答案

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

(add-hook 'text-mode-hook 
          (lambda () (auto-fill-mode -1)))
Run Code Online (Sandbox Code Playgroud)

请注意,这将改变在文本模式下导出的模式中的自动填充状态(乳胶模式是一个例子,还有很多其他这样的模式)