I found a couple of topics related to this but none of the proposed solutions fit everything I need: I sync settings across machines but have different settings for different plugins (mostly just executable paths). Problem is most plugins retrieve their settings by sublime.load_settings() and just once at startup. So not being familiar with the API I came up with this ‘hack’ (replace sublime.load_settings with my own function), put in a 1_PerHostSettings.sublime-package file to get it loaded a.s.a.p.:
import json
import os
import socket
import sublime
def LoadPerHostSettings(settingsFile):
origSettings = sublime.settings_loader(settingsFile)
baseName = os.path.splitext(settingsFile)[0]
hostname = socket.gethostname().lower()
hostSettingsFile = os.path.join(sublime.packages_path(), "User", "{}.{}.json".format(baseName, hostname))
try:
with open(hostSettingsFile) as f:
hostSettings = json.load(f)
for key, value in hostSettings.items():
print('PerHostSettings', 'replacing', origSettings.get(key), 'with', value)
origSettings.set(key, value)
except Exception:
pass
return origSettings
if not hasattr(sublime, 'load_settings_overloaded'):
sublime.load_settings_overloaded = True
sublime.settings_loader = sublime.load_settings
print('PerHostSettings', 'swapping', sublime.load_settings, 'with', LoadPerHostSettings)
sublime.load_settings = LoadPerHostSettings
This works, but I’m not that keen with modifying the sublime module itself. Are there other and better ways of doing this?