Пример #1
0
def _update(nvim: Nvim, buf: Buffer, ns: int, derived: Derived) -> Atomic:
    n_hash = derived.hashed
    try:
        p_hash: Sequence[str] = decode(
            Sequence[str], buf_get_var(nvim, buf=buf, key=_FM_HASH_VAR))
    except DecodeError:
        p_hash = ("", )

    atomic = Atomic()
    for (i1, i2), (j1, j2) in trans_inplace(src=p_hash,
                                            dest=n_hash,
                                            unifying=10):
        atomic.buf_clear_namespace(buf, ns, i1, i2)
        atomic.buf_set_lines(buf, i1, i2, True, derived.lines[j1:j2])

        for idx, highlights in enumerate(derived.highlights[j1:j2], start=i1):
            for hl in highlights:
                atomic.buf_add_highlight(buf, ns, hl.group, idx, hl.begin,
                                         hl.end)

        for idx, badges in enumerate(derived.badges[j1:j2], start=i1):
            vtxt = tuple((bdg.text, bdg.group) for bdg in badges)
            atomic.buf_set_virtual_text(buf, ns, idx, vtxt, {})

    atomic.buf_set_var(buf, _FM_HASH_VAR, n_hash)
    return atomic
Пример #2
0
def _update(
    use_extmarks: bool,
    buf: Buffer,
    ns: int,
    derived: Derived,
    hashed_lines: Sequence[str],
) -> Atomic:

    atomic = Atomic()
    for (i1, i2), (j1, j2) in trans_inplace(src=hashed_lines,
                                            dest=derived.hashed,
                                            unifying=10):
        atomic.buf_clear_namespace(buf, ns, i1, i2)
        atomic.buf_set_lines(buf, i1, i2, True, derived.lines[j1:j2])

        for idx, highlights in enumerate(derived.highlights[j1:j2], start=i1):
            for hl in highlights:
                atomic.buf_add_highlight(buf, ns, hl.group, idx, hl.begin,
                                         hl.end)

        for idx, badges in enumerate(derived.badges[j1:j2], start=i1):
            vtxt = tuple((bdg.text, bdg.group) for bdg in badges)
            if use_extmarks:
                atomic.buf_set_extmark(buf, ns, idx, -1, {
                    "virt_text": vtxt,
                    "hl_mode": "combine"
                })
            else:
                atomic.buf_set_virtual_text(buf, ns, idx, vtxt, {})

    atomic.buf_set_var(buf, _FM_HASH_VAR, derived.hashed)
    return atomic