diff --git a/nvim/.config/nvim/after/ftplugin/quarto.lua b/nvim/.config/nvim/after/ftplugin/quarto.lua index 699abc6..0f4b01a 100644 --- a/nvim/.config/nvim/after/ftplugin/quarto.lua +++ b/nvim/.config/nvim/after/ftplugin/quarto.lua @@ -1,6 +1,18 @@ +local default_buffer_session = function() + local buffer_path = vim.api.nvim_buf_get_name(0) or vim.fn.tempname() + local temp_path = vim.fn.stdpath("run") .. "/molten-sessions" .. buffer_path .. ".json" + + local dir = vim.fn.fnamemodify(temp_path, ":p:h") + if vim.fn.getftype(dir) ~= "dir" then + vim.fn.mkdir(dir, "p") + end + + return temp_path +end + -- Start quarto session local startsession = function(file, args) - file = file or "/tmp/jupyter-magma-session.json" + file = file or default_buffer_session() local path = require("util").get_python_venv() vim.g["python3_host_prog"] = path @@ -15,9 +27,8 @@ local startsession = function(file, args) vim.fn.jobstart({ "jupyter", "console", "-f", file }, { on_stdout = function(_) if not once then - vim.cmd("MoltenInit " .. file) - -- vim.cmd("JupyterAttach " .. file) - end + vim.cmd("MoltenInit " .. file) + end once = true end, on_exit = function(_) @@ -31,39 +42,63 @@ vim.api.nvim_create_user_command("JupyterStart", function() end, {}) local map = vim.keymap.set --- filetype mappings --- PLUGIN: magma-nvim --- Operate jupyter notebooks from within vim -map("n", "cc", ":MoltenEvaluateLine", { silent = true }) -map( - "n", - "C", - "?^```{jV/```k:MoltenEvaluateVisual", - { silent = true, desc = "Evaluate current code cell" } -) -map("x", "c", ":MoltenEvaluateVisual", { silent = true }) -map( - "n", - "c", - "nvim_exec('MoltenEvaluateOperator', v:true)", - { expr = true, silent = true, desc = "+code-evaluation" } -) -map("n", "cr", ":MoltenReevaluateCell", { silent = true }) -map("n", "cu", ":MoltenShowOutput", { silent = true }) -map("n", "cU", ":noautocmd :MoltenEnterOutput", { silent = true, desc = "Molten enter output" }) -map("n", "cd", ":MoltenDelete", { silent = true }) -map("n", "cs", ":MoltenInterrupt") -map("n", "ci", ":MoltenInit ") -map("n", "cD", ":MoltenDeinit") -map("n", "cR", ":MoltenRestart") --- jump to beginning of previous/ next cell code -map("n", "]c", "/^```{}:nohl", { desc = "Next quarto cell" }) -map("n", "[c", "?^```n}:nohl", { desc = "Previous quarto cell" }) --- insert cell header above/below -map("n", "co", "o```{python}```k", { desc = "Insert quarto cell below" }) -map("n", "cO", "O```{python}```k", { desc = "Insert quarto cell above" }) +local function molten_mappings_set() + -- Operate jupyter notebooks from within vim + map("n", "cc", ":MoltenEvaluateLine", { silent = true }) + map( + "n", + "C", + require("quarto.runner").run_cell, + { silent = true, desc = "Evaluate current code cell" } + ) + map("x", "c", ":MoltenEvaluateVisual", { silent = true }) + map( + "n", + "c", + "nvim_exec('MoltenEvaluateOperator', v:true)", + { expr = true, silent = true, desc = "+code-evaluation" } + ) + map("n", "cr", ":MoltenReevaluateCell", { silent = true }) + map("n", "cu", ":MoltenShowOutput", { silent = true }) + map("n", "cU", ":noautocmd :MoltenEnterOutput", { silent = true, desc = "Molten enter output" }) + map("n", "cd", ":MoltenDelete", { silent = true }) + map("n", "ci", ":MoltenInterrupt") + map("n", "cI", ":MoltenInfo") + map("n", "cN", ":MoltenInit ") + map("n", "cD", ":MoltenDeinit") + map("n", "cR", ":MoltenRestart") + map( + "n", + "cA", + require("quarto.runner").run_all, + { silent = true, desc = "Evaluate all code cells" } + ) + map( + "n", + "ca", + require("quarto.runner").run_above, + { silent = true, desc = "Evaluate cells above current" } + ) + map( + "n", + "cb", + require("quarto.runner").run_below, + { silent = true, desc = "Evaluate cells below current" } + ) + -- jump to beginning of previous/ next cell code + map("n", "]c", "/^```{}:nohl", { desc = "Next quarto cell" }) + map("n", "[c", "?^```n}:nohl", { desc = "Previous quarto cell" }) + -- insert cell header above/below + map("n", "co", "o```{python}```k", { desc = "Insert quarto cell below" }) + map("n", "cO", "O```{python}```k", { desc = "Insert quarto cell above" }) +end + +vim.api.nvim_create_autocmd("User", { + pattern = "MoltenInitPost", + callback = molten_mappings_set, +}) local bufnr = 0 map("n", "[d", "lua vim.diagnostic.goto_prev()", { buffer = bufnr, desc = "Previous diagnostic" }) map("n", "]d", "lua vim.diagnostic.goto_next()", { buffer = bufnr, desc = "Next diagnostic" }) @@ -97,6 +132,7 @@ map("n", "gI", "lua vim.lsp.buf.implementation()", { buffer = bufnr, de map("n", "gt", "lua vim.lsp.buf.type_definition()", { buffer = bufnr, desc = "Type definition" }) if vim.b["sessionfile"] == nil then - vim.b["sessionfile"] = vim.fn.tempname() .. ".json" - startsession(vim.b["sessionfile"]) + local path = default_buffer_session() + vim.b["sessionfile"] = path + vim.schedule_wrap(startsession(path)) end diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index a3ea645..9b86faa 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -32,7 +32,6 @@ "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" }, diff --git a/nvim/.config/nvim/lua/core/mappings.lua b/nvim/.config/nvim/lua/core/mappings.lua index 34dfeba..6278326 100644 --- a/nvim/.config/nvim/lua/core/mappings.lua +++ b/nvim/.config/nvim/lua/core/mappings.lua @@ -195,19 +195,21 @@ map("n", "ZD", ":setlocal spell! spelllang=de_de", { desc = "To map("i", "", "u[s1z=`]au") map("n", "z", "ms[s1z=`s", { desc = "Fix last spell error" }) +prefix({ ["s"] = { name = "+show" } }) -- Set vim to distraction free prose mode map("n", "sz", ":ZenMode", { silent = true }) -- PLUGIN: mini.nvim -prefix({ ["s"] = { name = "+show" } }) -map("n", "sm", ":lua MiniMap.toggle()", { silent = true, desc = "toggle minimap" }) -map("n", "ss", ":lua MiniStarter.open()", { desc = "show startpage" }) +map("n", "sm", ":lua MiniMap.toggle()", { silent = true, desc = "minimap" }) +map("n", "ss", ":lua MiniStarter.open()", { desc = "startpage" }) -- PLUGIN: symbols-outline.nvim -map("n", "so", "AerialToggle", { silent = true, desc = "toggle symbol outline" }) -map("n", "sn", "AerialNavToggle", { silent = true, desc = "toggle symbol navigator" }) +map("n", "so", "AerialNavToggle", { silent = true, desc = "symbol navigator" }) +map("n", "sO", "AerialToggle", { silent = true, desc = "symbol outline" }) + +-- PLUGIN: nvim-tree +map("n", "se", "NvimTreeToggle", { silent = true, desc = "filetree" }) -- PLUGIN: nvim-tree -map("n", "se", "NvimTreeToggle", { silent = true, desc = "toggle filetree" }) map("n", "sd", "Trouble workspace_diagnostics", { silent = true, desc = "diagnostics workspace" }) map("n", "sD", "Trouble document_diagnostics", { silent = true, desc = "diagnostics document" }) @@ -257,11 +259,10 @@ map("v", "nf", ":ZkMatch", { desc = "find note from selection" -- PLUGIN: toggleterm.nvim -- create a lazygit or python window, set up in toggleterm settings -- TODO create ability to go into python environment when in poetry venv and/or euporie/jupyter notebook -prefix({ ["t"] = { name = "+term" } }) -map("n", "tg", ":Lazygit") -map("n", "tG", ":Lazygit!") -map("n", "tp", ":Pythonterm") -map("n", "tP", ":Pythonterm!") +map("n", "sg", ":Lazygit") +map("n", "sG", ":Lazygit!") +map("n", "sp", ":Pythonterm") +map("n", "sP", ":Pythonterm!") prefix({ ["s"] = { name = "+set" } }) -- PLUGIN: wrapping.nvim diff --git a/nvim/.config/nvim/lua/plugins/data_analysis.lua b/nvim/.config/nvim/lua/plugins/data_analysis.lua index 40816b7..e0a0225 100644 --- a/nvim/.config/nvim/lua/plugins/data_analysis.lua +++ b/nvim/.config/nvim/lua/plugins/data_analysis.lua @@ -12,31 +12,20 @@ return { require("quarto").setup({ lspFeatures = { enabled = true, - languages = { "r", "python", "julia" }, - diagnostics = { enabled = true, triggers = { "BufWrite" } }, + languages = { "r", "python", "julia", "bash" }, + diagnostics = { enabled = true, triggers = { "BufWritePost" } }, completion = { enabled = true }, }, + codeRunner = { + enabled = true, + default_method = "molten", + }, }) end, lazy = false, ft = "quarto", }, - { - "lkhphuc/jupyter-kernel.nvim", - config = true, - cmd = "JupyterAttach", - build = ":UpdateRemotePlugins", - keys = { - { - "ck", - "JupyterInspect", - desc = "Inspect object in kernel", - }, - }, - lazy = false, - }, - -- REPL work { "3rd/image.nvim", @@ -62,7 +51,7 @@ return { "benlubas/molten-nvim", build = ":UpdateRemotePlugins", config = function() - vim.g.molten_image_provider = "image_nvim" + vim.g.molten_image_provider = "none" -- image integration does NOT work currently :-( vim.g.molten_auto_open_output = false end, cmd = {