Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ cell.
- `merge_cell`: Merge the current cell ith the one above (`dir='u'`) or below
(`dir='d'`)

## Related plugins

- [nvim-various-textobjs](https://github.com/chrisgrieser/nvim-various-textobjs)
also provides a notebook cell object that you might want to consider if you are
not interested on all the other functionality in NotebookNavigator.

## Contributors

A list of contributors can be found on `contributors.txt`.
Expand Down
12 changes: 12 additions & 0 deletions lua/notebook-navigator/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ M.run_all_cells = function(repl_provider, repl_args)
repl(1, buf_length, repl_args)
end

M.run_cells_above = function(cell_marker, repl_provider, repl_args)
local start_line = 1
local cell_object = miniai_spec("i", cell_marker)

local repl = get_repl(repl_provider)

if cell_object.from.line > 1 then
local previous_cell_end = cell_object.from.line - 1
repl(start_line, previous_cell_end, repl_args)
end
end

M.run_cells_below = function(cell_marker, repl_provider, repl_args)
local buf_length = vim.api.nvim_buf_line_count(0)
local cell_object = miniai_spec("i", cell_marker)
Expand Down
11 changes: 9 additions & 2 deletions lua/notebook-navigator/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ M.run_all_cells = function(repl_args)
core.run_all_cells(M.config.repl_provider, repl_args)
end

--- Run all cells above the current cell
---
---@param repl_args table|nil Optional config for the repl.
M.run_cells_above = function(repl_args)
core.run_cells_above(cell_marker(), M.config.repl_provider, repl_args)
end

--- Run all cells below (including current cell)
---
---@param repl_args table|nil Optional config for the repl.
Expand Down Expand Up @@ -207,7 +214,7 @@ local function activate_hydra(config)
M.split_cell,
{ desc = "Split cell", nowait = true },
},
{ "q", nil, { exit = true, nowait = true, desc = "exit" } },
{ "q", nil, { exit = true, nowait = true, desc = "exit" } },
{ "<esc>", nil, { exit = true, nowait = true, desc = "exit" } },
}

Expand Down Expand Up @@ -318,7 +325,7 @@ M.setup = function(config)
if #utils.available_repls == 0 then
vim.notify "[NotebookNavigator] No supported REPLs available.\nMost functionality will error out."
elseif
M.config.repl_provider ~= "auto" and not utils.has_value(utils.available_repls, M.config.repl_provider)
M.config.repl_provider ~= "auto" and not utils.has_value(utils.available_repls, M.config.repl_provider)
then
vim.notify("[NotebookNavigator] The requested repl (" .. M.config.repl_provider .. ") is not available.")
end
Expand Down