Python sublime 模块,run_command() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sublime.run_command()

项目:Sublime-minihtml-Preview    作者:ehuss    | 项目源码 | 文件源码
def run(self):

        sublime.run_command('new_window')
        new_window = sublime.active_window()
        new_window.run_command('set_layout', {
            'cols': [0.0, 0.5, 1.0],
            'rows': [0.0, 1.0],
            'cells': [[0, 0, 1, 1], [1, 0, 2, 1]]
        })
        new_window.focus_group(0)
        edit_view = new_window.new_file()
        edit_view_settings = edit_view.settings()
        edit_view_settings.set('minihtml_preview_edit_view', True)
        edit_view.set_scratch(True)
        edit_view.set_syntax_file('Packages/HTML/HTML.sublime-syntax')
        # Unfortunately Sublime indents on 'insert'
        edit_view.settings().set('auto_indent', False)
        edit_view.run_command('insert', {'characters': template})
        edit_view.settings().set('auto_indent', True)
        new_window.focus_group(1)
        output_view = new_window.new_file()
        output_view.set_scratch(True)
        edit_view_settings.set('minihtml_preview_output_view_id',
                               output_view.id())
        new_window.focus_group(0)
项目:NoDialogs    作者:maximsmol    | 项目源码 | 文件源码
def run(self):
        self.window = sublime.active_window()

        for view in self.window.views():
            self.view = view

            if not self.will_closing_discard(view):
                continue

            self.last_focused_view = self.window.active_view()
            self.window.focus_view(view)

            self.show_discard_prompt()
            return # wait for input, then start over

        self.window.run_command('close_window')
项目:NoDialogs    作者:maximsmol    | 项目源码 | 文件源码
def run(self):
        for win in sublime.windows():
            self.window = win
            for view in self.window.views():
                self.view = view

                if not self.will_closing_discard(view):
                    continue

                self.last_focused_view = self.window.active_view()
                self.window.focus_view(view)

                self.show_discard_prompt()
                return # wait for input, then start over

        sublime.run_command('exit')


#
# Rest of the commands
#
项目:a-file-icon    作者:ihodev    | 项目源码 | 文件源码
def ensure_reload():
        """
        Ensure all modules reload to initialize plugin successfully.
        """
        start_upgrade_msg = "Do not close the Sublime Text. Upgrading {}".format(
            PACKAGE_NAME
        )
        finish_upgrade_msg = "{} upgrade finished.".format(PACKAGE_NAME)

        active_view = sublime.active_window().active_view()
        active_view.set_status("afi_status", start_upgrade_msg)

        def erase_status():
            active_view.erase_status("afi_status")

        def reload():
            sublime.run_command("afi_reload")
            active_view.set_status("afi_status", finish_upgrade_msg)
            sublime.set_timeout(erase_status, 2000)

        sublime.set_timeout_async(reload, 5000)
项目:MarkdownLivePreview    作者:math2001    | 项目源码 | 文件源码
def show_html(md_view, preview):
    global windows_phantom_set
    html = markdown2html(get_view_content(md_view), os.path.dirname(md_view.file_name()), md_view.settings().get('color_scheme'))

    phantom_set = windows_phantom_set.setdefault(preview.window().id(),
                                             sublime.PhantomSet(preview, 'markdown_live_preview'))
    phantom_set.update([sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK,
                                    lambda href: sublime.run_command('open_url', {'url': href}))])

    # lambda href: sublime.run_command('open_url', {'url': href})
    # get the "ratio" of the markdown view's position.
    # 0 < y < 1
    y = md_view.text_to_layout(md_view.sel()[0].begin())[1] / md_view.layout_extent()[1]
    # set the vector (position) for the preview
    vector = [0, y * preview.layout_extent()[1]]
    # remove half of the viewport_extent.y to center it on the screen (verticaly)
    vector[1] -= preview.viewport_extent()[1] / 2
    # make sure the minimum is 0
    vector[1] = 0 if vector[1] < 0 else vector[1]
    # the hide the first line
    vector[1] += preview.line_height()
    preview.set_viewport_position(vector, animate=False)
