Ejemplo n.º 1
0
def indent():
    line, pos = vim.current.window.cursor
    buf = vim.current.buffer
    if buf[line-2].endswith(':'):
        return shift_indent(line)

    pline = buf[line-2].rstrip()
    if pline and pline[-1] in parens.keys():
        return shift_indent(line)

    if pline:
        start, closeb = max((pline.rfind(b), b) for b in parens.values())
        if start >= 0:
            openb = rparens[closeb]
            vfunc.cursor(line - 1, start + 1)
            l, _ = vfunc.searchpairpos(pescape[openb], '', pescape[closeb],
                                       'nWb', '', max(0, line - 30))
            if l and l != line - 1:
                return vfunc.indent(l)

        start = -1
        while True:
            start, openb = max((pline.rfind(b, 0, start), b)
                               for b in parens.keys())
            if start < 0:
                break
            vfunc.cursor(line - 1, start + 1)
            l, _ = vfunc.searchpairpos(pescape[openb], '',
                                       pescape[parens[openb]], 'nW', '', line)
            if not l or l != line - 1:
                return start + 1

    w = vfunc.indent(line-1)
    if not buf[line-1].strip() and w != pos:
        return -1

    return w
Ejemplo n.º 2
0
def indent():
    lnum, pos = vim.current.window.cursor
    buf = vim.current.buffer
    if lnum > 1:
        # previous line ends with a colon
        if buf[lnum - 2].endswith(':'):
            # log.error(('lnum > 1:', lnum, shift_indent(lnum)))
            return shift_indent(lnum)

        pline = buf[lnum - 2].rstrip()
        if pline and pline[-1] in parens.keys():
            # log.error(('lnum > 1 op ', lnum, repr(pline), shift_indent(lnum)))
            return shift_indent(lnum)

        if pline and pline[-2:] in ('"\\', "'\\"):
            # log.error(('lnum > 1 "\\ ', lnum, repr(pline), shift_indent(lnum)))
            return shift_indent(lnum)

        if pline and pline.endswith(','):
            np = get_nearest_paren(lnum, pos)
            if np and np[0] < lnum and np[1] < len(buf[np[0] - 1]):
                # log.error(('np', lnum, pos, np))
                return np[1]

    # current lines starts with a close parent
    cline = buf[lnum - 1].lstrip()
    if cline and cline[0] in parens.values():
        # log.error(('cline', repr(cline), vfunc.cindent(lnum)))
        return vfunc.cindent(lnum)

    # get indent of previous line
    w = vfunc.indent(lnum - 1)
    if not buf[lnum - 1].strip() and w != pos:
        # log.error(('pline', w))
        return -1

    # log.error(('Else', w))
    return w
Ejemplo n.º 3
0
def shift_indent(line, shift=1):
    return vfunc.indent(line - 1) + shift * vfunc.eval('&sw')
Ejemplo n.º 4
0
def shift_indent(line, shift=1):
    return vfunc.indent(line-1) + shift * vfunc.eval('&sw')