如何取消Emacs中whitespace-mode的前景色?

5
在编程文件中,我使用空格模式来突出制表符和长行。默认的突出显示对我来说太过花哨。我只想用灰色背景突出显示它们,并保持字体的正常颜色。我该如何设置?
以下设置无效。我希望超过80列的代码以黄色为主色调,就像快照中80列内的字符一样。
;; face for long lines' tails
(set-face-attribute 'whitespace-line nil
                    :background "#555"
                    :weight 'bold)

;; face for Tabs
(set-face-attribute 'whitespace-tab nil
                    :background "#555"
                    :weight 'bold)

whitespace-mode


相同的问题。在默认主题中,尾随空格是漂亮的灰色。在其他所有颜色主题中,它会像某个致命错误一样闪耀着红色。下面的set-face-attribute答案没有效果。 - Dave Cohen
2个回答

4

set-face-attribute 只会修改你指定的属性。

:foreground 设置为 nil

(set-face-attribute 'whitespace-line nil
                    :foreground nil
                    :background "#555"
                    :weight 'bold)

我明白了。简短的回答是:你做不到。较长的回答是:你需要打补丁来修改whitespace.el:https://gist.github.com/72d39c507d56c5c5e0ed - Dmitry
我正在寻找类似于defadvice的东西,用于函数。 - RNA
你可以通过同时建议 whitespace-color-onfont-lock-add-keywords 来实现这一点,在前者中将某些变量设置为 to,在后者中检查其值,并强制将 keywords 规范中的 override 值设置为 prepend,但实际上,这是一个可怕的解决方案。 - Dmitry
向Emacs错误跟踪器发送一个功能请求,我相信我们可以很快将这个更改加入主干。在那里使用“prepend”是有意义的。 - Dmitry
@MadhavanKumar 首先尝试使用(require 'whitespace) - Dmitry
显示剩余2条评论

3

对我来说,不愉快的颜色是尾随空格,我正在使用以下方法:

;; whitepace looks rediculous in color themes.
(defadvice color-theme-install (after my-color-theme-install-after activate)
  "Fix trailing-whitespace after color theme destroys it"
  (set-face-attribute 'trailing-whitespace nil
                      :foreground 'unspecified
                      :inverse-video 'unspecified
                      :slant 'unspecified
                      :weight 'unspecified
                      :background "#fff"))

对于Emacs 24.4,我针对尾随空格和空白行都进行了处理 - 除此之外,我还使用了(add-hook 'python-mode-hook '(lambda () (set-face-attribute ...)))。毫无疑问,这不是最好的位置,但对我的目的起到了作用。 - Croad Langshan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接