Exemplo n.º 1
0
def show_signature():
    source, pos = get_content_and_offset()
    result = env.get().get_docstring(source, pos, vim.current.buffer.name)
    redraw()
    if result:
        print result[0]
    else:
        print 'None'
Exemplo n.º 2
0
def show_signature():
    source, pos = get_content_and_offset()
    result = env.get().get_docstring(source, pos, vim.current.buffer.name)
    redraw()
    if result:
        print result[0]
    else:
        print 'None'
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 5
0
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))
Exemplo n.º 6
0
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))
Exemplo n.º 7
0
def goto_definition():
    source = get_content()
    pos = vim.current.window.cursor
    locs = env.get().location(source, pos, vim.current.buffer.name)

    if locs:
        mark()
        last = locs[-1]
        if isinstance(last, dict):
            head = locs[:-1]
            tail = [last]
        else:
            tail = last
            last = tail[0]
            head = locs[:-1]

        locs = head + tail
        if len(locs) > 1:
            llist = [{
                'bufnr': '',
                'filename': loc['file'],
                'pattern': '',
                'valid': 1,
                'nr': -1,
                'lnum': loc['loc'][0],
                'vcol': 0,
                'col': loc['loc'][1] + 1,
            } for loc in locs]
            vfunc.setloclist(0, llist, ' ')
            vim.command(':ll {}'.format(len(head) + 1))
            redraw()
            if len(tail) > 1:
                print 'Multiple locations'
            else:
                print 'Chained locations'
        else:
            fname = last['file']
            dpos = last['loc']
            if fname and fname != vim.current.buffer.name:
                vim.command(':edit {}'.format(vfunc.fnameescape(fname)))
                vim.current.window.cursor = dpos
            else:
                vim.current.window.cursor = dpos
    else:
        redraw()
        print 'Location not found'
Exemplo n.º 8
0
def goto_definition():
    source = get_content()
    pos = vim.current.window.cursor
    locs = env.get().location(source, pos, vim.current.buffer.name)

    if locs:
        mark()
        last = locs[-1]
        if isinstance(last, dict):
            head = locs[:-1]
            tail = [last]
        else:
            tail = last
            last = tail[0]
            head = locs[:-1]

        locs = head + tail
        if len(locs) > 1:
            llist = [{
                'bufnr': '',
                'filename': loc['file'],
                'pattern': '',
                'valid': 1,
                'nr': -1,
                'lnum': loc['loc'][0],
                'vcol': 0,
                'col': loc['loc'][1] + 1,
            } for loc in locs]
            vfunc.setloclist(0, llist, ' ')
            vim.command(':ll {}'.format(len(head) + 1))
            redraw()
            if len(tail) > 1:
                print 'Multiple locations'
            else:
                print 'Chained locations'
        else:
            fname = last['file']
            dpos = last['loc']
            if fname and fname != vim.current.buffer.name:
                vim.command(':edit {}'.format(vfunc.fnameescape(fname)))
                vim.current.window.cursor = dpos
            else:
                vim.current.window.cursor = dpos
    else:
        redraw()
        print 'Location not found'
Exemplo n.º 9
0
def grepop(type):
    old = vfunc.getreg('"')

    if type == 'v':
        vim.command('normal! `<v`>y')
    elif type == 'char':
        vim.command('normal! `[v`]y')
    else:
        return

    query = vfunc.getreg('"')
    if query.strip():
        grep(query)
    else:
        redraw()
        print 'Search for nothing?'

    vfunc.setreg('"', old)
Exemplo n.º 10
0
def grepop(type):
    old = vfunc.getreg('"')

    if type == 'v':
        vim.command('normal! `<v`>y')
    elif type == 'char':
        vim.command('normal! `[v`]y')
    else:
        return

    query = vfunc.getreg('"')
    if query.strip():
        grep(query)
    else:
        redraw()
        print 'Search for nothing?'

    vfunc.setreg('"', old)
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
0
    def add_test_result(self, rtype, name, result):
        self.counts[rtype] += 1
        lines = ['{} {}'.format(name, rtype)]

        trace, out = result
        for k, v in out:
            lines.append('  ----======= {} =======----'.format(k))
            lines.extend(indent(1, v.splitlines()))
            lines.append('')

        if trace:
            lines.extend(indent(1, trace.splitlines()))
            lines.append('')

        lines.append('')

        buflen = len(self.buf)
        self.buf[buflen-1:] = lines
        redraw()