项目:sublimeTextConfig    作者:luoye-fe    | 项目源码 | 文件源码
def typescript_update_structure(view, force):
    return
    project.assert_initialisation_finished()

    def async_react(members, filename, sender_view_id):
        ## members is the already json-decoded tss.js answer
        Debug('structure', 'STRUCTURE async_react for %s in start view %s, now view %s'
                % (filename, view.id(), sublime.active_window().active_view().id()) )

        if sublime.active_window().active_view().id() != sender_view_id or view.id() != sender_view_id:
            Debug('structure', 'STRUCTURE async_react canceled because of view change')
            return

        view.run_command('typescript_outline_view_set_text', {"members": members} )


    if T3SVIEWS.OUTLINE.is_active() and (force or not T3SVIEWS.OUTLINE.is_current_ts(view)):
        Debug('structure', 'STRUCTURE for %s in view %s, active view is %s'
            % (view.file_name(), view.id(), sublime.active_window().active_view().id()))
        TSS.structure(view.file_name(), view.id(), async_react)


# OPEN and WRITE TEXT TO OUTLINE VIEW
项目:sublimeTextConfig    作者:luoye-fe    | 项目源码 | 文件源码
def run(self, edit, characters):
        project = get_or_create_project_and_add_view(self.view)
        if project:
            filename = self.view.file_name()

            if not project.get_setting('activate_build_system'):
                Debug('notify', "Build system is disabled.")
                return

            project.assert_initialisation_finished()

            self.window = sublime.active_window()
            if characters != False:
                self.window.run_command('save')

            project.compile_once(self.window, filename)
项目:GhostText-for-SublimeText    作者:GhostText    | 项目源码 | 文件源码
def on_request(self, request):
        if len(sublime.windows()) == 0 or self.new_window_on_connect:
            sublime.run_command('new_window')

        if len(self.window_command_on_connect) > 0:
            sublime.active_window().run_command(self.window_command_on_connect)

        web_socket_server_thread = WebSocketServerThread(self._settings)
        web_socket_server_thread.start()
        while not web_socket_server_thread.get_server().get_running():
            sleep(0.1)

        port = web_socket_server_thread.get_server().get_port()
        Utils.show_status('Connection opened')

        return Response(json.dumps({"WebSocketPort": port, "ProtocolVersion": 1}),
                        "200 OK",
                        {'Content-Type': 'application/json'})
项目:CMakeBuilder    作者:rwols    | 项目源码 | 文件源码
def _create_project(self):
        os.makedirs(self.project_dir, exist_ok=True)
        if not os.path.exists(self.project_dir):
            sublime.error_message("Could not create directory %s" % self.project_dir)
        os.makedirs(os.path.join(self.project_dir, "src"), exist_ok=True)
        with open(os.path.join(self.project_dir, "CMakeLists.txt"), "w") as f:
            f.write(CMAKELISTS_FILE.format(self.project_name, self.type))
        with open(os.path.join(self.project_dir, "src", "main." + self.suffix), "w") as f:
            if self.type == "C":
                f.write(CFILE)
            else:
                f.write(CXXFILE)
        with open(os.path.join(self.project_dir, "src", "CMakeLists.txt"), "w") as f:
            f.write(CMAKELISTS_SRC_FILE.format(self.suffix))
        project_file = os.path.join(self.project_dir, self.project_name + ".sublime-project")
        with open(project_file, "w") as f:
            f.write(PROJECTFILE)
        if sublime.ok_cancel_dialog('Select the file %s in "%s" in the upcoming prompt...' % (self.project_name + ".sublime-project", self.project_dir)):
            sublime.run_command("prompt_open_project_or_workspace")
项目:Sublundo    作者:libundo    | 项目源码 | 文件源码
def on_close(self, view):
        """Clean up the visualization.
        """
        if 'text.sublundo.tree' not in view.scope_name(0):
            return

        w = sublime.active_window()
        single = not w.views_in_group(0) or not w.views_in_group(1)
        if w.num_groups() == 2 and single:
            sublime.set_timeout(lambda: w.set_layout(
                {
                    "cols": [0.0, 1.0],
                    "rows": [0.0, 1.0],
                    "cells": [[0, 0, 1, 1]]
                }
            ), 300)
        w.run_command('hide_panel', {'panel': 'output.sublundo'})
        w.destroy_output_panel('output.sublundo')
        for v in w.views():
            v.erase_regions('sublundo')
