在linux上使用emacs 23.3.1的两个相关问题:
首先,为什么我不能用setq
将show-trailing-whitespace
的值设置为t
,如下所示?当我把setq
版本放在.emacs
中时,它不会改变值(从功能和使用M-x describe-variable
来看)。
(setq show-trailing-whitespace t) ; Does not change variable value or give error
(custom-set-variables ; Sets show-trailing-whitespace as expected
'(show-trailing-whitespace t))
第二,如何在t
和nil
之间切换值?我以为这个答案正是我所需要的,但在这种情况下它不起作用。我用过:
(global-set-key "M-ow" 'tf-toggle-show-trailing-whitespace)
(defun tf-toggle-show-trailing-whitespace ()
"Toggle show-trailing-whitespace between t and nil"
(interactive)
(setq show-trailing-whitespace (if (= show-trailing-whitespace nil) t nil))
(redraw-display))
当我点击M-ow
时,我得到一个错误Wront type argument: number-or-marker-p, nil
。有什么想法吗?
第一:正如describe-variable
命令告诉您的那样,show-trailing-whitespace
是一个缓冲变量。这意味着执行setq
仅将其设置为当前缓冲区,因此在.emacs
文件中执行时没有任何效果。要有类似于什么自定义的东西,您需要使用setq-default
而不是setq
。这将适用于所有缓冲区。
第二:对于切换,如果您希望在每个缓冲区的基础上切换,则可能需要使用setq
。您得到的错误是,您使用=
来测试两个数字是否相等。通过使用CCD_ 19以更干净的方式进行切换。附带说明一下,(redraw-display)
命令似乎没有执行任何操作。
(defun tf-toggle-show-trailing-whitespace ()
"Toggle show-trailing-whitespace between t and nil"
(interactive)
(setq show-trailing-whitespace (not show-trailing-whitespace)))
write(eq显示尾随空格nil)
或更短但相反的
(如果显示尾部空白
对于来自未来的任何人(Emacs 28+):可以使用M-x customize-variable
和show-trailing-whitespace
全局设置变量,返回并切换到on
。