emacs - 如何在模式行中显示不同颜色的文本

标签 emacs emacs-faces

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

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

(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,我又回到了正轨。

最佳答案

这是我正在使用的自定义模型行的一小部分(我不记得在哪里找到它),根据您的要求进行修改,以另一种颜色显示缓冲区名称。在此示例中,我使用 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 中,以防您打开覆盖(我有点讨厌处于覆盖模式,所以我希望它非常明显)。

关于emacs - 如何在模式行中显示不同颜色的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24862563/

相关文章:

emacs - 如何在 Emacs 的 calc 中将十六进制数转换为十进制数?

emacs - 让 Emacs 识别自定义数学定界符,以便它可以相应地为面部着色

emacs - 如何在Emacs term-mode中阻止npm的彩色输出看起来难看?

emacs - 如何从 under overlay 中获取面孔?

emacs - 组织模式电子表格程序化远程引用

emacs - 组织模式:保护重点

emacs - Emacs 中的图像。放大和缩小?

ruby - 为 mac ruby​​ 开发设置 .emacs 文件

regex - 根据列号应用面部颜色