From 6da3d1934922bfde5ba6ccf27b465a23e6190115 Mon Sep 17 00:00:00 2001 From: Ben Lubas <56943754+benlubas@users.noreply.github.com> Date: Wed, 13 Dec 2023 22:31:55 -0500 Subject: [PATCH] feat: :ReevaluateAllCells command (#85) --- rplugin/python3/molten/__init__.py | 11 +++++++++++ rplugin/python3/molten/moltenbuffer.py | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/rplugin/python3/molten/__init__.py b/rplugin/python3/molten/__init__.py index 6533bd3..e267642 100644 --- a/rplugin/python3/molten/__init__.py +++ b/rplugin/python3/molten/__init__.py @@ -587,6 +587,17 @@ def cmd(kernel_id: str): """ self.nvim.exec_lua(lua, async_=False) + @pynvim.command("MoltenReevaluateAll", nargs=0, sync=True) # type: ignore + @nvimui # type: ignore + def command_reevaluate_all(self) -> None: + self._initialize_if_necessary() + + molten_kernels = self._get_current_buf_kernels(True) + assert molten_kernels is not None + + for kernel in molten_kernels: + kernel.reevaluate_all() + @pynvim.command("MoltenReevaluateCell", nargs=0, sync=True) # type: ignore @nvimui # type: ignore def command_evaluate_cell(self) -> None: diff --git a/rplugin/python3/molten/moltenbuffer.py b/rplugin/python3/molten/moltenbuffer.py index bb397d3..8efc5db 100644 --- a/rplugin/python3/molten/moltenbuffer.py +++ b/rplugin/python3/molten/moltenbuffer.py @@ -115,6 +115,11 @@ def run_code(self, code: str, span: CodeCell) -> None: self._check_if_done_running() + def reevaluate_all(self) -> None: + for span in sorted(self.outputs.keys(), key=lambda s: s.begin): + code = span.get_text(self.nvim) + self.run_code(code, span) + def reevaluate_cell(self) -> bool: self.selected_cell = self._get_selected_span() if self.selected_cell is None: