Example #1
0
 def get_file_iter(self, root):
     try:
         return self.file_iter_cache[root]
     except KeyError:
         result = get_files(root, keep_top=len(get_projects()) > 1)
         self.file_iter_cache[root] = result
         return result
Example #2
0
 def get_file_iter(self, root):
     try:
         return self.file_iter_cache[root]
     except KeyError:
         result = get_files(root, keep_top=len(get_projects()) > 1)
         self.file_iter_cache[root] = result
         return result
Example #3
0
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))
Example #4
0
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))
Example #5
0
def lint_all():
    t = time() - 1
    errors, warns = [], []
    for r in get_projects():
        for name, path, root, top, fullpath in get_files(r):
            if name.endswith('.py'):
                if time() - t >= 1:
                    redraw()
                    print fullpath
                    t = time()

                with open(fullpath) as f:
                    source = f.read()

                e, w = _lint(source, fullpath)
                errors += e
                warns += w

    show_lint_result(errors, warns)
Example #6
0
def lint_all():
    t = time() - 1
    errors, warns = [], []
    for r in get_projects():
        for name, path, root, top, fullpath in get_files(r):
            if name.endswith('.py'):
                if time() - t >= 1:
                    redraw()
                    print fullpath
                    t = time()

                with open(fullpath) as f:
                    source = f.read()

                e, w = _lint(source, fullpath)
                errors += e
                warns += w

    show_lint_result(errors, warns)