Sublime Forum

Theme setting is ignored in project-specific settings

#1

Hi,

I am trying to set the theme on a per-project basis.

Setting theme works all right in User/Preferences.sublime-settings. However, the “theme” setting seems to be ignored in the project setting. Putting this in my project’s settings, I can see that settings are used (margin is large as requested), but theme is not updated at all. Any clues?

[quote]
{
“build_systems”: … whatever I have here],

"settings":
{
    "margin": 100,
    "theme": "Soda Light 3.sublime-theme"
}

}[/quote]

Thanks!

0 Likes

#2

This is correct, the “theme” setting is one of the so-called “global” settings that can only be set in Default and User preferences.

Here is a list of known global settings: docs.sublimetext.info/en/latest/ … l-settings

1 Like

#3

OK, thanks – I wasn’t sure if this information was up to date.

This is highly disappointing. I can understand why “theme” couldn’t be overriden on a per language basis and so on. However, a window corresponds to a unique project, and one could expect that the theme could be overriden on a per-window basis.

This would be very useful to easily distinguish between different projects when you have multiple open at the same time. I know color schemes can be overriden, but that’s not quite as good: I like my color scheme OK, but would like to be able to change, e.g., the color of the status bar between projects. Any idea if there is a possible way to hack my way around this?

0 Likes

#4

I don’t know if this will work, because I was mainly interested in colour scheme changes (in my old job) rather than theme changes as such. But I did this using a plugin rather than sublime project settings, so this may work for you. It’s possibly quite inefficient, because the plugin inspects the file’s path when it is “activated” in the editor, and I just hard-code my own colour scheme for specific components in the path. The bit that’s of interest is that I also set the theme for some reason (presumably because this mechanism didn’t work without that). Now, I use the same theme for each case here, but it may be work trying this approach to see if you can change the theme this way.

I don’t actually make use of this at the moment, so it might have suffered from bit-rot, but here is the plugin code for you to try if you like:

import sublime, sublime_plugin

class ThemeSwitcher(sublime_plugin.EventListener):  
  def on_load(self, view):
    if view.file_name():
      print(view.file_name())

  def on_activated(self, view):
    fileName = view.file_name()
    if fileName:
      if "-main" in fileName or "-hmain" in fileName:
        view.settings().set('color_scheme', 'Packages/User/Blurk-main.tmTheme')
        view.settings().set('theme', 'Blurk.sublime-theme')
      elif "-tmp" in fileName or "-alt" in fileName:
        view.settings().set('color_scheme', 'Packages/User/Blurk-tmp.tmTheme')
        view.settings().set('theme', 'Blurk.sublime-theme')
      elif "-current-rel" in fileName or "-hrel" in fileName:
        view.settings().set('color_scheme', 'Packages/User/Blurk-current-rel.tmTheme')
        view.settings().set('theme', 'Blurk.sublime-theme')
      else:
        view.settings().set('color_scheme', 'Packages/User/Blurk-default.tmTheme')
        view.settings().set('theme', 'Blurk.sublime-theme')
0 Likes

#5

@blurk: it won’t work because the theme setting can only be set in preferences.sublime-settings. You could do it with s = sublime.load_settings("Preferences.sublime-settings"); s.set("theme",...); s.save_settings(). Sublime text requires you to restart it in order to load themes correctly however.

0 Likes