【问题标题】:How to display text with different colors in mode-line如何在模式行中显示不同颜色的文本
【发布时间】:2014-09-11 19:24:39
【问题描述】:

我想用不同的颜色显示我的模式行的一部分,但它没有按预期工作,我找不到很好的网络参考。我可以将文本更改为粗体或斜体,但不能根据需要更改颜色。

最简单的示例是显示一个简单的模式行,其中 buffer-file-name 为白色,而不是默认的面颜色。

(custom-set-variables
 '(mode-line-format
   (quote
    ("%e" mode-line-front-space
     "[" mode-name "] %l:%i"
     "\t"
     propertize buffer-file-name 'font-lock-face '(:foreground "white")))))

感谢 legosica 指出我应该包含我尝试过的其他示例...

  1. 将 'font-lock-face 替换为 'face:

    propertize buffer-file-name 'face '(:foreground "white")))))
    



跟进

感谢 TacticalCoder,我现在拥有了我想要的东西——我的模式行中有多种字体和颜色。设置'face '(:foreground "white") 不起作用的原因是它需要被包裹在'(:eval ...) 中。

我最终得到了这个......

(setq-default mode-line-format
  (list

    mode-line-front-space ; +-- just like in the default mode-line-format

    '(:eval (propertize (concat "\t[" mode-name "] %l:%i\t") 'face '(:foreground "black" :height 0.9 :weight normal)
        'help-echo (buffer-file-name)))

    '(:eval (propertize (file-name-directory buffer-file-name)  'face 'info-title-4
        'help-echo (buffer-file-name)))

    '(:eval (propertize (file-name-nondirectory buffer-file-name)  'face 'info-title-3
        'help-echo (buffer-file-name)))

    ))

结合...

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(info-title-3 ((t (:inherit info-title-4 :foreground "white" :height 1.2))))
 '(info-title-4 ((t (:inherit info-title-4 :foreground "black"))))
 '(mode-line ((t (:background "#6483af" :foreground "#001122" :box (:line-width 3 :color "#6483af") :weight ultra-bold :height 118 :family "Monospace")))))

...我得到了一个很好的简单模式行,它展示了我想要的大部分内容。更多的工作要做,但感谢 TacticalCoder,我回到了正轨。

【问题讨论】:

  • 你能用'face代替'font-lock-face吗?
  • @legoscia 谢谢,我已经尝试过了。我想我已经忘记了我尝试过的所有事情:-(
  • @abo-abo 谢谢,但我的 Lisp 还不够好,无法遵循电力线的实施。你能指出一个可能接近我需要的部分吗?
  • google for mode-line-format colors in google-images 你会发现很多例子。

标签: emacs emacs-faces


【解决方案1】:

这是我正在使用的自定义模式行的一小部分(我不记得在哪里找到它了),根据您的要求进行了修改,以另一种颜色显示缓冲区名称。在这个例子中,我使用font-lock-warning-face(在我的配色方案中是“红色”):

这绝不是一个完整的模式:

(setq-default mode-line-format
  (list

    mode-line-front-space ; +-- just like in the default mode-line-format
    mode-line-mule-info   ; |
    mode-line-client      ; |

    ;; the buffer name; the file name as a tool tip if you hover the mouse on it
    '(:eval (propertize "%b " 'face 'font-lock-warning-face
        'help-echo (buffer-file-name)))

    '(:eval (propertize (if overwrite-mode "OVERWRITE" "")
              'face 'font-lock-warning-face
              'help-echo (concat "Buffer is in "
                           (if overwrite-mode "overwrite" "insert") " mode")))

    "%-"                  ; fill what's left with '-'
    ))

这对你有用吗?我也确实在font-lock-warning-face 中添加了 OVERWRITE 出现的部分,以防你打开覆盖(我有点讨厌处于覆盖模式,所以我希望它非常明显)。

【讨论】:

  • 我正在为此投票给你,当我有机会检查它时,我可能会接受这个作为正确答案。它还显示了我接下来想做的一些事情,请为此竖起大拇指!
  • @ChrisMcCauley:那我再补充一些,你可能想做一些事情......顺便说一句,你可以简单地尝试评估我编写的函数,并立即查看它是否有效或不是。
  • 您可能会为此获得很多支持。我本可以简单地使用电力线或其他工具之一,但我什么也学不到。我确定我不是唯一一个。
  • @ChrisMcCauley:啊,算了吧:它实际上与用于“覆盖”的机制完全相同,但适用于其他事情......所以基本上你应该很高兴:)跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-24
  • 1970-01-01
  • 1970-01-01
  • 2020-09-26
  • 2012-08-24
相关资源
最近更新 更多