如何将word-wrap默认设为nil?

我目前在用emacs27.1,想要默认关闭 word-wrap,保证可以从任意中文字符处折行(暂不考虑升级到emacs28)。

加了这样的hook。在输出message的时候,word-wrap的值确实是nil;但buffer里面明显没有生效,用help variable查看,它的值却是t

(add-hook text-mode-hook (lambda () 
  (setq word-wrap nil)
  (message "word-wrap is %s" word-wrap)
  ))

我用的配置是spacemacs,搜索了 .emacs.d.spacemacs.d两个目录,没有其他任何设置word-wrap的代码了。

试一试 (add-hook 'text-mode-hook #'toggle-truncate-lines) 可不可以?

truncate lines属于优先级更高的层面,要自动换行生效,必须保持在disable状态。

试一试 visual-line-mode

word-wrap 的文档提到了

Instead of setting this variable directly, most users should use
Visual Line mode.  Visual Line mode, when enabled, sets word-wrap
to t, and additionally redefines simple editing commands to act on
visual lines rather than logical lines.  See the documentation of
visual-line-mode.

word-wrap 的默认值就是 nil,可能有其它地方改变了它。

这是我的自动换行策略,还没写好,先贴截图吧

1 个赞

我的配置里搜不到其他的word-wrap赋值了,请问有插入“数据断点”之类的功能吗?

不清楚,zsbd

整理完配置,竟然好了。。看来又把自己坑了 :neutral_face:

1 个赞