From f34dabfb0818b63b530db125d9e68f67e6f8e699 Mon Sep 17 00:00:00 2001 From: ESSO0428 <92996726+ESSO0428@users.noreply.github.com> Date: Fri, 26 Apr 2024 20:02:43 +0800 Subject: [PATCH 1/5] Update core.lua (add run_cells_above support in core) --- lua/notebook-navigator/core.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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) From a4808345e44321ed36dbca99e7273c2e15efb20e Mon Sep 17 00:00:00 2001 From: ESSO0428 <92996726+ESSO0428@users.noreply.github.com> Date: Fri, 26 Apr 2024 20:03:51 +0800 Subject: [PATCH 2/5] Update init.lua (add run_cells_above support in init) --- lua/notebook-navigator/init.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 From 88f0da507dac9f03a6e218b59d209c5fc7f8a5a8 Mon Sep 17 00:00:00 2001 From: ESSO0428 <92996726+ESSO0428@users.noreply.github.com> Date: Fri, 26 Apr 2024 20:16:27 +0800 Subject: [PATCH 3/5] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ae23baf..cdb1933 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ available through leader keymaps but will turn to the Hydra head when many cells be run (just by smashing `x`) or for less commonly used functionality. ```lua { - "GCBallesteros/NotebookNavigator.nvim", + "ESSO0428/NotebookNavigator.nvim", keys = { { "]h", function() require("notebook-navigator").move_cell "d" end }, { "[h", function() require("notebook-navigator").move_cell "u" end }, @@ -88,7 +88,7 @@ look like: return { "echasnovski/mini.hipatterns", event = "VeryLazy", - dependencies = { "GCBallesteros/NotebookNavigator.nvim" }, + dependencies = { "ESSO0428/NotebookNavigator.nvim" }, opts = function() local nn = require "notebook-navigator" @@ -112,7 +112,7 @@ meant include the _code cell_ text object then your 'mini.ai' could look like: return { "echasnovski/mini.ai", event = "VeryLazy", - dependencies = { "GCBallesteros/NotebookNavigator.nvim" }, + dependencies = { "ESSO0428/NotebookNavigator.nvim" }, opts = function() local nn = require "notebook-navigator" From 8ce6692bebacb0f613cf0ee75c79d14721eea938 Mon Sep 17 00:00:00 2001 From: ESSO0428 <92996726+ESSO0428@users.noreply.github.com> Date: Fri, 26 Apr 2024 20:17:38 +0800 Subject: [PATCH 4/5] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index cdb1933..fe3e058 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,8 @@ be run (just by smashing `x`) or for less commonly used functionality. { "ESSO0428/NotebookNavigator.nvim", keys = { + { "[e", function() require("notebook-navigator").run_cells_above "" end }, + { "]e", function() require("notebook-navigator").run_cells_below "" end }, { "]h", function() require("notebook-navigator").move_cell "d" end }, { "[h", function() require("notebook-navigator").move_cell "u" end }, { "X", "lua require('notebook-navigator').run_cell()" }, From 8a4b2f8b174dab98970e1ce8af58007b34dde2b8 Mon Sep 17 00:00:00 2001 From: ESSO0428 <92996726+ESSO0428@users.noreply.github.com> Date: Fri, 24 May 2024 22:49:13 +0800 Subject: [PATCH 5/5] Update README.md --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fe3e058..4d43af8 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,8 @@ available through leader keymaps but will turn to the Hydra head when many cells be run (just by smashing `x`) or for less commonly used functionality. ```lua { - "ESSO0428/NotebookNavigator.nvim", + "GCBallesteros/NotebookNavigator.nvim", keys = { - { "[e", function() require("notebook-navigator").run_cells_above "" end }, - { "]e", function() require("notebook-navigator").run_cells_below "" end }, { "]h", function() require("notebook-navigator").move_cell "d" end }, { "[h", function() require("notebook-navigator").move_cell "u" end }, { "X", "lua require('notebook-navigator').run_cell()" }, @@ -90,7 +88,7 @@ look like: return { "echasnovski/mini.hipatterns", event = "VeryLazy", - dependencies = { "ESSO0428/NotebookNavigator.nvim" }, + dependencies = { "GCBallesteros/NotebookNavigator.nvim" }, opts = function() local nn = require "notebook-navigator" @@ -114,7 +112,7 @@ meant include the _code cell_ text object then your 'mini.ai' could look like: return { "echasnovski/mini.ai", event = "VeryLazy", - dependencies = { "ESSO0428/NotebookNavigator.nvim" }, + dependencies = { "GCBallesteros/NotebookNavigator.nvim" }, opts = function() local nn = require "notebook-navigator" @@ -225,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`.