def run(self, edit):
        view = self.view
        point = view.sel()[0].b

        # Current lines, used to detemine whether is input, include, cite, or includegraphics
        line = view.substr(get_Region(view.line(point).a, point))[::-1]

        # if \cite or \ref
        if (OLD_STYLE_CITE_REGEX.match(line)
                or NEW_STYLE_CITE_REGEX.match(line)
                or OLD_STYLE_REF_REGEX.match(line)
                or NEW_STYLE_REF_REGEX.match(line)):
            view.run_command('latex_ref_cite')

        # if \input, \include or \includegraphics
        if TEX_INPUT_FILE_REGEX.match(line):
            prefix, suffix, nc_current_word = get_current_word(view, point)
            current_word = prefix + suffix
            if current_word != '':
                startpoint = point - len(prefix)
                endpoint = point + len(suffix)
                view.run_command('latex_tools_replace', {
                    'a': startpoint,
                    'b': endpoint,
                    'replacement': ''
                })
                view.run_command('latex_fill_input')
            else:
                view.run_command("latex_fill_input")
    def run(self, edit):
        view = self.view
        point = view.sel()[0].b

        # Current lines, used to detemine whether is input, include, cite, or includegraphics
        line = view.substr(get_Region(view.line(point).a, point))[::-1]

        # if \cite or \ref
        if (
            OLD_STYLE_CITE_REGEX.match(line)
            or NEW_STYLE_CITE_REGEX.match(line)
            or OLD_STYLE_REF_REGEX.match(line)
            or NEW_STYLE_REF_REGEX.match(line)
        ):
            view.run_command("latex_ref_cite")

        # if \input, \include or \includegraphics
        if TEX_INPUT_FILE_REGEX.match(line):
            prefix, suffix, nc_current_word = get_current_word(view, point)
            current_word = prefix + suffix
            if current_word != "":
                startpoint = point - len(prefix)
                endpoint = point + len(suffix)
                view.run_command("latex_tools_replace", {"a": startpoint, "b": endpoint, "replacement": ""})
                view.run_command("latex_fill_input")
            else:
                view.run_command("latex_fill_input")

        if BEGIN_END_BEFORE_REGEX.match(line):
            view.run_command("latex_fill_env")
    def run(self, edit):
        view = self.view
        point = view.sel()[0].b

        # Current lines, used to detemine whether is input, include, cite, or includegraphics
        line = view.substr(get_Region(view.line(point).a, point))[::-1]

        # if \cite or \ref
        if (OLD_STYLE_CITE_REGEX.match(line) or
            NEW_STYLE_CITE_REGEX.match(line) or
            OLD_STYLE_REF_REGEX.match(line)  or
            NEW_STYLE_REF_REGEX.match(line)):
                view.run_command('latex_ref_cite')
        # if \begin or \end
        elif BEGIN_END_BEFORE_REGEX.match(line):
            view.run_command("latex_fill_env")
        # input completions
        else:
            _, dyn_regex = _get_dyn_entries()
            if (
                TEX_INPUT_FILE_REGEX.match(line) or
                (dyn_regex and dyn_regex.match(line))
            ):
                prefix, suffix, nc_current_word = get_current_word(view, point)
                current_word = prefix + suffix
                if current_word != '':
                    startpoint = point - len(prefix)
                    endpoint = point + len(suffix)
                    view.run_command(
                        'latex_tools_replace',
                        {'a': startpoint, 'b': endpoint, 'replacement': ''}
                    )
                    view.run_command('latex_fill_input')
                else:
                    view.run_command("latex_fill_input")
    def run(self, edit):
        view = self.view
        if len(view.sel()) != 1:
            print("Jump to anywhere does not work with multiple cursors")
            return
        sel = view.sel()[0]
        line_r = view.line(sel)
        line = view.substr(line_r)

        def is_inside(g):
            """check whether the selection is inside the command"""
            if g is None:
                return False
            b = line_r.begin()
            # the region, which should contain the selection
            reg = g.regs[0]
            return reg[0] <= sel.begin() - b and sel.end() - b <= reg[1]

        try:
            com_reg = next(ifilter(is_inside, COMMAND_REG.finditer(line)))
        except:
            print("Cursor is not inside a command")
            return
        command = com_reg.group("command")
        args = com_reg.group("args")
        reversed_command = "{" + command[::-1] + "\\"
        # the cursor position inside the command
        pos = view.sel()[0].b - line_r.begin() - com_reg.start()
        # check if its a ref
        if NEW_STYLE_REF_REGEX.match(reversed_command):
            sublime.status_message("Jump to reference '{0}'".format(args))
            _jumpto_ref(view, com_reg, pos)
        # check if it is a cite
        elif NEW_STYLE_CITE_REGEX.match(reversed_command):
            sublime.status_message("Jump to citation '{0}'".format(args))
            _jumpto_cite(view, com_reg, pos)
        # check if it is any kind of input command
        elif any(reg.match(com_reg.group(0)) for reg in INPUT_REG_EXPS):
            args = {
                "auto_create_missing_folders": False,
                "auto_insert_root": False
            }
            view.run_command("jumpto_tex_file", args)
        elif command in ["usepackage", "Requirepackage"]:
            _jumpto_pkg_doc(view, com_reg, pos)
        else:
            # if the cursor is inside the \command part, try jump to
            # self defined commands
            b = line_r.begin()
            command_region = com_reg.regs[COMMAND_REG.groupindex["command"]]
            # if cursor is inside \command
            if (command_region[0] + b - 1 <= sel.begin()
                    and sel.end() <= command_region[1] + b):
                _opt_jumpto_self_def_command(view, com_reg)
 def is_correct_ref(c):
     command = ("\\" + c.command + "{")[::-1]
     return NEW_STYLE_REF_REGEX.match(command) and c.args == args
    def run(self, edit, position=None):
        view = self.view
        if position is None:
            if len(view.sel()) != 1:
                print("Jump to anywhere does not work with multiple cursors")
                return
            sel = view.sel()[0]
        else:
            sel = sublime.Region(position, position)
        line_r = view.line(sel)
        line = view.substr(line_r)

        def is_inside(g):
            """check whether the selection is inside the command"""
            if g is None:
                return False
            b = line_r.begin()
            # the region, which should contain the selection
            reg = g.regs[0]
            return reg[0] <= sel.begin() - b and sel.end() - b <= reg[1]

        try:
            com_reg = next(ifilter(is_inside, COMMAND_REG.finditer(line)))
        except:
            # since the magic comment will not match the command, do this here
            if view.file_name():
                m = TEX_DIRECTIVE.search(line)
                if (m and m.group(1) == 'root'
                        and m.start() <= sel.begin() - line_r.begin()
                        and sel.end() - line_r.begin() <= m.end()):
                    _jumpto_tex_root(view, m.group(2))
                    return

            print("Cursor is not inside a command")
            return

        command = com_reg.group("command")
        args = com_reg.group("args")
        reversed_command = "{" + command[::-1] + "\\"
        # the cursor position inside the command
        pos = sel.b - line_r.begin() - com_reg.start()
        # check if its a ref
        if NEW_STYLE_REF_REGEX.match(reversed_command):
            sublime.status_message("Jump to reference '{0}'".format(args))
            _jumpto_ref(view, com_reg, pos)
        # check if it is a cite
        elif NEW_STYLE_CITE_REGEX.match(reversed_command):
            sublime.status_message("Jump to citation '{0}'".format(args))
            _jumpto_cite(view, com_reg, pos)
        elif command == "label":
            _show_usage_label(view, args)
        elif GLO_LINE_RE.match(reversed_command):
            sublime.status_message("Jump to glossary '{0}'".format(args))
            _jumpto_glo(view, com_reg, pos)
        elif ACR_LINE_RE.match(reversed_command):
            sublime.status_message("Jump to acronym '{0}'".format(args))
            _jumpto_glo(view, com_reg, pos, acr=True)
        # check if it is any kind of input command
        elif any(reg.match(com_reg.group(0)) for reg in INPUT_REG_EXPS):
            kwargs = {
                "auto_create_missing_folders": False,
                "auto_insert_root": False
            }
            if pos is not None:
                kwargs.update({"position": position})
            view.run_command("jumpto_tex_file", kwargs)
        elif command in ["usepackage", "Requirepackage"]:
            _jumpto_pkg_doc(view, com_reg, pos)
        else:
            # if the cursor is inside the \command part, try jump to
            # self defined commands
            b = line_r.begin()
            command_region = com_reg.regs[COMMAND_REG.groupindex["command"]]
            # if cursor is inside \command
            if (command_region[0] + b - 1 <= sel.begin()
                    and sel.end() <= command_region[1] + b):
                _opt_jumpto_self_def_command(view, com_reg)
 def is_correct_ref(c):
     command = ("\\" + c.command + "{")[::-1]
     return NEW_STYLE_REF_REGEX.match(command) and c.args == args
    def run(self, edit, position=None):
        view = self.view
        if position is None:
            if len(view.sel()) != 1:
                print("Jump to anywhere does not work with multiple cursors")
                return
            sel = view.sel()[0]
        else:
            sel = sublime.Region(position, position)
        line_r = view.line(sel)
        line = view.substr(line_r)

        def is_inside(g):
            """check whether the selection is inside the command"""
            if g is None:
                return False
            b = line_r.begin()
            # the region, which should contain the selection
            reg = g.regs[0]
            return reg[0] <= sel.begin() - b and sel.end() - b <= reg[1]

        try:
            com_reg = next(ifilter(is_inside, COMMAND_REG.finditer(line)))
        except:
            # since the magic comment will not match the command, do this here
            if view.file_name():
                m = TEX_DIRECTIVE.search(line)
                if (
                    m and
                    m.group(1) == 'root' and
                    m.start() <= sel.begin() - line_r.begin() and
                    sel.end() - line_r.begin() <= m.end()
                ):
                    _jumpto_tex_root(view, m.group(2))
                    return

            print("Cursor is not inside a command")
            return

        command = com_reg.group("command")
        args = com_reg.group("args")
        reversed_command = "{" + command[::-1] + "\\"
        # the cursor position inside the command
        pos = sel.b - line_r.begin() - com_reg.start()
        # check if its a ref
        if NEW_STYLE_REF_REGEX.match(reversed_command):
            sublime.status_message("Jump to reference '{0}'".format(args))
            _jumpto_ref(view, com_reg, pos)
        # check if it is a cite
        elif NEW_STYLE_CITE_REGEX.match(reversed_command):
            sublime.status_message("Jump to citation '{0}'".format(args))
            _jumpto_cite(view, com_reg, pos)
        elif command == "label":
            _show_usage_label(view, args)
        elif GLO_LINE_RE.match(reversed_command):
            sublime.status_message("Jump to glossary '{0}'".format(args))
            _jumpto_glo(view, com_reg, pos)
        elif ACR_LINE_RE.match(reversed_command):
            sublime.status_message("Jump to acronym '{0}'".format(args))
            _jumpto_glo(view, com_reg, pos, acr=True)
        # check if it is any kind of input command
        elif any(reg.match(com_reg.group(0)) for reg in INPUT_REG_EXPS):
            kwargs = {
                "auto_create_missing_folders": False,
                "auto_insert_root": False
            }
            if pos is not None:
                kwargs.update({"position": position})
            view.run_command("jumpto_tex_file", kwargs)
        elif command in ["usepackage", "Requirepackage"]:
            _jumpto_pkg_doc(view, com_reg, pos)
        else:
            # if the cursor is inside the \command part, try jump to
            # self defined commands
            b = line_r.begin()
            command_region = com_reg.regs[COMMAND_REG.groupindex["command"]]
            # if cursor is inside \command
            if (command_region[0] + b - 1 <= sel.begin() and
                    sel.end() <= command_region[1] + b):
                _opt_jumpto_self_def_command(view, com_reg)