nvim: Set up molten for interactive python repl

Set it up with extended options and keymaps. Will use an image provider
if it has been set externally (usually set by the 'image.nvim' setup
routine) or fall back to use the `wezterm.nvim` plugin to display it in
a wezterm pane. This display can be a little buggy so we should prefer
others.
This commit is contained in:
Marty Oehme 2024-06-16 21:29:34 +02:00
parent 63dc6fb888
commit e25aedd94b
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -50,7 +50,6 @@ return {
ft = { "quarto" }, ft = { "quarto" },
}, },
-- REPL work
{ {
"3rd/image.nvim", "3rd/image.nvim",
config = function() config = function()
@ -71,41 +70,105 @@ return {
end, end,
ft = { "markdown", "vimwiki", "quarto" }, ft = { "markdown", "vimwiki", "quarto" },
}, },
-- REPL work
{ {
"benlubas/molten-nvim", "benlubas/molten-nvim",
dependencies = {
{ "willothy/wezterm.nvim", config = true },
{ "3rd/image.nvim", optional = true },
},
build = ":UpdateRemotePlugins", build = ":UpdateRemotePlugins",
config = function() config = function()
vim.g.molten_image_provider = "none" -- image integration does NOT work currently :-( vim.g.molten_image_provider = vim.g.molten_image_provider or "wezterm"
vim.g.molten_auto_open_output = false vim.g.molten_auto_open_output = false
vim.g.molten_virt_text_output = true
if vim.fn.has("nvim-0.10") then
vim.g.molten_output_show_more = true
end
vim.api.nvim_create_autocmd("User", {
pattern = "MoltenInitPost",
callback = function()
local map = vim.keymap.set
if require("core.util").is_available("which-key") then
require("which-key").register({ ["<localleader>c"] = { name = "+codecells" } })
end
-- Operate jupyter notebooks from within vim
map(
"n",
"<localleader>cc",
":MoltenEvaluateOperator<cr>",
{ desc = "evaluate operator", silent = true }
)
map("n", "<localleader>cl", ":MoltenEvaluateLine<cr>", { desc = "evaluate line", silent = true })
map(
"x",
"<localleader>c",
":<C-u>MoltenEvaluateVisual<cr>",
{ desc = "evaluate visual", silent = true }
)
map(
"n",
"<localleader>cr",
":MoltenReevaluateCell<cr>",
{ desc = "reevaluate cell", silent = true }
)
map(
"n",
"<localleader>cp",
":noautocmd :MoltenEnterOutput<cr>",
{ silent = true, desc = "show output" }
)
map("n", "<localleader>cP", function()
vim.cmd("MoltenHideOutput")
vim.cmd("MoltenDelete")
end, { silent = true, desc = "hide output" })
map("n", "<localleader>co", ":MoltenImagePopup<cr>", { silent = true, desc = "open image" })
map("n", "<localleader>ci", ":MoltenInterrupt<cr>", { desc = "interrupt cell", silent = true })
map("n", "<localleader>cD", ":MoltenDeinit<cr>", { desc = "de-init molten", silent = true })
map("n", "<localleader>cR", ":MoltenRestart<cr>", { desc = "restart molten", silent = true })
-- FIXME: Works for toggling TO virt text but not back
local function toggle_virtual_text_output()
if vim.g.molten_virt_text_output then
vim.fn.MoltenUpdateOption("molten_virt_text_output", false)
return
end
vim.fn.MoltenUpdateOption("molten_virt_text_output", true)
end
map(
"n",
"<localleader>cV",
toggle_virtual_text_output,
{ desc = "toggle virtual output", silent = true }
)
end, end,
cmd = { })
"MoltenInfo", vim.api.nvim_create_autocmd("User", {
"MoltenInit", pattern = "MoltenDeinitPost",
"MoltenDeinit", callback = function()
"MoltenGoto", local unmap = require("core.util").unmap_key
"MoltenNext", unmap("<localleader>cc")
"MoltenPrev", unmap("<localleader>cl")
"MoltenEvaluateLine", unmap("<localleader>c", "x")
"MoltenEvaluateVisual", unmap("<localleader>cr")
"MoltenEvaluateOperator", unmap("<localleader>cR")
"MoltenEvaluateArgument", unmap("<localleader>cp")
"MoltenReevaluateCell", unmap("<localleader>cP")
"MoltenDelete", unmap("<localleader>co")
"MoltenShowOutput", unmap("<localleader>cD")
"MoltenHideOutput", unmap("<localleader>ci")
"MoltenEnterOutput", unmap("<localleader>cV")
"MoltenInterrupt", local map = vim.keymap.set
"MoltenRestart", map("n", "<localleader>cI", ":MoltenInit<cr>", { desc = "init molten", silent = true })
"MoltenSave", end,
"MoltenLoad", })
"MoltenExportOutput", end,
}, ft = { "norg", "quarto", "python" },
ft = { "quarto", "python" },
lazy = false,
keys = { keys = {
{ "<leader>vn", ":MoltenInfo<cr>" }, { "<leader>vn", ":MoltenInfo<cr>" },
{ "<localleader>ci", ":MoltenInit<cr>" },
}, },
}, },
-- Edit code blocks in md/quarto using whatever language is -- Edit code blocks in md/quarto using whatever language is
{ {
"AckslD/nvim-FeMaco.lua", "AckslD/nvim-FeMaco.lua",