コード例 #1
0
ファイル: analysis.py プロジェクト: aleth/LaTeXTools
def get_analysis(tex_root):
    """
    Returns an analysis of the document using a cache

    Use this method if you want a fast result and don't mind if there
    are small changes between the analysis and the usage.
    Don't use this method if you ware looking forward in using
    the regions of the commands (it will most likely not yield proper result)
    (and is currently not supported with st2)

    Arguments:
    tex_root -- the path to the tex root as a string
                if you use the view instead, the tex root will be extracted
                automatically

    Returns:
    An Analysis of the view, which contains all relevant information and
    provides access methods to useful properties
    """
    if tex_root is None:
        return
    elif isinstance(tex_root, sublime.View):
        tex_root = get_tex_root(tex_root)
    elif not isinstance(tex_root, strbase):
        raise ValueError("tex_root must be a string or view")

    result = cache.cache(tex_root, "analysis",
                         lambda: analyze_document(tex_root))
    return result
コード例 #2
0
ファイル: analysis.py プロジェクト: nikhilhassija/st3-config
def get_analysis(tex_root):
    """
    Returns an analysis of the document using a cache

    Use this method if you want a fast result and don't mind if there
    are small changes between the analysis and the usage.
    Don't use this method if you ware looking forward in using
    the regions of the commands (it will most likely not yield proper result)
    (and is currently not supported with st2)

    Arguments:
    tex_root -- the path to the tex root as a string
                if you use the view instead, the tex root will be extracted
                automatically

    Returns:
    An Analysis of the view, which contains all relevant information and
    provides access methods to useful properties
    """
    if tex_root is None:
        return
    elif isinstance(tex_root, sublime.View):
        tex_root = get_tex_root(tex_root)
    elif not isinstance(tex_root, strbase):
        raise ValueError("tex_root must be a string or view")

    result = cache.cache(tex_root, "analysis",
                         lambda: analyze_document(tex_root))
    return result
コード例 #3
0
def get_own_env_completion(view):
    tex_root = get_tex_root(view)
    if not tex_root:
        return []

    def make_completions():
        ana = analysis.get_analysis(tex_root)
        return _make_own_env_completion(ana)

    return cache.cache(tex_root, "own_env_completion", make_completions)
コード例 #4
0
def get_own_env_completion(view):
    tex_root = get_tex_root(view)
    if not tex_root:
        return []

    def make_completions():
        ana = analysis.get_analysis(tex_root)
        return _make_own_env_completion(ana)

    return cache.cache(tex_root, "own_env_completion", make_completions)
コード例 #5
0
    def _get_completions(self, view, prefix, line, comp_type="glo", ac=False):
        tex_root = get_tex_root(view)
        if not tex_root:
            return []

        cache_name = "glocomp_{0}_{1}".format(comp_type, "ac" if ac else "kbd")

        def make_compl():
            ana = analysis.get_analysis(tex_root)
            if comp_type == "glo":
                comp = _get_glo_completions(ana, prefix, ac)
            elif comp_type == "acr":
                comp = _get_acr_completions(ana, prefix, ac)
            else:
                comp = []
            return comp

        comp = cache.cache(tex_root, cache_name, make_compl)
        return comp
コード例 #6
0
def get_own_command_completion(view):
    tex_root = get_tex_root(view)
    if not tex_root:
        return []

    # use special handling (additional completions) for math mode
    math_selector = ("string.other.math.tex, "
                     "string.other.math.latex, "
                     "string.other.math.block.environment.latex")
    is_math = bool(view.score_selector(view.sel()[0].b, math_selector))

    def make_completions():
        ana = analysis.get_analysis(tex_root)
        return _make_own_command_completion(ana, is_math)

    cache_name = "own_command_completion"
    if is_math:
        cache_name += "_math"
    return cache.cache(tex_root, cache_name, make_completions)
コード例 #7
0
    def _get_completions(self, view, prefix, line, comp_type="glo", ac=False):
        tex_root = get_tex_root(view)
        if not tex_root:
            return []

        cache_name = "glocomp_{0}_{1}".format(comp_type, "ac" if ac else "kbd")

        def make_compl():
            ana = analysis.get_analysis(tex_root)
            if comp_type == "glo":
                comp = _get_glo_completions(ana, prefix, ac)
            elif comp_type == "acr":
                comp = _get_acr_completions(ana, prefix, ac)
            else:
                comp = []
            return comp

        comp = cache.cache(tex_root, cache_name, make_compl)
        return comp
コード例 #8
0
def get_own_command_completion(view):
    tex_root = get_tex_root(view)
    if not tex_root:
        return []

    # use special handling (additional completions) for math mode
    math_selector = (
        "string.other.math.tex, "
        "string.other.math.latex, "
        "string.other.math.block.environment.latex"
    )
    is_math = bool(view.score_selector(view.sel()[0].b, math_selector))

    def make_completions():
        ana = analysis.get_analysis(tex_root)
        return _make_own_command_completion(ana, is_math)

    cache_name = "own_command_completion"
    if is_math:
        cache_name += "_math"
    return cache.cache(tex_root, cache_name, make_completions)