Exemple #1
0
    def on_post_save_async(self, view):
        if not view.score_selector(0, 'text.tex.latex'):
            return

        tex_root = get_tex_root(view)
        if tex_root is None:
            return

        _id = view.id()
        if _id not in self._TEX_CACHES:
            local_cache = self._TEX_CACHES[_id] = LocalCache(tex_root)
        else:
            local_cache = self._TEX_CACHES[_id]

        on_save = get_setting('cache_on_save', {})

        if on_save.get('analysis', True):
            # ensure the cache of bib_files is rebuilt on demand
            local_cache.invalidate('bib_files')
            self.run_analysis(tex_root)

        if on_save.get('bibliography', False):
            self.run_bib_cache(tex_root)

        self.run_cache_update()
def get_root(view_or_root):
    if isinstance(view_or_root, sublime.View):
        # here we can still handle root being None if the output_directory
        # setting is an aboslute path
        return get_tex_root(view_or_root)
    else:
        return view_or_root
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
def get_root(view_or_root):
    if isinstance(view_or_root, sublime.View):
        # here we can still handle root being None if the output_directory
        # setting is an aboslute path
        return get_tex_root(view_or_root)
    else:
        return view_or_root
    def on_post_save_async(self, view):
        if not view.score_selector(0, 'text.tex.latex'):
            return

        on_save = get_setting('cache_on_save', {}, view=view)
        if not on_save or not any(on_save.values()):
            return

        tex_root = get_tex_root(view)
        if tex_root is None:
            return

        _id = view.id()
        if _id not in self._TEX_CACHES:
            local_cache = self._TEX_CACHES[_id] = LocalCache(tex_root)
        else:
            local_cache = self._TEX_CACHES[_id]

        if on_save.get('analysis', False):
            # ensure the cache of bib_files is rebuilt on demand
            local_cache.invalidate('bib_files')
            self.run_analysis(tex_root)

        if on_save.get('bibliography', False):
            self.run_bib_cache(tex_root)

        self.run_cache_update()
Exemple #7
0
    def run(self, edit):
        if not self.view.score_selector(0, 'text.tex.latex'):
            return

        tex_root = get_tex_root(self.view)
        if tex_root is None:
            return

        self.run_bib_cache(tex_root)
        self.run_cache_update()
    def run(self, edit):
        if not self.view.score_selector(0, 'text.tex.latex'):
            return

        tex_root = get_tex_root(self.view)
        if tex_root is None:
            return

        self.run_bib_cache(tex_root)
        self.run_cache_update()
Exemple #9
0
    def on_load_async(self, view):
        if not view.score_selector(0, 'text.tex.latex'):
            return
        on_load = get_setting('cache_on_load', {}, view=view)
        if not on_load or not any(on_load.values()):
            return

        tex_root = get_tex_root(view)
        if tex_root is None:
            return

        self._TEX_CACHES[view.id()] = local_cache = LocalCache(tex_root)
        self._TEX_ROOT_REFS[tex_root] += 1

        # because cache state is shared amongst all documents sharing a tex
        # root, this ensure we only load the analysis ONCE in the on_load
        # event
        if (
            not local_cache.has('analysis') and
            on_load.get('analysis', False)
        ):
            self.run_analysis(tex_root)

        if tex_root not in self._BIB_CACHES:
            if on_load.get('bibliography', False):
                self.run_bib_cache(tex_root)

            self._BIB_CACHES[tex_root] = bib_caches = []

            LocalCache(tex_root).invalidate('bib_files')
            bib_files = find_bib_files(tex_root)

            plugins = get_setting(
                'bibliography_plugins', ['traditional'], view=view)
            if not isinstance(plugins, list):
                plugins = [plugins]

            if 'new' in plugins or 'new_bibliography' in plugins:
                for bib_file in bib_files:
                    bib_caches.append(BibCache('new', bib_file))

            if (
                'traditional' in plugins or
                'traditional_bibliography' in plugins
            ):
                for bib_file in bib_files:
                    bib_caches.append(BibCache('trad', bib_file))

        self.run_cache_update()
Exemple #10
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
    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
Exemple #12
0
def analyze_document(tex_root):
    """
    Analyzes the document

    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 = _analyze_tex_file(tex_root)
    return result
Exemple #13
0
def analyze_document(tex_root):
    """
    Analyzes the document

    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 = _analyze_tex_file(tex_root)
    return result