Skip to content

Commit

Permalink
feat: MoltenEvaluateRange non-strict indexing (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
benlubas committed Dec 14, 2023
1 parent 900441a commit 955b0e8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
1 change: 0 additions & 1 deletion docs/Not-So-Quick-Start-Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ return {
-- these are examples, not defaults. Please see the readme
vim.g.molten_image_provider = "image.nvim"
vim.g.molten_output_win_max_height = 20
vim.g.molten_auto_open_output = false
end,
},
{
Expand Down
8 changes: 5 additions & 3 deletions rplugin/python3/molten/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def _do_evaluate_expr(self, kernel_name: str, expr):
cell = CodeCell(
self.nvim,
DynamicPosition(self.nvim, self.extmark_namespace, bufno, 0, 0),
DynamicPosition(self.nvim, self.extmark_namespace, bufno, 0, 0),
DynamicPosition(self.nvim, self.extmark_namespace, bufno, 0, 0, right_gravity=True),
)

kernel.run_code(expr, cell)
Expand Down Expand Up @@ -325,7 +325,7 @@ def _do_evaluate(self, kernel_name: str, pos: Tuple[Tuple[int, int], Tuple[int,
span = CodeCell(
self.nvim,
DynamicPosition(self.nvim, self.extmark_namespace, bufno, *pos[0]),
DynamicPosition(self.nvim, self.extmark_namespace, bufno, *pos[1]),
DynamicPosition(self.nvim, self.extmark_namespace, bufno, *pos[1], right_gravity=True),
)

code = span.get_text(self.nvim)
Expand Down Expand Up @@ -902,7 +902,9 @@ def function_molten_define_cell(self, args: List[int]) -> None:
span = CodeCell(
self.nvim,
DynamicPosition(self.nvim, self.extmark_namespace, bufno, start - 1, 0),
DynamicPosition(self.nvim, self.extmark_namespace, bufno, end - 1, -1),
DynamicPosition(
self.nvim, self.extmark_namespace, bufno, end - 1, -1, right_gravity=True
),
)

for molten in molten_kernels:
Expand Down
2 changes: 1 addition & 1 deletion rplugin/python3/molten/code_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_text(self, nvim: Nvim) -> str:
assert self.begin.bufno == self.end.bufno

lines: List[str] = nvim.funcs.nvim_buf_get_lines(
self.bufno, self.begin.lineno, self.end.lineno + 1, True
self.bufno, self.begin.lineno, self.end.lineno + 1, False
)

if len(lines) == 1:
Expand Down
3 changes: 3 additions & 0 deletions rplugin/python3/molten/outputbuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ def show_virtual_output(self, anchor: Position) -> None:
if self.options.virt_lines_off_by_1:
win_row += 1

if win_row > (last := self.nvim.funcs.line("$")):
win_row = last

shape = (
win_col,
win_row,
Expand Down
7 changes: 6 additions & 1 deletion rplugin/python3/molten/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ def __init__(
bufno: int,
lineno: int,
colno: int,
right_gravity: bool = False,
):
self.nvim = nvim
self.extmark_namespace = extmark_namespace

self.bufno = bufno
self.extmark_id = self.nvim.funcs.nvim_buf_set_extmark(
self.bufno, extmark_namespace, lineno, colno, {}
self.bufno,
extmark_namespace,
lineno,
colno,
{"right_gravity": right_gravity, "strict": False},
)

def set_height(self, height: int) -> None:
Expand Down
1 change: 1 addition & 0 deletions rplugin/python3/molten/save_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def load(nvim: Nvim, moltenbuffer: MoltenKernel, nvim_buffer: Buffer, data: Dict
nvim_buffer.number,
cell["span"]["end"]["lineno"],
cell["span"]["end"]["colno"],
right_gravity=True,
)
span = CodeCell(nvim, begin_position, end_position)

Expand Down

0 comments on commit 955b0e8

Please sign in to comment.