项目:SpotifyWeb    作者:DevInsideYou    | 项目源码 | 文件源码
def open_settings_window(self):
    sublime.run_command("new_window")

    settings_window = sublime.active_window()

    left_right_group = {
      "cols": [0.0, 0.5, 1.0],
      "rows": [0.0, 1.0],
      "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
    }

    settings_window.set_layout(left_right_group) # the left group is focused by default

    settings_window.run_command("open_file", { "file": "${packages}/SpotifyWeb/" + self.__settings_file_name})

    settings_window.focus_group(1) # focus the right group

    settings_window.run_command("open_file", { "file": "${packages}/User/" + self.__settings_file_name})
项目:hyperhelp    作者:OdatNurd    | 项目源码 | 文件源码
def follow_link(self):
        topic = self.extract_topic()
        if topic is not None:
            return sublime.run_command("hyper_help", {"topic": topic})

        log("Cannot follow link; no link found under the cursor")
项目:hyperhelp    作者:OdatNurd    | 项目源码 | 文件源码
def on_text_command(self, view, command, args):
        """
        Listen for double clicks in help files and, if they occur over links,
        follow the link instead of selecting the text.
        """
        if command == "drag_select" and args.get("by", None) == "words":
            event = args["event"]
            point = view.window_to_text((event["x"], event["y"]))

            if view.match_selector(point, "text.hyperhelp meta.link"):
                view.window().run_command("hyper_help_navigate", {"nav": "follow_link"})
                return ("noop")

        return None
项目:FileManager    作者:math2001    | 项目源码 | 文件源码
def run(self, edit, event):
        base_path, input_path = self.get_path(event)
        abspath = computer_friendly(os.path.join(base_path, input_path))
        sublime.run_command('fm_creater', {'abspath': abspath,
                                           'input_path': input_path})
项目:FileManager    作者:math2001    | 项目源码 | 文件源码
def transform_aliases(self, string):
        """Transform aliases using the settings and the default variables
        It's recursive, so you can use aliases *in* your aliases' values
        """

        def has_unescaped_dollar(string):
            start = 0
            while True:
                index = string.find('$', start)
                if index < 0:
                    return False
                elif string[index-1] == '\\':
                    start = index + 1
                else:
                    return True

        string = string.replace('$$', '\\$')

        vars = self.window.extract_variables()
        vars.update(get_settings().get('aliases'))

        inifinite_loop_counter = 0
        while has_unescaped_dollar(string):
            inifinite_loop_counter += 1
            if inifinite_loop_counter > 100:
                sublime.error_message("Infinite loop: you better check your "
                                      "aliases, they're calling each other "
                                      "over and over again.")
                if get_settings().get('open_help_on_alias_infinite_loop',
                                      True) is True:

                    sublime.run_command('open_url', {
                        'url': 'https://github.com/math2001/ '
                               'FileManager/wiki/Aliases '
                               '#watch-out-for-infinite-loops'
                    })
                return string
            string = sublime.expand_variables(string, vars)

        return string
项目:FileManager    作者:math2001    | 项目源码 | 文件源码
def on_post_save(self, view):
        """Reload FileManager
        To use this, you need to have this plugin:
        https://github.com/math2001/sublime-plugin-reloader"""
        if not (os.path.dirname(__file__) in view.file_name() and
            view.file_name().endswith('.py')):
            return
        sublime.run_command('reload_plugin', {
            'main': __file__,
            'folders': ["FMcommands"],
            'scripts': ["input_for_path", "sublimefunctions",
                    "pathhelper"],
        })
项目:FileManager    作者:math2001    | 项目源码 | 文件源码
def on_load(self, view):
        settings = view.settings()
        snippet = settings.get('fm_insert_snippet_on_load', None)
        if snippet:
            view.run_command('insert_snippet', {'contents': snippet})
            settings.erase('fm_insert_snippet_on_load')
            if get_settings().get('save_after_creating'):
                view.run_command('save')
            if settings.get('fm_reveal_in_sidebar'):
                view.window().run_command('reveal_in_side_bar')
