def _set_theme_safely(self, name): """ Safe variant of setting theme. At one point, Sublime would be left with an empty Preference file if you modified it too soon. So manually reading ws the safest. The problem may or may not exist now. """ pref_file = join(sublime.packages_path(), 'User', 'Preferences.sublime-settings') pref = {} if exists(pref_file): try: with open(pref_file, "r") as f: # Allow C style comments and be forgiving of trailing commas content = sanitize_json(f.read(), True) pref = json.loads(content) except Exception: pass pref[SCHEME] = name j = json.dumps(pref, sort_keys=True, indent=4, separators=(',', ': ')) try: with open(pref_file, 'w') as f: f.write(j + "\n") except Exception: pass
def _load_tweak_settings(self): self._ensure_temp() p_settings = {} tweaks = packages_path(join(normpath(TEMP_PATH), basename(TWEAK_SETTINGS))) if exists(tweaks): try: with open(tweaks, "r") as f: # Allow C style comments and be forgiving of trailing commas content = sanitize_json(f.read(), True) p_settings = json.loads(content) except: pass return p_settings
def _load_tweak_settings(self): """Load the tweak settings.""" self._ensure_temp() p_settings = {} tweaks = packages_path( join(normpath(TEMP_PATH), basename(TWEAK_SETTINGS))) if exists(tweaks): try: with open(tweaks, "r") as f: # Allow C style comments and be forgiving of trailing commas content = sanitize_json(f.read(), True) p_settings = json.loads(content) except Exception: pass return p_settings
def _set_theme_safely(self, name): pref_file = join(sublime.packages_path(), 'User', 'Preferences.sublime-settings') pref = {} if exists(pref_file): try: with open(pref_file, "r") as f: # Allow C style comments and be forgiving of trailing commas content = sanitize_json(f.read(), True) pref = json.loads(content) except: pass pref[SCHEME] = name j = json.dumps(pref, sort_keys=True, indent=4, separators=(',', ': ')) try: with open(pref_file, 'w') as f: f.write(j + "\n") except: pass