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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions doc/NotebookNavigator.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions lua/notebook-navigator/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -125,15 +134,15 @@ 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)
local buf_length = vim.api.nvim_buf_line_count(0)
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)
Expand Down
12 changes: 9 additions & 3 deletions lua/notebook-navigator/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lua/notebook-navigator/repls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down