예제 #1
0
    def run(self, edit):

        global TRIGGER_CITE

        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 match(OLD_STYLE_CITE_REGEX, line) != None or match(NEW_STYLE_CITE_REGEX, line) != None or \
            match(OLD_STYLE_REF_REGEX, line) != None or match(NEW_STYLE_REF_REGEX, line) != None:

            view.run_command('latex_ref_cite')

        # if \input, \include or \includegraphics
        if TEX_INPUT_FILE_REGEX.match(line) != None:

            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")
예제 #2
0
    def run(self, edit):

        global TRIGGER_CITE
        
        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 match(OLD_STYLE_CITE_REGEX, line) != None or match(NEW_STYLE_CITE_REGEX, line) != None or \
            match(OLD_STYLE_REF_REGEX, line) != None or match(NEW_STYLE_REF_REGEX, line) != None:

            view.run_command('latex_ref_cite')

        # if \input, \include or \includegraphics
        if TEX_INPUT_FILE_REGEX.match(line) != None:

            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 on_query_completions(self, view, prefix, locations):
        # settings = sublime.load_settings("LaTeXTools.sublime-settings")
        # cwl_completion = settings.get('cwl_completion')

        if not CWL_COMPLETION:
            return []

        point = locations[0]
        if not view.score_selector(point, "text.tex.latex"):
            return []

        point_before = point - len(prefix)
        char_before = view.substr(get_Region(point_before - 1, point_before))
        if not _ST3:  # convert from unicode (might not be necessary)
            char_before = char_before.encode("utf-8")
        is_prefixed = char_before == "\\"

        completion_level = "prefixed"  # default completion level is "prefixed"
        try:
            settings = sublime.load_settings("LaTeXTools.sublime-settings")
            completion_level = settings.get("command_completion", completion_level)
        except:  # LaTeXTools settings are missing
            pass
        do_complete = {"never": False, "prefixed": is_prefixed, "always": True}.get(completion_level, is_prefixed)
        if not do_complete:
            return []

        line = view.substr(get_Region(view.line(point).a, point))
        line = line[::-1]

        # Do not do completions in actions
        for rex in ENV_DONOT_AUTO_COM:
            if match(rex, line) != None:
                return []

        completions = parse_cwl_file()
        # autocompleting with slash already on line
        # this is necessary to work around a short-coming in ST where having a keyed entry
        # appears to interfere with it recognising that there is a \ already on the line
        #
        # NB this may not work if there are other punctuation marks in the completion
        if is_prefixed:
            completions = [(c[0], c[1][1:]) if _is_snippet(c) else c for c in completions]
        return (completions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
예제 #4
0
    def on_query_completions(self, view, prefix, locations):
        
        # settings = sublime.load_settings("LaTeXTools.sublime-settings")
        # cwl_completion = settings.get('cwl_completion')

        if CWL_COMPLETION == False:
            return []

        point = locations[0]
        if not view.score_selector(point, "text.tex.latex"):
            return []

        point = locations[0]
        line = view.substr(get_Region(view.line(point).a, point))
        line = line[::-1]

        # Do not do completions in actions
        for rex in ENV_DONOT_AUTO_COM:
            if match(rex, line) != None:
                return []

        completions = parse_cwl_file()
        return (completions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
예제 #5
0
    def on_query_completions(self, view, prefix, locations):
        # settings = sublime.load_settings("LaTeXTools.sublime-settings")
        # cwl_completion = settings.get('cwl_completion')

        if not CWL_COMPLETION:
            return []

        point = locations[0]
        if not view.score_selector(point, "text.tex.latex"):
            return []

        point = locations[0]
        line = view.substr(get_Region(view.line(point).a, point))
        line = line[::-1]

        # Do not do completions in actions
        for rex in ENV_DONOT_AUTO_COM:
            if match(rex, line) != None:
                return []

        completions = parse_cwl_file()
        # autocompleting with slash already on line
        # this is necessary to work around a short-coming in ST where having a keyed entry
        # appears to interfere with it recognising that there is a \ already on the line
        #
        # NB this may not work if there are other punctuation marks in the completion
        # since these are rare in TeX, this is probably ok
        if len(line) > 0 and line[0] == '\\':
            _completions = []
            for completion in completions:
                _completion = completion[1]
                if  _completion[0] == '\\' and '${1:' in _completion:
                    completion = (completion[0], _completion[1:])
                _completions.append(completion)
        else:
            _completions = completions
        return (_completions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
예제 #6
0
    def on_query_completions(self, view, prefix, locations):

        # settings = sublime.load_settings("LaTeXTools.sublime-settings")
        # cwl_completion = settings.get('cwl_completion')

        if CWL_COMPLETION == False:
            return []

        point = locations[0]
        if not view.score_selector(point, "text.tex.latex"):
            return []

        point = locations[0]
        line = view.substr(get_Region(view.line(point).a, point))
        line = line[::-1]

        # Do not do completions in actions
        for rex in ENV_DONOT_AUTO_COM:
            if match(rex, line) != None:
                return []

        completions = parse_cwl_file()
        return (completions, sublime.INHIBIT_WORD_COMPLETIONS
                | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
예제 #7
0
    def on_query_completions(self, view, prefix, locations):
        if not CWL_COMPLETION:
            return []

        point = locations[0]
        if not view.score_selector(point, "text.tex.latex"):
            return []

        point_before = point - len(prefix)
        char_before = view.substr(get_Region(point_before - 1, point_before))
        if not _ST3:  # convert from unicode (might not be necessary)
            char_before = char_before.encode("utf-8")
        is_prefixed = char_before == "\\"

        line = view.substr(get_Region(view.line(point).begin(), point))
        line = line[::-1]
        is_env = bool(BEGIN_END_BEFORE_REGEX.match(line))

        completion_level = "prefixed"  # default completion level is "prefixed"
        completion_level = get_setting("command_completion", completion_level)

        do_complete = {
            "never": False,
            "prefixed": is_prefixed or is_env,
            "always": True
        }.get(completion_level, is_prefixed or is_env)

        if not do_complete:
            return []

        # if it is inside the begin oder end of an env,
        # create and return the available environments
        if is_env:
            completions = parse_cwl_file(parse_line_as_environment)
            return completions

        # do not autocomplete if the leading backslash is escaped
        if ESCAPE_REGEX.match(line):
            # if there the autocompletion has been opened with the \ trigger
            # (no prefix) and the user has not enabled auto completion for the
            # scope, then hide the auto complete popup
            selector = view.settings().get("auto_complete_selector")
            if not prefix and not view.score_selector(point, selector):
                view.run_command("hide_auto_complete")
            return []

        # Do not do completions in actions
        for rex in ENV_DONOT_AUTO_COM:
            if match(rex, line) != None:
                return []

        completions = parse_cwl_file(parse_line_as_command)
        # autocompleting with slash already on line
        # this is necessary to work around a short-coming in ST where having a keyed entry
        # appears to interfere with it recognising that there is a \ already on the line
        #
        # NB this may not work if there are other punctuation marks in the completion
        if is_prefixed:
            completions = [(c[0], c[1][1:]) if _is_snippet(c) else c
                           for c in completions]
        return (completions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
    def on_query_completions(self, view, prefix, locations):
        if not is_cwl_available():
            return []

        point = locations[0]
        if not view.score_selector(point, "text.tex.latex"):
            return []

        point_before = point - len(prefix)
        char_before = view.substr(getRegion(point_before - 1, point_before))
        is_prefixed = char_before == "\\"

        line = view.substr(getRegion(view.line(point).begin(), point))
        line = line[::-1]
        is_env = bool(BEGIN_END_BEFORE_REGEX.match(line))

        # default completion level is "prefixed"
        completion_level = get_setting(
            "command_completion", "prefixed"
        )

        do_complete = {
            "never": False,
            "prefixed": is_prefixed or is_env,
            "always": True
        }.get(completion_level, is_prefixed or is_env)

        if not do_complete:
            return []

        # do not autocomplete if the leading backslash is escaped
        if ESCAPE_REGEX.match(line):
            # if there the autocompletion has been opened with the \ trigger
            # (no prefix) and the user has not enabled auto completion for the
            # scope, then hide the auto complete popup
            selector = view.settings().get("auto_complete_selector")
            if not prefix and not view.score_selector(point, selector):
                view.run_command("hide_auto_complete")
            return []

        # Do not do completions in actions
        if (
            latex_input_completions.TEX_INPUT_FILE_REGEX not in
            ENV_DONOT_AUTO_COM
        ):
            ENV_DONOT_AUTO_COM.append(
                latex_input_completions.TEX_INPUT_FILE_REGEX)

        for rex in ENV_DONOT_AUTO_COM:
            if match(rex, line) is not None:
                return []

        # load the completions for the document
        if is_env:
            completions = CWL_COMPLETIONS.get_completions(env=True) + \
                get_own_env_completion(view)
        else:
            completions = CWL_COMPLETIONS.get_completions() + \
                get_own_command_completion(view)

        # autocompleting with slash already on line
        # this is necessary to work around a short-coming in ST where having a
        # keyed entry appears to interfere with it recognising that there is a
        # \ already on the line
        #
        # NB this may not work if there are other punctuation marks in the
        # completion
        if is_prefixed:
            completions = [
                (c[0], c[1][1:]) if c[1].startswith("\\") else c
                for c in completions
            ]

        return (
            completions,
            sublime.INHIBIT_WORD_COMPLETIONS |
            sublime.INHIBIT_EXPLICIT_COMPLETIONS
        )
    def on_query_completions(self, view, prefix, locations):
        if not is_cwl_available():
            return []

        point = locations[0]
        if not view.score_selector(point, "text.tex.latex"):
            return []

        point_before = point - len(prefix)
        char_before = view.substr(getRegion(point_before - 1, point_before))
        is_prefixed = char_before == "\\"

        line = view.substr(getRegion(view.line(point).begin(), point))
        line = line[::-1]
        is_env = bool(BEGIN_END_BEFORE_REGEX.match(line))

        # default completion level is "prefixed"
        completion_level = get_setting("command_completion", "prefixed")

        do_complete = {
            "never": False,
            "prefixed": is_prefixed or is_env,
            "always": True
        }.get(completion_level, is_prefixed or is_env)

        if not do_complete:
            return []

        # do not autocomplete if the leading backslash is escaped
        if ESCAPE_REGEX.match(line):
            # if there the autocompletion has been opened with the \ trigger
            # (no prefix) and the user has not enabled auto completion for the
            # scope, then hide the auto complete popup
            selector = view.settings().get("auto_complete_selector")
            if not prefix and not view.score_selector(point, selector):
                view.run_command("hide_auto_complete")
            return []

        # Do not do completions in actions
        if (latex_input_completions.TEX_INPUT_FILE_REGEX
                not in ENV_DONOT_AUTO_COM):
            ENV_DONOT_AUTO_COM.append(
                latex_input_completions.TEX_INPUT_FILE_REGEX)

        for rex in ENV_DONOT_AUTO_COM:
            if match(rex, line) is not None:
                return []

        # load the completions for the document
        if is_env:
            completions = CWL_COMPLETIONS.get_completions(env=True) + \
                get_own_env_completion(view)
        else:
            completions = CWL_COMPLETIONS.get_completions() + \
                get_own_command_completion(view)

        # autocompleting with slash already on line
        # this is necessary to work around a short-coming in ST where having a
        # keyed entry appears to interfere with it recognising that there is a
        # \ already on the line
        #
        # NB this may not work if there are other punctuation marks in the
        # completion
        if is_prefixed:
            completions = [(c[0], c[1][1:]) if c[1].startswith("\\") else c
                           for c in completions]

        return (completions, sublime.INHIBIT_WORD_COMPLETIONS
                | sublime.INHIBIT_EXPLICIT_COMPLETIONS)