def grep(query): matcher = re.compile(re.escape(query)) t = time() - 1 result = [] for r in get_projects(): for name, path, root, top, fullpath in get_files(r): if time() - t >= 1: redraw() print fullpath t = time() try: if os.stat(fullpath).st_size > MAX_FILESIZE: continue with open(fullpath) as f: source = f.read() matches = matcher.finditer(source) lines = source.splitlines() except OSError: continue for m in matches: start = m.start() line = source.count('\n', 0, start) + 1 offset = start - source.rfind('\n', 0, start) text = lines[line - 1] if len(text) > 100: offstart = max(0, offset - 30) text = text[offstart:offstart + 60] + '...' if offstart: text = '...' + text result.append({ 'bufnr': '', 'filename': fullpath, 'pattern': '', 'valid': 1, 'nr': -1, 'lnum': line, 'vcol': 0, 'col': offset, 'text': text.replace('\x00', ' '), 'type': '' }) vfunc.setqflist(result) if result: vim.command('cw') redraw() print '{} matches found'.format(len(result))
def grep(query): matcher = re.compile(re.escape(query)) t = time() - 1 result = [] for r in get_projects(): for name, path, root, top, fullpath in get_files(r): if time() - t >= 1: redraw() print fullpath t = time() try: if os.stat(fullpath).st_size > MAX_FILESIZE: continue with open(fullpath) as f: source = f.read() matches = matcher.finditer(source) lines = source.splitlines() except OSError: continue for m in matches: start = m.start() line = source.count('\n', 0, start) + 1 offset = start - source.rfind('\n', 0, start) text = lines[line - 1] if len(text) > 100: offstart = max(0, offset - 30) text = text[offstart:offstart+60] + '...' if offstart: text = '...' + text result.append({ 'bufnr': '', 'filename': fullpath, 'pattern': '', 'valid': 1, 'nr': -1, 'lnum': line, 'vcol': 0, 'col': offset, 'text': text.replace('\x00', ' '), 'type': '' }) vfunc.setqflist(result) if result: vim.command('cw') redraw() print '{} matches found'.format(len(result))
def show_lint_result(errors, warns, append=False): result = errors + warns if not result: vim.command('cclose') redraw() print 'Good job!' return vfunc.setqflist(errors + warns, 'a' if append else ' ') if errors: vim.command('copen') redraw() print '{} error(s) and {} warning(s) found'.format(len(errors), len(warns))
def filter_qf(pattern): qf = vfunc.getqflist() if not qf: return regex = re.compile(fnmatch.translate(pattern)) result = [] for r in qf: fname = vfunc.bufname(r['bufnr']) if regex.match(fname): nr = dict(r) nr['filename'] = fname result.append(nr) vfunc.setqflist(result)