nvim: Add molten and image.nvim plugins

Image nvim works mostly well (slow on wezterm but that will always be the case
with kitty protocol for now as far as I know).
Would love to be able to toggle images on/off dynamically but I don't see a
way to accomplish that now. (or really, get to any option of the plugin).

Molten itself also works well - the output is displayed more nicely than for
the Magma plugins and everything continues working mostly well (or rather,
just as wonky as I had it set up on my older magma install :)

For now, the molten - image.nvim integration seems to not work at all -
it simply errors out when it would produce an image as output. No clue why
and it also complains about the wrong image provider (which I have taken from
the molten readme). No time to bugfix now but maybe at some point.

To do - find a much better way of installing the image.nvim required
luarock magick - done manually with hardcoded path in setup now

Also extended the old `py` alias to a full-blown script which will in
addition to detecting the python repl also find any running molten
session for the current directory (i.e. any running jupy kernel) and let
the user choose the right one if there is multiple. Will then default to
starting a kernel-aware repl environment (euporia or jupyter-console).

Added a very simple `-c` option which lets you choose python command to
run manually.
This commit is contained in:
Marty Oehme 2023-12-05 21:24:33 +01:00
parent 297f2c87a3
commit c487da69a8
Signed by: Marty
GPG Key ID: EDBF2ED917B2EF6A
5 changed files with 114 additions and 40 deletions

View File

@ -11,10 +11,14 @@ local startsession = function(file, args)
if args then
file = args[0]
end
local once = false
vim.fn.jobstart({ "jupyter", "console", "-f", file }, {
on_stdout = function(_)
vim.cmd("MagmaInit " .. file)
vim.cmd("JupyterAttach " .. file)
if not once then
vim.cmd("MoltenInit " .. file)
-- vim.cmd("JupyterAttach " .. file)
end
once = true
end,
on_exit = function(_)
vim.notify(string.format("jupyter kernel stopped: %s", file), vim.log.levels.INFO)
@ -30,28 +34,28 @@ local map = vim.keymap.set
-- filetype mappings
-- PLUGIN: magma-nvim
-- Operate jupyter notebooks from within vim
map("n", "<localleader>cc", ":MagmaEvaluateLine<cr>", { silent = true })
map("n", "<localleader>cc", ":MoltenEvaluateLine<cr>", { silent = true })
map(
"n",
"<localleader>C",
"?^```{<cr>jV/```<cr>k:<C-u>MagmaEvaluateVisual<cr>",
"?^```{<cr>jV/```<cr>k:<C-u>MoltenEvaluateVisual<cr>",
{ silent = true, desc = "Evaluate current code cell" }
)
map("x", "<localleader>c", ":<C-u>MagmaEvaluateVisual<cr>", { silent = true })
map("x", "<localleader>c", ":<C-u>MoltenEvaluateVisual<cr>", { silent = true })
map(
"n",
"<localleader>c",
"nvim_exec('MagmaEvaluateOperator', v:true)",
"nvim_exec('MoltenEvaluateOperator', v:true)",
{ expr = true, silent = true, desc = "+code-evaluation" }
)
map("n", "<localleader>cr", ":MagmaReevaluateCell<cr>", { silent = true })
map("n", "<localleader>cu", ":MagmaShowOutput<cr>", { silent = true })
map("n", "<localleader>cU", ":noautocmd :MagmaEnterOutput<cr>", { silent = true, desc = "MagmaEnterOutput" })
map("n", "<localleader>cd", ":MagmaDelete<cr>", { silent = true })
map("n", "<localleader>cs", ":MagmaInterrupt<cr>")
map("n", "<localleader>ci", ":MagmaInit ")
map("n", "<localleader>cD", ":MagmaDeinit<cr>")
map("n", "<localleader>cR", ":MagmaRestart<cr>")
map("n", "<localleader>cr", ":MoltenReevaluateCell<cr>", { silent = true })
map("n", "<localleader>cu", ":MoltenShowOutput<cr>", { silent = true })
map("n", "<localleader>cU", ":noautocmd :MoltenEnterOutput<cr>", { silent = true, desc = "Molten enter output" })
map("n", "<localleader>cd", ":MoltenDelete<cr>", { silent = true })
map("n", "<localleader>cs", ":MoltenInterrupt<cr>")
map("n", "<localleader>ci", ":MoltenInit ")
map("n", "<localleader>cD", ":MoltenDeinit<cr>")
map("n", "<localleader>cR", ":MoltenRestart<cr>")
-- jump to beginning of previous/ next cell code
map("n", "]c", "/^```{<cr>}:nohl<cr>", { desc = "Next quarto cell" })

View File

@ -31,12 +31,12 @@
"git-conflict.nvim": { "branch": "main", "commit": "4e0191c9a0ae05d7fbdcdc7f15cd358f56d23bfb" },
"gitsigns.nvim": { "branch": "main", "commit": "6ef8c54fb526bf3a0bc4efb0b2fe8e6d9a7daed2" },
"headlines.nvim": { "branch": "master", "commit": "e3d7bfdf40e41a020d966d35f8b48d75b90367d2" },
"image.nvim": { "branch": "master", "commit": "c40215d7d7d1d8c823ee9a77be1a894d5c8df41b" },
"jupyter-kernel.nvim": { "branch": "main", "commit": "5772fa8932f2c73736a777082656f1bfe0287076" },
"lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" },
"lightspeed.nvim": { "branch": "main", "commit": "fcc72d8a4d5f4ebba62d8a3a0660f88f1b5c3b05" },
"lsp-setup.nvim": { "branch": "main", "commit": "7276e54faf4af909b6ea171975fd4179ebe65cec" },
"lualine.nvim": { "branch": "master", "commit": "2248ef254d0a1488a72041cfb45ca9caada6d994" },
"magma-nvim-goose": { "branch": "main", "commit": "9a626aab63361d027541d023707f82e28d7f872c" },
"markdown-preview.nvim": { "branch": "master", "commit": "9becceee5740b7db6914da87358a183ad11b2049" },
"markmap.nvim": { "branch": "main", "commit": "3befc2a54c2448a16c30c1c7762aab263f22946a" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "4eb8e15e3c0757303d4c6dea64d2981fc679e990" },
@ -44,6 +44,7 @@
"mason.nvim": { "branch": "main", "commit": "41e75af1f578e55ba050c863587cffde3556ffa6" },
"mdeval.nvim": { "branch": "master", "commit": "2654caf8ecaad702b50199d18e39cff23d81e0ba" },
"mini.nvim": { "branch": "main", "commit": "b5645ac6eefce8e7af9d7dd4e5e296a81cba8a10" },
"molten-nvim": { "branch": "main", "commit": "93f2f168e77cbd82a881e07030cdbd45a48ed070" },
"neotest": { "branch": "master", "commit": "009328955066ae6c170d24bb0de5f168d8760ff8" },
"neotest-python": { "branch": "master", "commit": "81d2265efac717bb567bc15cc652ae10801286b3" },
"null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" },

