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" },
},
-- REPL work
{
"3rd/image.nvim",
config = function()
@ -71,41 +70,105 @@ return {
end,
ft = { "markdown", "vimwiki", "quarto" },
},
-- REPL work
{
"benlubas/molten-nvim",
dependencies = {
{ "willothy/wezterm.nvim", config = true },
{ "3rd/image.nvim", optional = true },
},
build = ":UpdateRemotePlugins",
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_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,
})
vim.api.nvim_create_autocmd("User", {
pattern = "MoltenDeinitPost",
callback = function()
local unmap = require("core.util").unmap_key
unmap("<localleader>cc")
unmap("<localleader>cl")
unmap("<localleader>c", "x")
unmap("<localleader>cr")
unmap("<localleader>cR")
unmap("<localleader>cp")
unmap("<localleader>cP")
unmap("<localleader>co")
unmap("<localleader>cD")
unmap("<localleader>ci")
unmap("<localleader>cV")
local map = vim.keymap.set
map("n", "<localleader>cI", ":MoltenInit<cr>", { desc = "init molten", silent = true })
end,
})
end,
cmd = {
"MoltenInfo",
"MoltenInit",
"MoltenDeinit",
"MoltenGoto",
"MoltenNext",
"MoltenPrev",
"MoltenEvaluateLine",
"MoltenEvaluateVisual",
"MoltenEvaluateOperator",
"MoltenEvaluateArgument",
"MoltenReevaluateCell",
"MoltenDelete",
"MoltenShowOutput",
"MoltenHideOutput",
"MoltenEnterOutput",
"MoltenInterrupt",
"MoltenRestart",
"MoltenSave",
"MoltenLoad",
"MoltenExportOutput",
},
ft = { "quarto", "python" },
lazy = false,
ft = { "norg", "quarto", "python" },
keys = {
{ "<leader>vn", ":MoltenInfo<cr>" },
{ "<localleader>ci", ":MoltenInit<cr>" },
},
},
-- Edit code blocks in md/quarto using whatever language is
{
"AckslD/nvim-FeMaco.lua",