def _get_default_engine_if_not_valid(engine, default='DuckDuckGo'): if engine is None: engine = suricate.get_setting('default_search_engine', default) if engine not in ENGINES: suricate.log('ERROR: Search engine "%s" not implemented.', engine) engine = default return engine
def clean(window=None): """Remove LaTeX temporary files.""" temp_extensions = [ ".log", ".aux", ".dvi", ".lof", ".lot", ".bit", ".idx", ".glo", ".bbl", ".ilg", ".toc", ".ind", ".out", ".synctex.gz", ".blg", ] prefix = _get_path_prefix(window) counter = 0 for path in [prefix + ext for ext in temp_extensions]: if os.access(path, os.F_OK): os.remove(path) counter += 1 message = "%i files removed" % counter suricate.log(message) sublime.status_message(message)
def to_buffer(title, modules): # @todo infinite recursion. assert not suricate.is_packaged() writer = MarkdownWriter() writer.add_header(title, level=1) for mymodule in modules: module_name = mymodule['module'] module_alias = mymodule.get('alias') recursive = mymodule.get('recursive', False) suricate.log('generating documentation for %r...', module_name) root = import_module(module_name) if not recursive: writer.add_module(module_alias, module(module_name)) else: for _, name, _ in pkgutil.walk_packages(root.__path__, root.__name__ + '.'): suricate.log('parsing module %r...', name) module_info = module(name) if module_alias and module_info.name.startswith(module_name): alias = module_alias + module_info.name[len(module_name):] else: alias = module_info.name writer.add_module(alias, module_info) sublime_wrapper.flush_to_buffer( '\n'.join(writer.lines), name=title, scratch=True, syntax='Markdown')
def convert_to_tex(string): """Convert special characters to TeX symbols.""" # @todo add more symbols tex_symbols = sublime_wrapper.locate_and_load_resource("tex_symbols_map") if not tex_symbols: suricate.log("ERROR: unable to load 'tex_symbols_map'") return for char, tex in [x.split(" ") for x in tex_symbols.splitlines()]: string = string.replace(char, tex) return string
def call(cmd, active_flags, view): settings = sublime.load_settings(SourceControlFileBaseName) scslist = settings.get('user_source_control') scslist += settings.get('source_control') for item in scslist: cmdi = item['commands'].get(cmd) if cmdi is not None and suricate.flags.special_check( active_flags, suricate.flags.from_string( item['flags'])) and all( osutil.which(exe) is not None for exe in item['exes']): suricate.debuglog('%s: %s', item['name'], cmdi['caption']) cmdi['path'] = view.file_name() return _do(**cmdi) suricate.log('ERROR: Source control command \'%s\' is not available.', cmd)
def locate_and_load_resource(hint): """Try to load the first match of hint""" try: return sublime.load_resource(hint) except OSError: pass resources = sublime.find_resources(hint) if not resources: sublime.error_message('Unable to locate %r' % hint) raise OSError('resource not found') first = resources[0] if len(resources) > 1: suricate.log('WARNING: more than one %r found, using %r', hint, first) return sublime.load_resource(first)
def switch_language(view): dicts = suricate.get_setting('quick_switch_dictionary_list', []) if not dicts: dicts = sublime.find_resources('*.dic') if not dicts: suricate.log('ERROR: no dictionary found') return current = view.settings().get('dictionary') next_item_index = dicts.index(current) + 1 if current in dicts else 0 next_item = dicts[next_item_index % len(dicts)] if next_item in sublime.find_resources('*.dic'): view.settings().set('dictionary', next_item) sublime.status_message( 'Dictionary changed to %s' % os.path.basename(next_item)) else: sublime.error_message('Dictionary %r not available' % next_item)
def show_quick_panel(display_list, on_done, window=None): """Show a quick panel fed with display_list on window. on_done must be a callable object that accepts one argument, the element picked (not the index!). It won't be called if the user cancels.""" if not display_list: suricate.log('ERROR: Quick panel fed with an empty list!') return if window is None: window = sublime.active_window() def _on_done(index): if index != -1: on_done(display_list[index]) sublime.status_message('Cancelled') # This allows nested quick panels on Sublime Text 3. def _on_show_quick_panel(): window.run_command('hide_overlay') window.show_quick_panel(display_list, _on_done) sublime.set_timeout(_on_show_quick_panel, 0)