コード例 #1
0
ファイル: plugin.py プロジェクト: solarnz/vial
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))
コード例 #2
0
ファイル: plugin.py プロジェクト: baverman/vial
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))
コード例 #3
0
ファイル: plugin.py プロジェクト: baverman/vial-python
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))
コード例 #4
0
ファイル: plugin.py プロジェクト: baverman/vial-python
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))
コード例 #5
0
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)
コード例 #6
0
ファイル: plugin.py プロジェクト: baverman/vial
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)