项目:FileManager    作者:math2001    | 项目源码 | 文件源码
def on_text_command(self, view, command, args):
        if command not in ['undo', 'unindent'] or view.name() != 'FileManager::input-for-path':
            return

        settings = view.settings()

        if command == 'unindent':
            index = settings.get('completions_index')
            settings.set('go_backwards', True)
            view.run_command('insert', {'characters': '\t'})
            return

        # command_history: (command, args, times)
        first = view.command_history(0)
        if first[0] != 'fm_edit_replace' or first[2] != 1:
            return

        second = view.command_history(-1)
        if ((second[0] != 'reindent') and
            not (second[0] == 'insert' and second[1] == {'characters': '\t'})):
            return

        settings.set('ran_undo', True)
        view.run_command('undo')

        index = settings.get('completions_index')
        if index == 0 or index is None:
            settings.erase('completions')
            settings.erase('completions_index')
        else:
            settings.set('completions_index', index - 1)
项目:SublimeRemoteGDB    作者:summerwinter    | 项目源码 | 文件源码
def destroy_view(self):
        sublime.active_window().focus_view(self.view)
        sublime.active_window().run_command("close")
        self.view = None
        self.closed = True
项目:SublimeRemoteGDB    作者:summerwinter    | 项目源码 | 文件源码
def do_add_line(self, line):
        self.view.run_command("gdb_view_add_line", {"line": line, "doScroll": self.doScroll})
项目:SublimeRemoteGDB    作者:summerwinter    | 项目源码 | 文件源码
def do_fold_all(self, data):
        self.view.run_command("fold_all")
项目:SublimeRemoteGDB    作者:summerwinter    | 项目源码 | 文件源码
def do_clear(self, data):
        self.view.run_command("gdb_view_clear")
项目:SublimeRemoteGDB    作者:summerwinter    | 项目源码 | 文件源码
def do_scroll(self, data):
        self.view.run_command("goto_line", {"line": data + 1})
项目:SublimeRemoteGDB    作者:summerwinter    | 项目源码 | 文件源码
def run(self):
        global gdb_shutting_down
        gdb_shutting_down = True
        wait_until_stopped()
        run_cmd("-gdb-exit", True)
        # if gdb_server_process:
        #     gdb_server_process.terminate()

        sublime.active_window().run_command("hide_panel", {"cancel": True})
项目:SublimeRemoteGDB    作者:summerwinter    | 项目源码 | 文件源码
def run(self, edit):
        if gdb_variables_view.is_open() and self.view.id() == gdb_variables_view.get_view().id():
            self.view.run_command("gdb_edit_variable")
        else:
            self.view.run_command("gdb_edit_register")
项目:NoDialogs    作者:maximsmol    | 项目源码 | 文件源码
def force_close_view(view):
    view.set_scratch(True)

    win = view.window()
    win.focus_view(view)
    win.run_command('close')
项目:NoDialogs    作者:maximsmol    | 项目源码 | 文件源码
def replace_view_text(view, new_text):
    view.run_command('no_dialogs_replace_helper', {'new_text': new_text})
项目:NoDialogs    作者:maximsmol    | 项目源码 | 文件源码
def run(self, _):
        global next_completion
        next_completion = True

        self.view.run_command(settings.get('no_dialogs_right_arrow_default_command'), settings.get('no_dialogs_right_arrow_default_args'))
项目:NoDialogs    作者:maximsmol    | 项目源码 | 文件源码
def resave(self):
        mkdirp(self.view.file_name())
        self.view.run_command('save')
项目:NoDialogs    作者:maximsmol    | 项目源码 | 文件源码
def reopen_from_new_path(self):
        force_close_view(self.view)
        self.window.open_file(self.path)
        self.window.run_command('hide_panel')
项目:NoDialogs    作者:maximsmol    | 项目源码 | 文件源码
def finish_the_job(self):
        self.view.set_scratch(True)
        self.view.settings().set('save_on_focus_lost', False)

        self.cleanup()
        sublime.run_command('no_dialogs_create_close_window_prompt')
项目:NoDialogs    作者:maximsmol    | 项目源码 | 文件源码
def finish_the_job(self):
        self.view.set_scratch(True)
        self.view.settings().set('save_on_focus_lost', False)

        self.cleanup()
        sublime.run_command('no_dialogs_create_exit_prompt')
