简体   繁体   English

有没有办法为不同的文件源使用不同的Sublime Text主题?

[英]Is there a way to use different Sublime Text themes for different file sources?

I would like to set up two separate themes in ST3. 我想在ST3中设置两个单独的主题。 One theme would be for local files, while the second would be for any file opened via my FTP app (Transmit). 一个主题用于本地文件,第二个主题用于通过我的FTP应用程序打开的任何文件(传输)。 Is this possible? 这可能吗?

The simplest solution may be to override any file coming from the FTP's cache folders. 最简单的解决方案可能是覆盖来自FTP缓存文件夹的任何文件。 But I have no idea if this is possible. 但是我不知道这是否可能。

Yes, this is possible with a fairly simple plugin. 是的,这可以通过相当简单的插件实现。 Open a new Python file in Sublime, and add the following to it: 在Sublime中打开一个新的Python文件,并添加以下内容:

import sublime
import sublime_plugin


class TransmitColorSchemeCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        if "/path/to/transmit/tempfiles" in self.view.file_name():
            self.view.settings().set("color_scheme", "Packages/Color Scheme - Default/Monokai.tmTheme")


class TransmitEventListener(sublime_plugin.EventListener):

    def on_load_async(self, view):
        view.run_command("transmit_color_scheme")

Make sure you adjust "/path/to/transmit/tempfiles" to the actual path you want, and change the "color_scheme" setting to the color scheme you want to use for Transmit files. 确保将"/path/to/transmit/tempfiles"为所需的实际路径,并将"color_scheme"设置更改为要用于传输文件的配色方案。 Save the file as Packages/User/transmit_color_scheme.py where Packages is the folder opened when selecting the Preferences -> Browse Packages... menu option. 将文件另存为Packages/User/transmit_color_scheme.py ,其中Packages是在选择Preferences -> Browse Packages...菜单选项时打开的文件夹。 On OS X, it's ~/Library/Application Support/Sublime Text 3/Packages . 在OS X上,它是~/Library/Application Support/Sublime Text 3/Packages

Once saved, the event listener will start up immediately, and any file you open that contains the specified path will have the color scheme set to whatever you indicate. 保存后,事件侦听器将立即启动,并且您打开的包含指定路径的任何文件都会将颜色方案设置为您指定的颜色。 All other files from other paths will use your default color scheme. 来自其他路径的所有其他文件将使用您的默认配色方案。

Have fun! 玩得开心!


Please note that this plugin will only work in ST3. 请注意,此插件仅在ST3中可用。 To make it work in ST2, change def on_load_async to def on_load . 要使其在ST2中工作, def on_load_async def on_load更改为def on_load

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM