コード例 #1
0
def cwl_parsing_handler(callback):
    completion_results = {}
    environment_results = {}
    cwl_files, use_package = get_cwl_package_files()

    for cwl_file in cwl_files:
        base_name = os.path.basename(cwl_file)
        if use_package:
            try:
                s = (sublime.load_resource(cwl_file).replace("\r\n",
                                                             "\n").replace(
                                                                 "\r", "\n"))
            except IOError:
                print(u'{0} does not exist or could not be accessed'.format(
                    cwl_file))
                continue
        else:
            if not os.path.isabs(cwl_file) and cwl_file.startswith('Package'):
                cwl_file = os.path.normpath(
                    cwl_file.replace('Package', sublime.packages_path()))

            try:
                s = utils.read_file_unix_endings(cwl_file)
            except IOError:
                print(u'{0} does not exist or could not be accessed'.format(
                    cwl_file))
                continue

        completions = parse_cwl_file(base_name, s)
        completion_results[base_name] = completions

        environments = parse_cwl_file(base_name, s, parse_line_as_environment)
        environment_results[base_name] = environments

    callback(completion_results, environment_results)
コード例 #2
0
def cwl_parsing_handler(callback):
    completion_results = {}
    environment_results = {}
    cwl_files, use_package = get_cwl_package_files()

    for cwl_file in cwl_files:
        base_name = os.path.basename(cwl_file)
        if use_package:
            try:
                s = (sublime.load_resource(cwl_file).replace("\r\n", "\n")
                     .replace("\r", "\n"))
            except IOError:
                print(
                    u'{0} does not exist or could not be accessed'.format(
                        cwl_file
                    )
                )
                continue
        else:
            if not os.path.isabs(cwl_file) and cwl_file.startswith('Package'):
                cwl_file = os.path.normpath(
                    cwl_file.replace('Package', sublime.packages_path())
                )

            try:
                s = utils.read_file_unix_endings(cwl_file)
            except IOError:
                print(
                    u'{0} does not exist or could not be accessed'.format(
                        cwl_file
                    )
                )
                continue

        completions = parse_cwl_file(base_name, s)
        completion_results[base_name] = completions

        environments = parse_cwl_file(base_name, s, parse_line_as_environment)
        environment_results[base_name] = environments

    callback(completion_results, environment_results)
コード例 #3
0
def _jumpto_cite(view, com_reg, pos):
    tex_root = get_tex_root(view)
    bib_key = _get_selected_arg(view, com_reg, pos)
    if tex_root is None or not bib_key:
        return
    message = "Scanning bibliography files for key '{0}'...".format(bib_key)
    print(message)
    sublime.status_message(message)
    base_dir = os.path.dirname(tex_root)
    ana = analysis.get_analysis(tex_root)

    bib_commands = ana.filter_commands(
        ["bibliography", "nobibliography", "addbibresource"])
    for bib_command in bib_commands:
        for bib_file in jumpto_tex_file._split_bib_args(bib_command.args):
            if not os.path.splitext(bib_file)[1]:
                bib_file += ".bib"
            bib_file = os.path.join(base_dir, bib_file)
            try:
                file_content = utils.read_file_unix_endings(bib_file)
                start = file_content.find(bib_key)
                end = start + len(bib_key)
                # check that we found the entry and we are not inside a word
                if (start == -1 or file_content[start - 1:start].isalnum()
                        or file_content[end:end + 1].isalnum()):
                    continue
                region = sublime.Region(start, end)
                message = "Jumping to bibliography key '{0}'.".format(bib_key)
                print(message)
                sublime.status_message(message)
                utils.open_and_select_region(view, bib_file, region)
                return
            except Exception as e:
                print("Error occurred opening file {0}".format(bib_file))
                print(e)
                continue
    message = "Entry '{0}' not found in bibliography.".format(bib_key)
    print(message)
    sublime.status_message(message)
コード例 #4
0
ファイル: jumpto_anywhere.py プロジェクト: r-stein/LaTeXTools
def _jumpto_cite(view, com_reg, pos):
    tex_root = get_tex_root(view)
    bib_key = _get_selected_arg(view, com_reg, pos)
    if tex_root is None or not bib_key:
        return
    message = "Scanning bibliography files for key '{0}'...".format(bib_key)
    print(message)
    sublime.status_message(message)
    base_dir = os.path.dirname(tex_root)
    ana = analysis.get_analysis(tex_root)

    bib_commands = ana.filter_commands(
        ["bibliography", "nobibliography", "addbibresource"])
    for bib_command in bib_commands:
        for bib_file in jumpto_tex_file._split_bib_args(bib_command.args):
            if not os.path.splitext(bib_file)[1]:
                bib_file += ".bib"
            bib_file = os.path.join(base_dir, bib_file)
            try:
                file_content = utils.read_file_unix_endings(bib_file)
                start = file_content.find(bib_key)
                end = start + len(bib_key)
                # check that we found the entry and we are not inside a word
                if (start == -1 or file_content[start - 1:start].isalnum() or
                        file_content[end:end + 1].isalnum()):
                    continue
                region = sublime.Region(start, end)
                message = "Jumping to bibliography key '{0}'.".format(bib_key)
                print(message)
                sublime.status_message(message)
                utils.open_and_select_region(view, bib_file, region)
                return
            except Exception as e:
                print("Error occurred opening file {0}".format(bib_file))
                print(e)
                continue
    message = "Entry '{0}' not found in bibliography.".format(bib_key)
    print(message)
    sublime.status_message(message)