def kill_buffers( nvim: Nvim, last_used: Mapping[int, None], paths: AbstractSet[PurePath], reopen: Mapping[PurePath, PurePath], ) -> None: active = ({ win_get_buf(nvim, win=win): win for win in find_non_fm_windows_in_tab( nvim, last_used=last_used, ) } if reopen else {}) for buf in list_bufs(nvim, listed=True): name = PurePath(buf_name(nvim, buf=buf)) buf_paths = ancestors(name) | {name} if not buf_paths.isdisjoint(paths): win = active.get(buf) new_path = reopen.get(name) if reopen and win and new_path: p = Path(name) p.touch() with hold_win_pos(nvim): set_cur_win(nvim, win=win) escaped = nvim.funcs.fnameescape(normcase(new_path)) nvim.command(f"edit! {escaped}") p.unlink(missing_ok=True) buf_close(nvim, buf=buf)
async def _poll(self) -> None: while True: bufs = await async_call( self._supervisor.nvim, lambda: list_bufs(self._supervisor.nvim, listed=True), ) await self._misc.vacuum({buf.number for buf in bufs}) async with self._supervisor.idling: await self._supervisor.idling.wait()
def find_buffers_with_file(nvim: Nvim, file: PurePath) -> Iterator[Buffer]: for buf in list_bufs(nvim, listed=True): name = PurePath(buf_name(nvim, buf=buf)) if name == file: yield buf
def find_fm_buffers(nvim: Nvim) -> Iterator[Buffer]: for buf in list_bufs(nvim, listed=True): if is_fm_buffer(nvim, buf=buf): yield buf
def _list_marked_bufs(nvim: Nvim) -> Iterator[Buffer]: for buf in list_bufs(nvim): flag: Optional[bool] = buf_get_var(nvim, buf=buf, key=BUF_VAR_NAME) if flag: yield buf
def find_buffers_with_file(nvim: Nvim, file: str) -> Iterator[Buffer]: for buf in list_bufs(nvim): name = buf_name(nvim, buf=buf) if name == file: yield buf
def kill_buffers(nvim: Nvim, paths: AbstractSet[str]) -> None: for buf in list_bufs(nvim): name = buf_name(nvim, buf=buf) buf_paths = ancestors(name) | {name} if not buf_paths.isdisjoint(paths): buf_close(nvim, buf=buf)
def _scratch_buffer(nvim: Nvim) -> None: bufs = list_bufs(nvim, listed=False) for buf in bufs: name = buf_name(nvim, buf=buf) if not name: buf_set_option(nvim, buf=buf, key="buftype", val="nofile")
def cont() -> Iterator[str]: for buf in list_bufs(nvim, listed=True): with suppress(NvimError): filename = buf_name(nvim, buf=buf) yield filename