项目:NoDialogs    作者:maximsmol    | 项目源码 | 文件源码
def run(self):
        self.alias_window_and_view()

        view_file_name = self.view.file_name()
        if not view_file_name or not os.path.exists(view_file_name):
            sublime.run_command('no_dialogs_create_close_prompt')
            return

        if not settings.get('no_dialogs_delete_without_prompt'):
            self.show_prompt()
        else:
            self.finish_the_job()
项目:a-file-icon    作者:ihodev    | 项目源码 | 文件源码
def _remove():
    try:
        shutil.rmtree(path.get_overlay_aliases())
    except Exception as error:
        log("Error during remove")
        dump(error)
    finally:
        sublime.run_command("refresh_folder_list")
项目:a-file-icon    作者:ihodev    | 项目源码 | 文件源码
def _rename():
    aliases_path = path.get_overlay_aliases()

    try:
        for alias_base in os.listdir(aliases_path):
            alias_path = os.path.join(aliases_path, alias_base)

            if os.path.isfile(alias_path):
                name, ext = os.path.splitext(alias_path)
                os.rename(alias_path, alias_path.replace(".disabled-", "."))
    except Exception as error:
        log("Error during rename")
        dump(error)
    finally:
        sublime.run_command("refresh_folder_list")
项目:a-file-icon    作者:ihodev    | 项目源码 | 文件源码
def run(self):
        log("Cleaning")
        overlay_path = path.get_overlay()
        patches = _get_patches(overlay_path, ".sublime-theme")

        if os.path.exists(overlay_path):
            try:
                for p in patches:
                    os.remove(p)
            except Exception as error:
                log("Error during cleaning")
                dump(error)
            else:
                log("Cleaned up successfully")
                sublime.run_command("afi_patch_themes")
项目:a-file-icon    作者:ihodev    | 项目源码 | 文件源码
def _on_aliases_change():
    log("Aliases settings changed")
    sublime.run_command("afi_check_aliases")
项目:a-file-icon    作者:ihodev    | 项目源码 | 文件源码
def _on_icons_change():
    log("Icons settings changed")
    sublime.run_command("afi_patch_themes", {"overwrite": True})
项目:a-file-icon    作者:ihodev    | 项目源码 | 文件源码
def _on_force_mode_change():
    log("Force mode settings changed")
    sublime.run_command("afi_patch_themes")
项目:MarkdownLivePreview    作者:math2001    | 项目源码 | 文件源码
def on_post_save(self, view):
        if not (os.path.dirname(__file__) in view.file_name() and
            view.file_name().endswith('.py')):
            return
        sublime.run_command('reload_plugin', {
            'main': os.path.join(sublime.packages_path(), 'MarkdownLivePreview',
                                 'MarkdownLivePreview.py'),
            'scripts': ['image_manager', 'functions', 'MLPApi',
                        'setting_names'],
            'folders': ['lib'],
            'quiet': True
        })
项目:MarkdownLivePreview    作者:math2001    | 项目源码 | 文件源码
def run(self):

        """Inspired by the edit_settings command"""

        current_view = sublime.active_window().active_view()
        file_name = current_view.file_name()
        if get_settings().get('keep_open_when_opening_preview') is False:
            current_view.close()
        if file_name is None:
            return sublime.error_message('MarkdownLivePreview: Not supporting '
                                         'unsaved file for now')

        sublime.run_command('new_window')
        self.window = sublime.active_window()
        self.window.settings().set(PREVIEW_WINDOW, True)
        self.window.run_command('set_layout', {
            'cols': [0.0, 0.5, 1.0],
            'rows': [0.0, 1.0],
            'cells': [[0, 0, 1, 1], [1, 0, 2, 1]]
        })
        self.window.focus_group(1)
        preview = create_preview(self.window, current_view)

        self.window.focus_group(0)
        md_view = self.window.open_file(file_name)
        mdsettings = md_view.settings()

        mdsettings.set(PREVIEW_ENABLED, True)
        mdsettings.set(PREVIEW_ID, preview.id())
