Ejemplo n.º 1
0
 def it() -> Iterator[Tuple[int, int]]:
     for tabsize in range(2, 9):
         indent_lvs = tuple(
             p_indent(line, tabsize=tabsize) for line in lines if lines)
         divibilty = sum(lv % tabsize == 0 for lv in indent_lvs if lv)
         if divibilty:
             yield divibilty, tabsize
Ejemplo n.º 2
0
def _p_inside(init_lv: int, tabsize: int, lines: Iterable[str]) -> int:
    n = 0
    for n, line in enumerate(lines):
        lv = p_indent(line, tabsize=tabsize)
        if line and lv < init_lv:
            return n
    else:
        return n + 1 if n else 0
Ejemplo n.º 3
0
def _indent(nvim: Nvim) -> None:
    win = cur_win(nvim)
    buf = win_get_buf(nvim, win)
    row, _ = win_get_cursor(nvim, win)
    tabsize: int = buf_get_option(nvim, buf=buf, key="tabstop")

    lines = buf_get_lines(nvim, buf=buf, lo=0, hi=-1)
    before, curr, after = lines[:row], lines[row], lines[row + 1:]
    init_lv = p_indent(curr, tabsize=tabsize)

    top = row - _p_inside(init_lv, tabsize=tabsize, lines=reversed(before))
    btm = row + _p_inside(init_lv, tabsize=tabsize, lines=after)

    set_visual_selection(nvim,
                         win=win,
                         mode="V",
                         mark1=(top, 0),
                         mark2=(btm, 0))
Ejemplo n.º 4
0
def _indent(nvim: Nvim) -> None:
    win = cur_win(nvim)
    buf = win_get_buf(nvim, win)
    row, _ = win_get_cursor(nvim, win)
    tabsize: int = buf_get_option(nvim, buf=buf, key="tabstop")

    lines = buf_get_lines(nvim, buf=buf, lo=0, hi=-1)
    before, curr, after = lines[:row], lines[row], lines[row + 1:]
    init_lv = p_indent(curr, tabsize=tabsize)

    top = row - _p_inside(init_lv, tabsize=tabsize, lines=reversed(before))
    btm = row + _p_inside(init_lv, tabsize=tabsize, lines=after)

    lines = deque(buf_get_lines(nvim, buf=buf, lo=top, hi=btm + 1))
    while lines:
        if line := lines.popleft():
            lines.appendleft(line)
            break
        else:
            top += 1