View File

@ -39,24 +39,59 @@ return {
-- REPL work
{
"WhiteBlackGoose/magma-nvim-goose",
"3rd/image.nvim",
config = function()
-- Example for configuring Neovim to load user-installed installed Lua rocks:
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?/init.lua;"
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?.lua;"
require("image").setup({
backend = "kitty",
integrations = {
markdown = {
enabled = true,
download_remote_images = true,
only_render_image_at_cursor = false,
filetypes = { "markdown", "vimwiki", "quarto" },
},
},
})
end,
lazy = false,
},
{
"benlubas/molten-nvim",
build = ":UpdateRemotePlugins",
config = function()
vim.g.magma_image_provider = "kitty"
vim.g.magma_automatically_open_output = false
vim.g.molten_image_provider = "image_nvim"
vim.g.molten_auto_open_output = false
end,
cmd = {
"MagmaInit",
"MagmaEvaluateOperator",
"MagmaEvaluateLine",
"MagmaEvaluateVisual",
"MagmaRestart",
"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,
},
-- MARKDOWN ONLY
-- MARKDOWN ONLY
-- Evaluate markdown code blocks
{
"jubnzv/mdeval.nvim",
@ -71,11 +106,11 @@ return {
lazy = false,
},
{
"AckslD/nvim-FeMaco.lua",
cmd = {
"FeMaco"
},
ft = { "markdown" },
config = true
}
"AckslD/nvim-FeMaco.lua",
cmd = {
"FeMaco",
},
ft = { "markdown" },
config = true,
},
}

43
scripts/.local/bin/py Executable file
View File

@ -0,0 +1,43 @@
#!/usr/bin/env bash
molten_session_dir="/run/user/$UID/molten-sessions"
cur_dir=$(pwd)
search_dir="${molten_session_dir}${cur_dir}"
if [ "$1" == "-c" ]; then
cmd=$(echo -e "euporie-console\njupyter-console\nptipython\nipython\npython" | fzf)
fi
# set normal command first
if [ -z "$cmd" ]; then
if exist ptipython; then
cmd=ptipython
elif exist ipython; then
cmd=ipython
elif exist python; then
cmd=python
else
echo "No python found on system, please install." 1>&2
exit 1
fi
fi
# search for molten session for current dir
if [ -n "$(ls -A "${search_dir}" 2>/dev/null)" ]; then
res=$(find "$search_dir" -maxdepth 1 -type f -name "*.json")
if [ "$(echo "$res" | wc -l)" -gt 1 ]; then
session=$(echo "$res" | fzf --prompt "Molten session> ")
fi
fi
# attach to kernel
if [ -n "${session}" ]; then
if exist euporie-console || [ "$cmd" == "euporie-console" ]; then
euporie-console --edit-mode vi --connection-file "$session"
elif exist jupyter-console || [ "$cmd" == "jupyter-console" ]; then
jupyter-console --existing "$session"
fi
# or just run normal python
else
$cmd
fi

View File

@ -106,15 +106,6 @@ else
done
fi
# python
if exist ptipython; then
alias py=ptipython
elif exist ipython; then
alias py=ipython
elif exist python; then
alias py=python
fi
# distrobox
if exist distrobox; then
alias db=distrobox