项目:MarkdownLivePreview    作者:math2001    | 项目源码 | 文件源码
def on_activated_async(self, view):
        vsettings = view.settings()

        if (is_markdown_view(view) and get_settings().get(ON_OPEN)
            and not vsettings.get(PREVIEW_ENABLED)
            and vsettings.get('syntax') != 'Packages/MarkdownLivePreview/' + \
                                           '.sublime/MarkdownLivePreviewSyntax' + \
                                           '.hidden-tmLanguage'
            and not any(filter(lambda window: window.settings().get(PREVIEW_WINDOW) is True,
                               sublime.windows()))):
            sublime.run_command('new_markdown_live_preview')
项目:sublimeTextConfig    作者:luoye-fe    | 项目源码 | 文件源码
def run(self, edit):
        project = get_or_create_project_and_add_view(self.view)
        if project:
            sublime.active_window().run_command('save_all')
            project.reopen_project()
            #project.tsserver.reload(lambda: )


# ################################# SHOW INFOS #################################
项目:sublimeTextConfig    作者:luoye-fe    | 项目源码 | 文件源码
def async_react(self, refs, filename, line, col):
        if refs is None or len(refs) == 0:
            return

        view = sublime.active_window().active_view()
        project = get_or_create_project_and_add_view(view)

        if not project:
            return

        if self.selection_has_changed(filename, line, col):
            return

        Debug('refactor', refs)
        #{'lineText': '        let total = 0;',
        # 'file': '/home/daniel/.config/sublime-text-3/Packages/ArcticTypescript/tests/TDDTesting/main.ts',
        # 'min': {'character': 13,
        #         'line': 43},
        # 'lim': {'character': 18,
        #         'line': 43},
        # 'ref': {'textSpan': {'start': 760,
        #                      'length': 5},
        #         'fileName': '/home/daniel/.config/sublime-text-3/Packages/ArcticTypescript/tests/TDDTesting/main.ts',
        #         'isWriteAccess': True}}


        refactor_member = self.get_entire_member_name(refs)
        if not refactor_member:
            return

        Debug('refactor', refactor_member)

        sublime.active_window().show_input_panel(
            'Refactoring %s (found %i times) to:' % (refactor_member, len(refs)),
            refactor_member,
            lambda new_name: sublime.run_command("typescript_apply_refactor",
                {"project":project, "refs":refs, "old_name":refactor_member, "new_name":new_name}), # require edit token
            None, # change
            None) # camcel
            ## TODO: keine Objekte ins run_command -> verweise bze hashes und die refs temporär im project abspeicern
项目:sublimeTextConfig    作者:luoye-fe    | 项目源码 | 文件源码
def run(self, edit_token):
        project = get_or_create_project_and_add_view(self.view)
        if project:
            return # typescript tools dropped support for this
            Debug('structure', 'open view if not already open')
            project.assert_initialisation_finished()

            T3SVIEWS.OUTLINE.enable()
            T3SVIEWS.OUTLINE.bring_to_top(back_to=self.view)

            self.view.run_command('typescript_update_structure', {"force": True})


# ################################# REFRESH OUTLINE ############################
项目:GhostText-for-SublimeText    作者:GhostText    | 项目源码 | 文件源码
def on_message(self, text):
        try:
            request = json.loads(text)
            self._current_view.run_command('replace_content', request)
            self._current_view.window().focus_view(self._current_view)
        except ValueError as e:
            Utils.show_error(e, 'Invalid JSON')
项目:st_package_reviewer    作者:packagecontrol    | 项目源码 | 文件源码
def __init__(self):
        # Again, unsafe
        sublime.run_command()
项目:st_package_reviewer    作者:packagecontrol    | 项目源码 | 文件源码
def __init__(self):
        # This is safe, though
        sublime.run_command()
项目:st-user-package    作者:math2001    | 项目源码 | 文件源码
def on_close(self, view):
        """
        Closes the other settings view when one of the two is closed
        """

        view_settings = view.settings()

        if not view_settings.get('edit_settings_view'):
            return

        window = sublime.active_window()

        sublime.set_timeout(lambda: window.run_command('close_window'), 50)
项目:st-user-package    作者:math2001    | 项目源码 | 文件源码
def on_load(self, view):
        default_contents = view.settings().get('default_contents')
        if not os.path.isfile(view.file_name()) and default_contents:
            view.run_command('insert_snippet', {'contents': default_contents})