Exemplo n.º 14
0
def jump(dir):
    w = vim.current.window
    check_history(w)
    history = list(w.vars[VHIST])

    bufnr = vim.current.buffer.number

    now = time()
    lastbuf = w.vars.get(VLAST, None)
    if not lastbuf or (bufnr == lastbuf[0] and
                       now - lastbuf[1] > vim.vars['vial_bufhist_timeout']):
        history = add_to_history(w, bufnr)

    if bufnr not in history:
        history = add_to_history(w, bufnr)

    names = {
        r.number:
        (split(r.name) if r.name else ['', '[buf-{}]'.format(r.number)])
        for r in vim.buffers if vfunc.buflisted(r.number)
    }
    history[:] = filter(lambda r: r in names, history)

    dups = True
    while dups:
        dups = False
        for name, g in groupby(sorted(names.iteritems(), key=skey), skey):
            g = list(g)
            if len(g) > 1:
                dups = True
                for nr, (path, _) in g:
                    p, n = split(path)
                    names[nr] = p, n + '/' + name

    width = vim.vars['vial_bufhist_width']
    if width < 0:
        width += int(vim.eval('&columns')) - 1

    try:
        idx = history.index(bufnr)
    except ValueError:
        return

    idx += dir

    if idx < 0:
        idx = 0
    elif idx >= len(history):
        idx = len(history) - 1

    anr = history[idx]
    active = names[anr][1]
    before = '  '.join(names[r][1] for r in history[:idx])
    after = '  '.join(names[r][1] for r in history[idx + 1:])

    half = (width - len(active) - 4) / 2
    if len(before) < len(after):
        blen = min(half, len(before))
        alen = width - len(active) - blen - 4
    else:
        alen = min(half, len(after))
        blen = width - len(active) - alen - 4

    if len(before) > blen:
        before = '...' + before[3 - blen:]
    if len(after) > alen:
        after = after[:alen - 3] + '...'

    if before: before += '  '
    if after: after = '  ' + after

    vim.command('let x=&ruler | let y=&showcmd')
    vim.command('set noruler noshowcmd')
    redraw()
    echon(before)
    vim.command('echohl CursorLine')
    echon(active)
    vim.command('echohl None')
    echon(after)
    vim.command('let &ruler=x | let &showcmd=y')

    if anr != bufnr:
        w.vars['vial_bufhist_switch'] = 1
        vim.command('silent b {}'.format(anr))
        w.vars['vial_bufhist_switch'] = 0

    vim.command('augroup vial_bufhist_wait_action')
    vim.command('au!')
    vim.command('au CursorMoved,CursorHold <buffer> python %s()' % moved.ref)
    vim.command('augroup END')
Exemplo n.º 15
0
def jump(dir):
    w = vim.current.window
    check_history(w)
    history = list(w.vars[VHIST])

    bufnr = vim.current.buffer.number

    now = time()
    lastbuf = w.vars.get(VLAST, None)
    if not lastbuf or (bufnr == lastbuf[0] and
                       now - lastbuf[1] > vim.vars['vial_bufhist_timeout']):
        history = add_to_history(w, bufnr)

    if bufnr not in history:
        history = add_to_history(w, bufnr)

    names = {r.number: (split(r.name)
                        if r.name
                        else ['', '[buf-{}]'.format(r.number)])
             for r in vim.buffers if vfunc.buflisted(r.number)}
    history[:] = filter(lambda r: r in names, history)

    dups = True
    while dups:
        dups = False
        for name, g in groupby(sorted(names.iteritems(), key=skey), skey):
            g = list(g)
            if len(g) > 1:
                dups = True
                for nr, (path, _) in g:
                    p, n = split(path)
                    names[nr] = p, n + '/' + name

    width = vim.vars['vial_bufhist_width']
    if width < 0:
        width += int(vim.eval('&columns')) - 1

    try:
        idx = history.index(bufnr)
    except ValueError:
        return

    idx += dir

    if idx < 0:
        idx = 0
    elif idx >= len(history):
        idx = len(history) - 1

    anr = history[idx]
    active = names[anr][1]
    before = '  '.join(names[r][1] for r in history[:idx])
    after = '  '.join(names[r][1] for r in history[idx+1:])

    half = (width - len(active) - 4) / 2
    if len(before) < len(after):
        blen = min(half, len(before))
        alen = width - len(active) - blen - 4
    else:
        alen = min(half, len(after))
        blen = width - len(active) - alen - 4

    if len(before) > blen:
        before = '...' + before[3-blen:]
    if len(after) > alen:
        after = after[:alen-3] + '...'

    if before: before += '  '
    if after: after = '  ' + after

    vim.command('let x=&ruler | let y=&showcmd')
    vim.command('set noruler noshowcmd')
    redraw()
    echon(before)
    vim.command('echohl CursorLine')
    echon(active)
    vim.command('echohl None')
    echon(after)
    vim.command('let &ruler=x | let &showcmd=y')

    if anr != bufnr:
        w.vars['vial_bufhist_switch'] = 1
        vim.command('silent b {}'.format(anr))
        w.vars['vial_bufhist_switch'] = 0

    vim.command('augroup vial_bufhist_wait_action')
    vim.command('au!')
    vim.command('au CursorMoved,CursorHold <buffer> python %s()' % moved.ref)
    vim.command('augroup END')
Exemplo n.º 16
0
 def reset(self):
     cwin = vim.current.window
     _, self.buf = make_scratch('__vial_pytest__', self.init, 'pytest')
     vim.command('normal! ggdG')
     focus_window(cwin)
     redraw()