python类save_settings()的实例源码

phpfmt.py 文件源码 项目:phpfmt_stable 作者: nanch 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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')
SingleTrailingNewLine.py 文件源码 项目:sublime-single-trailing-new-line 作者: mattst 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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)
xsupport.py 文件源码 项目:VintageousPlus 作者: trishume 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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))
PanePane.py 文件源码 项目:PanePane 作者: mjsmith1028 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def save_settings(cls):
        sublime.save_settings(
            WindowCommandSettings.SETTINGS_FILE)
PanePane.py 文件源码 项目:PanePane 作者: mjsmith1028 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def run(self, setting):
        self.toggle_boolean_setting(setting)
        self.save_settings()
text_commands.py 文件源码 项目:sublime_gpg 作者: dmitrievav 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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)
ToolTipHelper.py 文件源码 项目:ToolTip-Helper 作者: doobleweb 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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")
ToolTipHelper.py 文件源码 项目:ToolTip-Helper 作者: doobleweb 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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)
googleitup.py 文件源码 项目:InstaGoogling 作者: Ivanca 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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")
LanguageTool.py 文件源码 项目:languagetool-sublime 作者: gtarawneh 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def saveIgnoredRules(ignored):
    settings = sublime.load_settings(lt_user_settings_file)
    settings.set('ignored', ignored)
    sublime.save_settings(lt_user_settings_file)
util.py 文件源码 项目:Sublundo 作者: libundo 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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)
bracket_highligher.py 文件源码 项目:LaTeXYZ 作者: randy3k 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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)
ksp_plugin.py 文件源码 项目:SublimeKSP 作者: nojanath 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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")
SettingsManager.py 文件源码 项目:SpotifyWeb 作者: DevInsideYou 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __save_settings(self):
    sublime.save_settings(self.__settings_file_name)
persist.py 文件源码 项目:sublime-text-3-packages 作者: nickjj 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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')
sublimegdb.py 文件源码 项目:SublimeRemoteGDB 作者: summerwinter 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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()
goGuru.py 文件源码 项目:GoGuru 作者: alvarolm 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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")
anaconda.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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)
persist.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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')
phpfmt.py 文件源码 项目:phpfmt_stable 作者: nanch 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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)


问题


面经


文章

微信
公众号

扫码关注公众号