Emacs通过模式定制背景颜色 [英] Emacs custom background color by mode
问题描述
我使用emacs来编辑多个文件类型,并且想要一个简单的可视化队列来例如.vhd或.py文件中的.c文件。如何为该语言的主要模式添加自定义背景颜色?
I use emacs to edit a number of file types, and would like an easy visual queue to tell .c files from .vhd or .py files, for instance. How can I add a custom background color to the major mode for that language?
推荐答案
可以通过钩子来做到这一点。除了别的以外,你可以勾选当一个新的主要模式开始。将这样的东西放入你的.emacs文件中,emacs会在每次进入Python模式时将背景颜色设置为紫色。
You can do this via hooks. Among other things you can hook is when a new major mode starts. Put something like this into your .emacs file, and emacs will set your background color to purple every time you go into Python mode.
(add-hook 'python-mode-hook
(lambda ()
(set-background-color "purple")))
将背景颜色重置为默认值,在切换回没有显式设置背景钩子的模式的情况下,将作为一项练习读者。
Resetting the background color to the default in the case that you switch back to a mode that doesn't have an explicit set-background hook for it is left as an exercise for the reader.
您还可以使用Mx set-background-color手动设置背景颜色
You can also manually set the background color with M-x set-background-color
这篇关于Emacs通过模式定制背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!