def on_query_completions(self, view, prefix, locations): if not is_bib_buffer(view): return [] current_line = get_text_to_cursor(view)[::-1] if current_line.startswith(prefix[::-1]): current_line = current_line[len(prefix):] result = get_completions_if_matches( CROSSREF_REGEX, current_line, get_cite_keys, view) if result: return result if not is_biblatex_buffer(view): return [] return get_completions_if_matches( BIBLATEX_REGEX, current_line, get_cite_keys, view) or \ get_completions_if_matches( XDATA_REGEX, current_line, get_xdata_keys, view) or \ get_completions_if_matches( ENTRY_SET_REGEX, current_line, get_entryset_keys, view) or \ []
def on_query_completions(self, view, prefix, locations): if not is_bib_buffer(view): return [] # do not return completions if the cursor is inside an entry if view.score_selector(view.sel()[0].b, 'meta.entry.braces.bibtex') > 0: return [] if is_biblatex_buffer(view): return (get_biblatex_completions(), sublime.INHIBIT_WORD_COMPLETIONS) else: return (get_bibtex_completions(), sublime.INHIBIT_WORD_COMPLETIONS)
def on_query_completions(self, view, prefix, locations): if not is_bib_buffer(view): return [] current_line = get_text_to_cursor(view)[::-1] if current_line.startswith(prefix[::-1]): current_line = current_line[len(prefix):] matcher = ON_NAME_FIELD_REGEX.match(current_line) if matcher: return ([(name, _get_replacement(matcher, name)) for name in get_names_from_view(view) ], sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS) return []
def on_query_completions(self, view, prefix, locations): if not is_bib_buffer(view): return [] current_line = get_text_to_cursor(view)[::-1] if current_line.startswith(prefix[::-1]): current_line = current_line[len(prefix):] matcher = ON_NAME_FIELD_REGEX.match(current_line) if matcher: return ([ (name, _get_replacement(matcher, name)) for name in get_names_from_view(view) ], sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS) return []
def run(self): view = self.window.active_view() if view is None: return is_tex_file = bool(view.score_selector(0, "text.tex.latex")) if not (is_tex_file or is_bib_buffer(view)): return # find the instance of LatextoolsCacheUpdateListener, if any cache_listener = None for callback in sublime_plugin.all_callbacks['on_close']: try: instance = get_self(callback) except: continue if instance.__class__.__name__ == 'LatextoolsCacheUpdateListener': cache_listener = instance break if cache_listener is None: return # if run from a TeX file, clear all bib caches associated with this # document if is_tex_file: tex_root = getTeXRoot.get_tex_root(view) for bib_cache in cache_listener._BIB_CACHES.get(tex_root, []): bib_cache.invalidate() # if run from a bib file, clear all bib caches that reflect this # document else: file_name = view.file_name() if not file_name: return for bib_caches in cache_listener._BIB_CACHES.values(): for bib_cache in bib_caches: if bib_cache.bib_file == file_name: bib_cache.invalidate()
def on_query_completions(self, view, prefix, locations): if not is_bib_buffer(view): return [] cursor_point = view.sel()[0].b # do not autocomplete if the cursor is outside an entry if view.score_selector(cursor_point, 'meta.entry.braces.bibtex') == 0: return [] # do not autocomplete when cursor is in the citekey field if view.score_selector(cursor_point, 'entity.name.type.entry-key.bibtex') > 0: return [] # do not autocomplete if we are already inside a field if view.score_selector(cursor_point, 'meta.key-assignment.bibtex') > 0: return [] if is_biblatex_buffer(view): return (biblatex_fields, sublime.INHIBIT_WORD_COMPLETIONS) else: return (bibtex_fields, sublime.INHIBIT_WORD_COMPLETIONS)
def is_visible(self, *args): view = self.window.active_view() if view: return (bool(view.score_selector(0, "text.tex.latex")) or is_bib_buffer(view)) return False
def is_visible(self, *args): view = self.window.active_view() return ( bool(view.score_selector(0, "text.tex.latex")) or is_bib_buffer(view) )