在linux上使用emacs 23.3.1的两个相关问题:
首先,为什么不能我的值设置show-trailing-whitespace到t与setq如下图所示?当我把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))
Run Code Online (Sandbox Code Playgroud)
其次,我怎么可以切换之间的价值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))
Run Code Online (Sandbox Code Playgroud)
当我点击时M-ow我得到一个错误Wront type argument: number-or-marker-p, nil.有任何想法吗?
Nic*_*out 18
第一:因为它describe-variable告诉你show-trailing-whitespace是一个缓冲变量.这意味着只做一个setq为当前缓冲区设置它,因此在.emacs文件中完成时没有任何效果.要有类似于自定义的东西,你需要使用setq-default而不是setq.这适用于所有缓冲区.
第二:对于切换,setq如果要在每个缓冲区的基础上切换缓冲区,可能需要使用.您得到的错误是您使用=哪个来测试两个数字是否相等.通过使用更清洁的方式进行切换not.作为旁注,该(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)))
Run Code Online (Sandbox Code Playgroud)