在Sublime中,文件标签的颜色总是跟在文件背景的颜色后面,唯一可以改变的是
color_scheme
设置。
特别是,即使api允许您查看正在用于特定样式(如您在问题中指出的样式)的颜色,但是api函数没有直接的模拟来直接更改这些样式之一。
一般策略是通过更改
配色方案
将该文件设置为其他文件以应用所需的颜色更改。
这可以通过您在问题中概述的命令手动完成,也可以使用
EventListener
监视文件事件,以便为您执行检查,以便无缝地更改颜色,或进行某些组合。
这种插件的一个例子是:
import sublime
import sublime_plugin
# A global list of potential path fragments that indicate that a file is a
# production file.
_prod_paths = ["/production/", "/prod/"]
# The color scheme to apply to files that are production files.
#
# If the color scheme you use is a `tmTheme` format, the value here needs to
# be a full package resource path. For sublime-color-scheme, only the name of
# the file should be used.
_prod_scheme = "Monokai-Production.sublime-color-scheme"
# _prod_scheme = "Packages/Color Scheme - Legacy/Blackboard.tmTheme"
class ProductionEventListener(sublime_plugin.EventListener):
"""
Listen for files to be loaded or saved and alter their color scheme if
any of the _production_path path fragments appear in their paths.
"""
def alter_color_scheme(self, view):
if view.file_name():
# Get the current color scheme and an indication if this file
# contains a production path fragment,.
scheme = view.settings().get("color_scheme")
is_prod = any(p for p in _prod_paths if p in view.file_name())
# If this file is a production file and the color scheme is not the
# production scheme, change it now.
if is_prod and scheme != _prod_scheme:
view.settings().set("color_scheme", _prod_scheme)
# If the file is not production but has the production color scheme
# remove our custom setting; this can happen if the path has
# changed, for example.
if not is_prod and scheme == _prod_scheme:
view.settings().erase("color_scheme")
# Use our method to handle file loads and saves
on_load = on_post_save = alter_color_scheme
每个视图都有自己的本地视图
settings
对象,该对象继承默认设置,但也允许您提供每视图设置。在这里插件应用
配色方案
当检测到文件包含生产路径段时重写继承版本的设置,如果您
Save As
文件名不再是生产路径。
剩下的难题是如何确定要在这里使用什么颜色方案。在上面的例子中,我手动创建了
Monokai.sublime-color-scheme
带着崇高和改良
background
属性更改显示的颜色。
或者,您可以选择其他颜色方案作为生产方案,或者甚至生成
sublime-color-scheme
在飞行中。
在这种情况下,您可能需要使用
sublime.load_resource()
和
sublime.decode_value()
加载并解码
高级配色方案
进入一个json对象,然后操作颜色并将文件另存为一个新的
高级配色方案
进入你的
User
包裹。