diff --git a/README.md b/README.md index 4d43af8..bfc76fb 100644 --- a/README.md +++ b/README.md @@ -153,8 +153,9 @@ Any options that are not specified when calling `setup` will take on their defau }, -- The repl plugin with which to interface -- Current options: "iron" for iron.nvim, "toggleterm" for toggleterm.nvim, - -- "molten" for molten-nvim or "auto" which checks which of the above are + -- "molten" for molten-nvim or "auto" which checks which of the above are -- installed + -- (start_line, end_line, repl_args, cell_marker) -> boolean (success) repl_provider = "auto", -- Syntax based highlighting. If you don't want to install mini.hipattners or -- enjoy a more minimalistic look @@ -204,6 +205,8 @@ keymaps on the plugin configuration or even map them on they Hydra mode as long as you take heed of the [advice given above](#current-limitations). - `move_cell(dir)`: Move up or done a cell in the `u`p or `d`own direction. + - `D` to move to the first non-empty line of the next cell, likewise `U` + - `e` to move to the last non-empty line of the next cell, `E` for previous cell - `run_cell(repl_args)`: Run the current cell. You may optionally pass a table of `repl_args` that will be forwarded to the repl. For the details of what is forwarded exactly and how it is used check `repls.lua` and look for your repl diff --git a/doc/NotebookNavigator.txt b/doc/NotebookNavigator.txt index be37209..043a2de 100644 --- a/doc/NotebookNavigator.txt +++ b/doc/NotebookNavigator.txt @@ -184,6 +184,8 @@ Default values: -- Current options: "iron" for iron.nvim, "toggleterm" for toggleterm.nvim, -- "molten" for molten-nvim or "auto" which checks which of the above are -- installed + -- or provide a function with signature + -- (start_line, end_line, repl_args, cell_marker) -> boolean (success) repl_provider = "auto", -- Syntax based highlighting. If you don't want to install mini.hipattners or -- enjoy a more minimalistic look diff --git a/lua/notebook-navigator/core.lua b/lua/notebook-navigator/core.lua index c563c35..65e9925 100644 --- a/lua/notebook-navigator/core.lua +++ b/lua/notebook-navigator/core.lua @@ -7,17 +7,26 @@ local M = {} M.move_cell = function(dir, cell_marker) local search_res local result + local mod = dir:sub(2, 2) - if dir == "d" then + if dir == "d" or dir == "D" or dir == "e" then search_res = vim.fn.search("^" .. cell_marker, "W") if search_res == 0 then result = "last" + elseif dir == "D" then + vim.fn.search("^\\w", "W") + elseif dir == "e" then + vim.fn.search("^\\w", "bW") end else search_res = vim.fn.search("^" .. cell_marker, "bW") if search_res == 0 then result = "first" vim.api.nvim_win_set_cursor(0, { 1, 0 }) + elseif dir == "U" then + vim.fn.search("^\\w", "W") + elseif dir == "E" then + vim.fn.search("^\\w", "bW") end end @@ -125,7 +134,7 @@ M.run_all_cells = function(repl_provider, repl_args) local buf_length = vim.api.nvim_buf_line_count(0) local repl = get_repl(repl_provider) - repl(1, buf_length, repl_args) + return repl(1, buf_length, repl_args) end M.run_cells_below = function(cell_marker, repl_provider, repl_args) @@ -133,7 +142,7 @@ M.run_cells_below = function(cell_marker, repl_provider, repl_args) local cell_object = miniai_spec("i", cell_marker) local repl = get_repl(repl_provider) - repl(cell_object.from.line, buf_length, repl_args) + return repl(cell_object.from.line, buf_length, repl_args) end M.merge_cell = function(dir, cell_marker) diff --git a/lua/notebook-navigator/init.lua b/lua/notebook-navigator/init.lua index 797d291..7d4afe9 100644 --- a/lua/notebook-navigator/init.lua +++ b/lua/notebook-navigator/init.lua @@ -221,11 +221,13 @@ local function activate_hydra(config) local hydra_config = { name = "NotebookNavigator", mode = { "n" }, - config = { + config = vim.tbl_extend("force", { invoke_on_body = true, color = "pink", hint = { border = "rounded" }, - }, + buffer = config.buffer, + desc = config.desc, + }, config.hydra), body = config.activate_hydra_keys, heads = active_hydra_heads, } @@ -267,6 +269,8 @@ M.config = { -- The repl plugin with which to interface -- Current options: "iron" for iron.nvim, "toggleterm" for toggleterm.nvim, -- or "auto" which checks which of the above are installed + -- installed + -- (start_line, end_line, repl_args, cell_marker) -> boolean (success) repl_provider = "auto", -- Syntax based highlighting. If you don't want to install mini.hipattners or -- enjoy a more minimalistic look @@ -318,7 +322,9 @@ 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 type(M.config.repl_provider) == "string" + 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 diff --git a/lua/notebook-navigator/repls.lua b/lua/notebook-navigator/repls.lua index 3a22137..810daf9 100644 --- a/lua/notebook-navigator/repls.lua +++ b/lua/notebook-navigator/repls.lua @@ -70,8 +70,10 @@ local get_repl = function(repl_provider) chosen_repl = repls[r] break end - else + elseif type(repl_provider) == "string" then chosen_repl = repls[repl_provider] + elseif type(repl_provider) == "function" then + chosen_repl = repl_provider end -- Check if we actuall got out a supported repl