2

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

最简单的示例是显示一个简单的模式行,其中缓冲区文件名为白色,而不是默认的面颜色。

(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. 用 'face 替换 'font-lock-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,我回到了正轨。

4

1 回答 1

3

这是我正在使用的自定义模式行的一小部分(我不记得在哪里找到它),根据您要求以另一种颜色显示缓冲区名称进行修改。在此示例中,我正在使用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 '-'
    ))

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

于 2014-07-21T11:52:49.500 回答