diff --git a/README.md b/README.md index ae23baf..4d43af8 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/lua/notebook-navigator/core.lua b/lua/notebook-navigator/core.lua index 279602d..a4bbc86 100644 --- a/lua/notebook-navigator/core.lua +++ b/lua/notebook-navigator/core.lua @@ -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) diff --git a/lua/notebook-navigator/init.lua b/lua/notebook-navigator/init.lua index 797d291..04194eb 100644 --- a/lua/notebook-navigator/init.lua +++ b/lua/notebook-navigator/init.lua @@ -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. @@ -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" } }, { "", nil, { exit = true, nowait = true, desc = "exit" } }, } @@ -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