设置`truncate-lines`和`global-visual-line-mode`自动wrap lines显示完整行完全不起作用

(setq-default truncate-lines t)
(setq-default global-visual-line-mode t)

我C-h v查看了2个变量, 是t, 但是就是不会自动断行. 反复重启多次也不行. 请问可能的原因是什么呢? 用的是spacemacs. 看了这个链接, 发现也有好几个人情况相同. toggle-truncate-lines是可以的.

toggle-truncate-lines 之后你再看看 truncate-lines 值是什么。

truncate-lines is a variable defined in ‘src/buffer.c’.

Its value is nil

Non-nil means do not display continuation lines. Instead, give each line of text just one screen line.

Note that this is overridden by the variable ‘truncate-partial-width-windows’ if that variable is non-nil and this buffer is not full-frame width.

Minibuffers set this variable to nil.

Don’t set this to a non-nil value when ‘visual-line-mode’ is turned on, as it could produce confusing results.

Automatically becomes permanently buffer-local when set. Calls these functions when changed: (#) This variable is safe as a file local variable if its value satisfies the predicate ‘booleanp’. You can customize this variable. Probably introduced at or before Emacs version 1.7.

[back]

我是将这两句写在了配置的最后面,生效了

(setq-default truncate-lines t) ;; for scratch no wrap

(add-hook 'hack-local-variables-hook (lambda () (setq truncate-lines t))) ;; global no wrap :: nil->wrap-on ,t->wrap-off

你这个就更离谱了。

你看看「生效」了之后 truncate-lines 的值是什么。

truncate 不是 wrap,它们是相反的概念。

是的,我也觉得很奇怪。目的是不要自动换行显示。
这两句中,如果不写第一句,只有scratch 失效。如果不写第二句,除了scratch 以外,其它类型文件就都失效。所以两句我都写了,就有效果了。就达到了想要的效果
一会儿回家开电脑看看truncate-lines 的值,然后反馈给你 :raised_hands:

我现在告诉你,是 nil。

是的, 我没认真看文档, 这个值设置nil才是完整显示的意思. 我望文生义, 想着truncate是截断, 那么分行显示就是截断.

在配置中改成nil也还是不起作用, 不过现在C-h v发现默认值是nil. 但打开一个buffer就会被设置为t. 这个帖子说明spacemacs的确有对应的hook. 加上这一行即可:

(add-hook 'hack-local-variables-hook #'spacemacs/toggle-truncate-lines-off)
1 个赞

我查了一下,truncate-lines 在我这边显示的是 t :laughing:

@ twlz0ne

这是Windows 7 上的



这是 Linux 上的

截图上面没有 wrap,所为 t,是符合 trancate 定义的。有 wrap 就应该是 nil。

1 个赞

哦哦哦!原来是这样!
还是你了解的比较清晰深入! :+1: