Ejemplo n.º 1
0
def _jumpto_ref(view, com_reg, pos):
    label_id = _get_selected_arg(view, com_reg, pos)
    if not label_id:
        return
    sublime.status_message(
        "Scanning document for label '{0}'...".format(label_id))
    tex_root = get_tex_root(view)
    ana = analysis.analyze_document(tex_root)
    if ana is None:
        return

    def is_correct_label(c):
        return c.command == "label" and c.args == label_id
    labels = ana.filter_commands(is_correct_label)
    try:
        label = labels[0]
    except:
        message = "No matching label found for '{0}'.".format(label_id)
        print(message)
        sublime.status_message(message)
        return
    label_region = label.region
    message = "Jumping to label '{0}'.".format(label_id)
    print(message)
    sublime.status_message(message)
    utils.open_and_select_region(view, label.file_name, label_region)
Ejemplo n.º 2
0
def _jumpto_ref(view, com_reg, pos):
    label_id = _get_selected_arg(view, com_reg, pos)
    if not label_id:
        return
    sublime.status_message(
        "Scanning document for label '{0}'...".format(label_id))
    tex_root = get_tex_root(view)
    ana = analysis.analyze_document(tex_root)
    if ana is None:
        return

    def is_correct_label(c):
        return c.command == "label" and c.args == label_id

    labels = ana.filter_commands(is_correct_label)
    try:
        label = labels[0]
    except:
        message = "No matching label found for '{0}'.".format(label_id)
        print(message)
        sublime.status_message(message)
        return
    label_region = label.region
    message = "Jumping to label '{0}'.".format(label_id)
    print(message)
    sublime.status_message(message)
    utils.open_and_select_region(view, label.file_name, label_region)
Ejemplo n.º 3
0
    def run(self):
        view = self.window.active_view()
        tex_root = get_tex_root(view)
        if not tex_root:
            return
        ana = analysis.analyze_document(tex_root)

        show_toc_quickpanel(ana)
Ejemplo n.º 4
0
    def run(self):
        view = self.window.active_view()
        tex_root = get_tex_root(view)
        if not tex_root:
            return
        ana = analysis.analyze_document(tex_root)

        show_toc_quickpanel(ana)
Ejemplo n.º 5
0
    def run(self, only_current_file=False):
        view = self.window.active_view()
        tex_root = get_tex_root(view)
        if not tex_root:
            return
        ana = analysis.analyze_document(tex_root)

        only_file = None if not only_current_file else view.file_name()
        show_toc_quickpanel(ana, only_file=only_file)
Ejemplo n.º 6
0
    def run(self, only_current_file=False):
        view = self.window.active_view()
        tex_root = get_tex_root(view)
        if not tex_root:
            return
        ana = analysis.analyze_document(tex_root)

        only_file = None if not only_current_file else view.file_name()
        show_toc_quickpanel(ana, only_file=only_file)
Ejemplo n.º 7
0
    def run(self, commands):
        window = self.window
        view = window.active_view()
        tex_root = get_tex_root(view)

        ana = analysis.analyze_document(tex_root)
        entries = ana.filter_commands(commands, flags=analysis.ALL_COMMANDS)

        captions = [_make_caption(ana, e) for e in entries]
        quickpanel.show_quickpanel(captions, entries)
Ejemplo n.º 8
0
    def run(self, commands):
        window = self.window
        view = window.active_view()
        tex_root = get_tex_root(view)

        ana = analysis.analyze_document(tex_root)
        entries = ana.filter_commands(commands, flags=analysis.ALL_COMMANDS)

        captions = [_make_caption(ana, e) for e in entries]
        quickpanel.show_quickpanel(captions, entries)
Ejemplo n.º 9
0
    def run(self, commands, only_current_file=False):
        window = self.window
        view = window.active_view()
        tex_root = get_tex_root(view)

        ana = analysis.analyze_document(tex_root)
        entries = ana.filter_commands(commands, flags=analysis.ALL_COMMANDS)

        if only_current_file:
            file_name = view.file_name()
            entries = [e for e in entries if e.file_name == file_name]

        captions = [_make_caption(ana, e) for e in entries]
        quickpanel.show_quickpanel(captions, entries)
Ejemplo n.º 10
0
    def run(self, commands, only_current_file=False):
        window = self.window
        view = window.active_view()
        tex_root = get_tex_root(view)

        ana = analysis.analyze_document(tex_root)
        entries = ana.filter_commands(commands, flags=analysis.ALL_COMMANDS)

        if only_current_file:
            file_name = view.file_name()
            entries = [e for e in entries if e.file_name == file_name]

        captions = [_make_caption(ana, e) for e in entries]
        quickpanel.show_quickpanel(captions, entries)
Ejemplo n.º 11
0
def _opt_jumpto_self_def_command(view, com_reg):
    tex_root = get_tex_root(view)
    if tex_root is None:
        return False

    # check in the cache whether we should jump (is command self defined)
    newcommand_keywords = ["newcommand", "renewcommand"]
    command = "\\" + com_reg.group("command")
    cana = analysis.get_analysis(tex_root)
    new_commands = cana.filter_commands(newcommand_keywords)
    if command not in [c.args for c in new_commands]:
        message = "Command not defined (cached) '{0}'".format(command)
        print(message)
        return False

    message =\
        "Scanning document for command definition of '{0}'".format(command)
    print(message)
    sublime.status_message(message)
    # analyze the document to retrieve the correct position of the
    # command definition
    ana = analysis.analyze_document(tex_root)
    new_commands = ana.filter_commands(newcommand_keywords)
    try:
        new_com_def = next(ifilter(lambda c: c.args == command,
                                   new_commands))
    except:
        message = "Command not self defined '{0}'".format(command)
        print(message)
        return False
    file_name = new_com_def.file_name
    region = new_com_def.args_region

    message = "Jumping to definition of '{0}'".format(command)
    print(message)
    sublime.status_message(message)
    utils.open_and_select_region(view, file_name, region)
    return True
Ejemplo n.º 12
0
def _opt_jumpto_self_def_command(view, com_reg):
    tex_root = get_tex_root(view)
    if tex_root is None:
        return False

    # check in the cache whether we should jump (is command self defined)
    newcommand_keywords = ["newcommand", "renewcommand"]
    command = "\\" + com_reg.group("command")
    cana = analysis.get_analysis(tex_root)
    new_commands = cana.filter_commands(newcommand_keywords)
    if command not in [c.args for c in new_commands]:
        message = "Command not defined (cached) '{0}'".format(command)
        print(message)
        return False

    message =\
        "Scanning document for command definition of '{0}'".format(command)
    print(message)
    sublime.status_message(message)
    # analyze the document to retrieve the correct position of the
    # command definition
    ana = analysis.analyze_document(tex_root)
    new_commands = ana.filter_commands(newcommand_keywords)
    try:
        new_com_def = next(ifilter(lambda c: c.args == command,
                                   new_commands))
    except:
        message = "Command not self defined '{0}'".format(command)
        print(message)
        return False
    file_name = new_com_def.file_name
    region = new_com_def.args_region

    message = "Jumping to definition of '{0}'".format(command)
    print(message)
    sublime.status_message(message)
    utils.open_and_select_region(view, file_name, region)
    return True
Ejemplo n.º 13
0
def _show_usage_label(view, args):
    tex_root = get_tex_root(view)
    if tex_root is None:
        return False
    ana = analysis.analyze_document(tex_root)

    def is_correct_ref(c):
        command = ("\\" + c.command + "{")[::-1]
        return NEW_STYLE_REF_REGEX.match(command) and c.args == args

    refs = ana.filter_commands(is_correct_ref)

    if len(refs) == 0:
        sublime.error_message("No references for '{0}' found.".format(args))
        return
    elif len(refs) == 1:
        ref = refs[0]
        utils.open_and_select_region(view, ref.file_name, ref.region)
        return

    captions = [ana_utils.create_rel_file_str(ana, r) for r in refs]

    quickpanel.show_quickpanel(captions, refs)
Ejemplo n.º 14
0
def _jumpto_glo(view, com_reg, pos, acr=False):
    tex_root = get_tex_root(view)
    if not tex_root:
        return
    ana = analysis.analyze_document(tex_root)
    if not acr:
        commands = ana.filter_commands(
            ["newglossaryentry", "longnewglossaryentry", "newacronym"])
    else:
        commands = ana.filter_commands("newacronym")

    iden = com_reg.group("args")
    try:
        entry = next(c for c in commands if c.args == iden)
    except:
        message = "Glossary definition not found for '{0}'".format(iden)
        print(message)
        sublime.status_message(message)
        return
    message = "Jumping to Glossary '{0}'.".format(iden)
    print(message)
    sublime.status_message(message)
    utils.open_and_select_region(view, entry.file_name, entry.args_region)
Ejemplo n.º 15
0
def _jumpto_glo(view, com_reg, pos, acr=False):
    tex_root = get_tex_root(view)
    if not tex_root:
        return
    ana = analysis.analyze_document(tex_root)
    if not acr:
        commands = ana.filter_commands(
            ["newglossaryentry", "longnewglossaryentry"])
    else:
        commands = ana.filter_commands("newacronym")

    iden = com_reg.group("args")
    try:
        entry = next(c for c in commands if c.args == iden)
    except:
        message = "Glossary definition not found for '{0}'".format(iden)
        print(message)
        sublime.status_message(message)
        return
    message = "Jumping to Glossary '{0}'.".format(iden)
    print(message)
    sublime.status_message(message)
    utils.open_and_select_region(view, entry.file_name, entry.args_region)
Ejemplo n.º 16
0
def _show_usage_label(view, args):
    tex_root = get_tex_root(view)
    if tex_root is None:
        return False
    ana = analysis.analyze_document(tex_root)

    def is_correct_ref(c):
        command = ("\\" + c.command + "{")[::-1]
        return NEW_STYLE_REF_REGEX.match(command) and c.args == args

    refs = ana.filter_commands(is_correct_ref)

    if len(refs) == 0:
        sublime.error_message("No references for '{0}' found.".format(args))
        return
    elif len(refs) == 1:
        ref = refs[0]
        utils.open_and_select_region(view, ref.file_name, ref.region)
        return

    captions = [ana_utils.create_rel_file_str(ana, r) for r in refs]

    quickpanel.show_quickpanel(captions, refs)
Ejemplo n.º 17
0
 def _run_analysis(self, tex_root):
     LocalCache(tex_root).set(
         'analysis', analysis.analyze_document(tex_root)
     )
 def _run_analysis(self, tex_root):
     LocalCache(tex_root).set(
         'analysis', analysis.analyze_document(tex_root)
     )