我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sublime.save_settings()。
def run(self, edit): def setIndentWithSpace(text): s = sublime.load_settings('phpfmt.sublime-settings') v = text.strip() if not v: v = False else: v = int(v) s.set("indent_with_space", v) sublime.save_settings('phpfmt.sublime-settings') sublime.status_message("phpfmt (indentation): done") sublime.active_window().active_view().run_command("fmt_now") s = sublime.load_settings('phpfmt.sublime-settings') spaces = s.get("indent_with_space", 4) if not spaces: spaces = "" spaces = str(spaces) self.view.window().show_input_panel('how many spaces? (leave it empty to return to tabs)', spaces, setIndentWithSpace, None, None)
def run(self, edit): try: settings = sublime.load_settings(SETTINGS_FILE) syntax_current_file = self.view.settings().get("syntax") enable_for_syntaxes = settings.get(ENABLE_FOR_SYNTAXES_LIST_SETTING, []) if syntax_current_file not in enable_for_syntaxes: enable_for_syntaxes.append(syntax_current_file) enable_for_syntaxes.sort() settings.set(ENABLE_FOR_SYNTAXES_LIST_SETTING, enable_for_syntaxes) sublime.save_settings(SETTINGS_FILE) msg = "Syntax added to the syntax list" sublime.status_message(msg) else: msg = "Syntax already in the syntax list" sublime.status_message(msg) except Exception: msg = "The SingleTrailingNewLine.sublime-settings file is invalid" sublime.status_message(msg)
def run(self, edit): try: settings = sublime.load_settings(SETTINGS_FILE) syntax_current_file = self.view.settings().get("syntax") enable_for_syntaxes = settings.get(ENABLE_FOR_SYNTAXES_LIST_SETTING, []) if syntax_current_file in enable_for_syntaxes: enable_for_syntaxes.remove(syntax_current_file) enable_for_syntaxes.sort() settings.set(ENABLE_FOR_SYNTAXES_LIST_SETTING, enable_for_syntaxes) sublime.save_settings(SETTINGS_FILE) msg = "Syntax removed from the syntax list" sublime.status_message(msg) else: msg = "Syntax was not in the syntax list" sublime.status_message(msg) except Exception: msg = "The SingleTrailingNewLine.sublime-settings file is invalid" sublime.status_message(msg)
def run(self, edit, dirs): settings = sublime.load_settings('dired.sublime-settings') for key_name in ['reuse_view', 'bookmarks']: settings.set(key_name, settings.get(key_name)) bm = bookmarks() for path in dirs : bm.append(path) settings.set('bookmarks', bm) # This command makes/writes a sublime-settings file at Packages/User/, # and doesn't write into one at Packages/dired/. sublime.save_settings('dired.sublime-settings') sublime.status_message('Bookmarking succeeded.') self.view.erase_regions('marked')
def run(self, edit): settings = sublime.load_settings('dired.sublime-settings') for key_name in ['reuse_view', 'bookmarks']: settings.set(key_name, settings.get(key_name)) bm = bookmarks() def on_done(select) : if not select == -1 : bm.pop(select) sublime.status_message('Remove selected bookmark.') settings.set('bookmarks', bm) sublime.save_settings('dired.sublime-settings') self.view.window().show_quick_panel(bm, on_done)
def set_generic_view_setting(view, name, value, opt, globally=False): if opt.scope == SCOPE_VI_VIEW: name = 'vintageous_' + name if not opt.parser: if not globally or (opt.scope not in (SCOPE_VI_VIEW, SCOPE_VI_WINDOW)): view.settings().set(name, value) else: prefs = sublime.load_settings('Preferences.sublime-settings') prefs.set(name, value) sublime.save_settings('Preferences.sublime-settings') return else: if not globally or (opt.scope not in (SCOPE_VI_VIEW, SCOPE_VI_WINDOW)): view.settings().set(name, opt.parser(value)) else: name = 'vintageous_' + name prefs = sublime.load_settings('Preferences.sublime-settings') prefs.set(name, opt.parser(value)) sublime.save_settings('Preferences.sublime-settings') return raise ValueError("Vintageous: bad option value")
def temporary_settings_fix(): s = sublime.load_settings('gpg.sublime-settings') if s.has('gpg_command'): s.set('gpg.command', s.get('gpg_command', 'gpg')) s.erase('gpg_command') if s.has('homedir'): s.set('gpg.homedir', s.get('homedir', '')) s.erase('homedir') if s.has('verbosity'): s.set('gpg.verbosity', s.get('verbosity', 1)) s.erase('verbosity') if s.has('recipients'): s.set('gpg.recipients', s.get('recipients', '')) s.erase('recipients') if s.has('first_run'): s.set('gpg.readme_shown', not s.get('first_run', True)) s.erase('first_run') sublime.save_settings('gpg.sublime-settings')
def run(self, edit): def done(path): settings = sublime.load_settings("PICO-8.sublime-settings") settings.set("pico-8_path", path) sublime.save_settings("PICO-8.sublime-settings") return platform = sublime.platform() if platform == "linux": self.view.window().show_input_panel("PICO-8 Path", "/path/to/pico8", done, None, None) elif platform == "osx": self.view.window().show_input_panel("PICO-8 Path", "/path/to/PICO-8.app/Contents/MacOS/pico8", done, None, None) elif platform == "windows": self.view.window().show_input_panel("PICO-8 Path", "C:\\Program Files (x86)\\PICO-8\\pico8.exe", done, None, None) else: sublime.error_message("Error: could not resolve platform\n\n[\"linux\", \"osx\", \"windows\"]") return
def _update_ignored_packages(): # Updates the list of ignored packages with packages that are redundant, # obsolete, or cause problems due to conflicts e.g. Vintage, Vintageous, # etc. settings = sublime.load_settings('Preferences.sublime-settings') ignored_packages = settings.get('ignored_packages', []) conflict_packages = [x for x in ['Six', 'Vintage', 'Vintageous'] if x not in ignored_packages] if conflict_packages: print('NeoVintageous: update ignored packages with conflicts {}'.format(conflict_packages)) ignored_packages = sorted(ignored_packages + conflict_packages) settings.set('ignored_packages', ignored_packages) sublime.save_settings('Preferences.sublime-settings')
def restore_setting(name, value): config = sublime.load_settings(CONFIG_NAME) config.set(name, value) sublime.save_settings(CONFIG_NAME)
def save_test_run(self, command, working_dir): s = sublime.load_settings("ElixirTest.last-run") s.set("last_test_run", command) s.set("last_test_working_dir", working_dir) sublime.save_settings("ElixirTest.last-run")
def set_kodi_folder(path): """ Sets kodi path to *path and saves it if file exists. """ if os.path.exists(path): sublime.load_settings(SETTINGS_FILE).set("kodi_path", path) sublime.save_settings(SETTINGS_FILE) else: logging.critical("Folder %s does not exist." % path)
def set_ip(self, ip): """ set and save ip of adb device, return to actions menu when finished """ self.settings.set("remote_ip", ip) sublime.save_settings(SETTINGS_FILE) self.window.run_command("remote_actions")
def put(self, setting, value): """Store and save `setting` as `value`. Args: setting (str): The name of the setting to be accessed. value (str, int, bool): The value to be stored. """ self.settings.set(setting, value) sublime.save_settings(self.settings_file)
def run(self, edit): view = self.view prev = s.get('flipped_key_bindings') if prev: s.set('flipped_key_bindings', False) else: s.set('flipped_key_bindings', True) sublime.save_settings("Hungry Backspace.sublime-settings")
def settings_set(key): sublime.load_settings(SETTINGS).set(key) sublime.save_settings(SETTINGS)
def update_authentication_setting(auth_type=AUTHENTICATION_OAUTH2): s = sublime.load_settings(SFDC_HUANGXY_SETTINGS) s.set("authentication", auth_type) sublime.save_settings(SFDC_HUANGXY_SETTINGS)
def update_default_browser(browser_name): s = sublime.load_settings(SFDC_HUANGXY_SETTINGS) # Save the updated settings s.set("default_browser", browser_name) sublime.save_settings(SFDC_HUANGXY_SETTINGS)
def update_default_project(default_project): s = sublime.load_settings(SFDC_HUANGXY_SETTINGS) # Save the updated settings s.set("default_project", default_project) sublime.save_settings(SFDC_HUANGXY_SETTINGS)
def update_project_session(default_project): s = sublime.load_settings(SFDC_HUANGXY_SETTINGS) # Save the updated settings s.set("default_project", default_project) sublime.save_settings(SFDC_HUANGXY_SETTINGS)
def plugin_unloaded(): for k in openfiles: try: openfiles[k].close() except Exception as e: if getSetting('debug'): print(e) sublime.save_settings(setting_file) from package_control import events if events.remove(package_name): if os.path.isdir(getDocphpPath()): shutil.rmtree(getDocphpPath())
def setSetting(key, value): currentSettings.set(key, value) sublime.save_settings(setting_file)
def saveSetting(key, value = None): conf = sublime.load_settings(sFile) conf.set(key, value) return sublime.save_settings(sFile)
def save_changes(self): try: file_settings = 'ToolTipHelper.sublime-settings' file_load = sublime.load_settings(file_settings) files = file_load.get("files") files.append({"file_name":self.file_name, "source":self.source, "link":self.link}) file_load.set("files", files) sublime.save_settings(file_settings) sublime.status_message("the changes was saved!") except Exception as e: sublime.status_message("cannot save the changes")
def save_keyorder_list(self): """ save the new keyorder in settings""" file_settings = 'ToolTipHelper.sublime-settings' file_load = sublime.load_settings(file_settings) file_load.set("keyorder", self.keyorder) sublime.save_settings(file_settings)
def run(self, paths = [], type = 'item'): Preferences = sublime.load_settings("Preferences.sublime-settings") excluded = Preferences.get("binary_file_patterns", []) for item in self.items(paths, type, SideBarSelection(paths)): excluded.append(item) for k, v in enumerate(excluded): excluded[k] = excluded[k].replace('\\', '/') excluded[k] = re.sub('([a-z])\:/', '/\\1/', excluded[k], 0, re.I) excluded[k] = re.sub('/$', '/**', excluded[k]) excluded = list(set(excluded)) excluded = sorted(excluded) Preferences.set("binary_file_patterns", excluded); sublime.save_settings("Preferences.sublime-settings");
def on_done(self, index): theme = self.themes[index] + '.sublime-theme' self.set_scheme(self.schemes[index]) self.set_theme(theme) self.save_settings(theme)
def save_settings(self, theme): sublime.save_settings('Preferences.sublime-settings') sublime.status_message('Agila Theme: ' + theme) print('') print('[Agila Theme] ' + theme) print('')
def _set_enabled(self, config_name: str, is_enabled: bool): if _settings_obj: client_settings = self._global_settings.setdefault(config_name, {}) client_settings["enabled"] = is_enabled _settings_obj.set("clients", self._global_settings) sublime.save_settings("LSP.sublime-settings")
def _save_test_run(self, command: str) -> None: """Save the last ran test """ s = sublime.load_settings('PythonTestRunner.last-run') s.set('last_test_run', command) sublime.save_settings('PythonTestRunner.last-run')
def run(self, edit, option): s = sublime.load_settings('phpfmt.sublime-settings') options = { "autocomplete":"autocomplete", "autoimport":"dependency autoimport", "enable_auto_align":"auto align", "format_on_save":"format on save", "psr1":"PSR1", "psr1_naming":"PSR1 Class and Method Naming", "psr2":"PSR2", "readini":"look for .php.tools.ini", "smart_linebreak_after_curly":"smart linebreak after curly", "skip_if_ini_missing":"skip if ini file is missing", "visibility_order":"visibility order", "yoda":"yoda mode", } s = sublime.load_settings('phpfmt.sublime-settings') value = s.get(option, False) if value: s.set(option, False) msg = "phpfmt: "+options[option]+" disabled" print_debug(msg) sublime.status_message(msg) else: s.set(option, True) msg = "phpfmt: "+options[option]+" enabled" print_debug(msg) sublime.status_message(msg) sublime.save_settings('phpfmt.sublime-settings')
def run(self, edit, **kwargs): try: arg_value = kwargs.get("value", None) if not isinstance(arg_value, bool): msg = "Invalid args" sublime.status_message(msg) return settings = sublime.load_settings(SETTINGS_FILE) if arg_value: settings.set(ENABLE_FOR_ALL_SYNTAXES_SETTING, True) msg = "Enable For All Syntaxes - True" else: settings.set(ENABLE_FOR_ALL_SYNTAXES_SETTING, False) msg = "Enable For All Syntaxes - False" sublime.save_settings(SETTINGS_FILE) sublime.status_message(msg) except Exception: msg = "The SingleTrailingNewLine.sublime-settings file is invalid" sublime.status_message(msg)
def run(self): prefs = sublime.load_settings('Preferences.sublime-settings') value = prefs.get('vintageous_use_ctrl_keys', False) prefs.set('vintageous_use_ctrl_keys', (not value)) sublime.save_settings('Preferences.sublime-settings') status = 'enabled' if (not value) else 'disabled' print("Package.Vintageous: Use of Ctrl- keys {0}.".format(status)) sublime.status_message("Vintageous: Use of Ctrl- keys {0}" .format(status))
def save_settings(cls): sublime.save_settings( WindowCommandSettings.SETTINGS_FILE)
def run(self, setting): self.toggle_boolean_setting(setting) self.save_settings()
def plugin_loaded(): ''' Sublime 3 calls this once the plugin API is ready. ''' # TODO: remove this fix and its def above after a few updates temporary_settings_fix() s = sublime.load_settings('gpg.sublime-settings') gpg_readme_shown = s.get('gpg.readme_shown', False) if not gpg_readme_shown: s.set('gpg.readme_shown', True) sublime.save_settings('gpg.sublime-settings') sublime.set_timeout_async(lambda: sublime.active_window().run_command('gpg_readme'), 5000)
def save_changes(self): try: file_settings = 'ToolTipHelper.sublime-settings' file_load = sublime.load_settings(file_settings) files = file_load.get("files") files.append({"file_name":self.file_name, "scope":self.scope, "link":self.link}) file_load.set("files", files) sublime.save_settings(file_settings) sublime.status_message("the changes was saved!") except Exception as e: sublime.status_message("cannot save the changes")
def save_keyorder_list(self): """ save the new keyorder in settings """ file_settings = 'ToolTipHelper.sublime-settings' file_load = sublime.load_settings(file_settings) file_load.set("keyorder", self.keyorder) sublime.save_settings(file_settings)
def setSettingIsOpen(val): setting = sublime.load_settings("Preferences.sublime-settings") setting.set("instagoogling_is_open", True if val else False) sublime.save_settings("Preferences.sublime-settings")
def saveIgnoredRules(ignored): settings = sublime.load_settings(lt_user_settings_file) settings.set('ignored', ignored) sublime.save_settings(lt_user_settings_file)
def set_setting(name, value): """Store and save `name` as `value`. """ settings = sublime.load_settings(SETTING_FILE) settings.set(name, value) sublime.save_settings(SETTING_FILE)
def run(self, edit, remove=False): bh_core_settings = sublime.load_settings(bh_core_settings_file) for k, v in bh_core_latex_settings.items(): bh_core_settings.set(k, self.merge(v, bh_core_latex_settings[k], remove)) sublime.save_settings(bh_core_settings_file)
def run(self, setting, default): s = sublime.load_settings("KSP.sublime-settings") s.set(setting, not s.get(setting, False)) sublime.save_settings("KSP.sublime-settings")
def __save_settings(self): sublime.save_settings(self.__settings_file_name)
def save(self, view=None): """ Regenerate and save the user settings. User settings are updated with the default settings and the defaults from every linter, and if the user settings are currently being edited, the view is updated. """ self.load() # Fill in default linter settings settings = self.settings linters = settings.pop('linters', {}) for name, linter in linter_classes.items(): default = linter.settings().copy() default.update(linters.pop(name, {})) for key, value in (('@disable', False), ('args', []), ('excludes', [])): if key not in default: default[key] = value linters[name] = default settings['linters'] = linters filename = '{}.sublime-settings'.format(PLUGIN_NAME) user_prefs_path = os.path.join(sublime.packages_path(), 'User', filename) settings_views = [] if view is None: # See if any open views are the user prefs for window in sublime.windows(): for view in window.views(): if view.file_name() == user_prefs_path: settings_views.append(view) else: settings_views = [view] if settings_views: def replace(edit): if not view.is_dirty(): j = json.dumps({'user': settings}, indent=4, sort_keys=True) j = j.replace(' \n', '\n') view.replace(edit, sublime.Region(0, view.size()), j) for view in settings_views: edits[view.id()].append(replace) view.run_command('sublimelinter_edit') view.run_command('save') else: user_settings = sublime.load_settings('SublimeLinter.sublime-settings') user_settings.set('user', settings) sublime.save_settings('SublimeLinter.sublime-settings')
def cleanup(): global gdb_global_clean_count with gdb_global_lock: if gdb_global_clean_count == 1: gdb_global_clean_count = 0 else: gdb_global_clean_count = 1 currentLayout = gdb_bkp_window.get_layout() s = sublime.load_settings("SublimeRemoteGDB.sublime-settings") s.set("layout",currentLayout) log_debug(str(gdb_bkp_window.num_groups())) log_debug("\n") gdb_allview = gdb_bkp_window.views() for v in gdb_allview: if v.name().find("Callstack") != -1: s.set("callstack_group",gdb_bkp_window.get_view_index(v)[0]) if v.name().find("Console") != -1: s.set("console_group",gdb_bkp_window.get_view_index(v)[0]) if v.name().find("Session") != -1: s.set("session_group",gdb_bkp_window.get_view_index(v)[0]) if v.name().find("Variables") != -1: s.set("variables_group",gdb_bkp_window.get_view_index(v)[0]) if v.name().find("Threads") != -1: s.set("threads_group",gdb_bkp_window.get_view_index(v)[0]) if v.name().find("Breakpoints") != -1: s.set("breakpoints_group",gdb_bkp_window.get_view_index(v)[0]) sublime.save_settings("SublimeRemoteGDB.sublime-settings") global __debug_file_handle if get_setting("close_views", True): for view in gdb_views: view.close() if get_setting("push_pop_layout", True): gdb_bkp_window.set_layout(gdb_bkp_layout) gdb_bkp_window.focus_view(gdb_bkp_view) if __debug_file_handle is not None: if __debug_file_handle != sys.stdout: __debug_file_handle.close() __debug_file_handle = None global gdb_process gdb_process = GDBProcess()
def plugin_loaded(): # load shellenv def load_shellenv(): global shellenv from .dep import shellenv # try golangconfig if get_setting("goguru_use_golangconfig", False): try: global golangconfig import golangconfig except: error("couldn't import golangconfig:", sys.exc_info()[0]) log("using shellenv instead of golangconfig") # use_golangconfig = False load_shellenv() else: load_shellenv() log("debug:", get_setting("goguru_debug", False)) log("use_golangconfig", get_setting("goguru_use_golangconfig", False)) # keep track of the version if possible (pretty nasty workaround, any other ideas ?) try: PluginPath = os.path.dirname(os.path.realpath(__file__)) p = subprocess.Popen(["git", "describe", "master", "--tags"], stdout=subprocess.PIPE, cwd=PluginPath) GITVERSION = p.communicate()[0].decode("utf-8").rstrip() if p.returncode != 0: debug("git return code", p.returncode) raise Exception("git return code", p.returncode) defsettings = os.path.join(PluginPath, 'Default.sublime-settings') f = open(defsettings, 'r') filedata = f.read() f.close() newdata = filedata.replace(get_setting('goguru_version'), GITVERSION + '_') f = open(defsettings, 'w') f.write(newdata) f.close() except: debug("couldn't get git tag:", sys.exc_info()[0]) # read version log("version:", get_setting('goguru_version')) # check if user setting exists and creates it us = sublime.load_settings("GoGuru.sublime-settings") if (not us.has('goguru_debug')): us.set('goguru_debug', get_setting("goguru_debug", False)) sublime.save_settings("GoGuru.sublime-settings")
def monitor_plugins(): """Monitor for any plugin that conflicts with anaconda """ view = sublime.active_window().active_view() if not get_settings(view, 'auto_unload_conflictive_plugins', True): return plist = [ 'Jedi - Python autocompletion', # breaks auto completion 'SublimePythonIDE', # interfere with autocompletion 'SublimeCodeIntel' # breaks everything, SCI is a mess ] hllist = [ 'MagicPython', # breaks autocompletion on [dot] 'Python 3' # breeaks autocompletion on [dot] ] for plugin in plist: if plugin in sys.modules: [ sublime_plugin.unload_module(m) for k, m in sys.modules.items() if plugin in k ] if plugin not in DISABLED_PLUGINS: DISABLED_PLUGINS.append(plugin) for highlighter in hllist: paths = os.listdir(sublime.packages_path()) + \ os.listdir(sublime.installed_packages_path()) for p in paths: if highlighter in p: fname = '{0}.sublime-settings'.format(highlighter) s = sublime.load_settings(fname) if all((s.has('auto_complete_triggers'), s.has('extensions'))): break auto_complete = [ { 'characters': '.', 'selector': 'source.python - string - constant.numeric', # noqa } ] s.set('extensions', ['py']) s.set('auto_complete_triggers', auto_complete) sublime.save_settings(fname) break sublime.set_timeout_async(monitor_plugins, 500000)
def run(self, edit): s = sublime.load_settings('phpfmt.sublime-settings') php_bin = s.get("php_bin", "php") formatter_path = os.path.join(dirname(realpath(sublime.packages_path())), "Packages", "phpfmt", "fmt.phar") cmd_passes = [php_bin,formatter_path,'--list-simple']; print_debug(cmd_passes) if os.name == 'nt': startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW p = subprocess.Popen(cmd_passes, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, startupinfo=startupinfo) else: p = subprocess.Popen(cmd_passes, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) out, err = p.communicate() descriptions = out.decode("utf-8").strip().split(os.linesep) def on_done(i): if i >= 0 : s = sublime.load_settings('phpfmt.sublime-settings') passes = s.get('passes', []) chosenPass = descriptions[i].split(' ') option = chosenPass[0] passDesc = option if option in passes: passes.remove(option) msg = "phpfmt: "+passDesc+" disabled" print_debug(msg) sublime.status_message(msg) else: passes.append(option) msg = "phpfmt: "+passDesc+" enabled" print_debug(msg) sublime.status_message(msg) s.set('passes', passes) sublime.save_settings('phpfmt.sublime-settings') self.view.window().show_quick_panel(descriptions, on_done, sublime.MONOSPACE_FONT)