nvim: Do not establish quarto molten session on open

We now disable the automatic establishing of quarto molten sessions
(using the virtual environment provided python interpreter) as soon as
the file is opened since it can have some negative side-effects and also
slows down quarto file opening.
Instead, use the `JupyterStart` command to establish a jupyter session
in the correct environment and initialize a molten session.

The behaviour can be re-enabled with
`vim.g.quarto_auto_init_molten_session = true`.
This commit is contained in:
Marty Oehme 2024-07-24 14:13:01 +02:00
parent a94b1ccbb2
commit 1b4f73ae9b
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
2 changed files with 20 additions and 10 deletions

View file

@ -1,3 +1,4 @@
local default_buffer_session = function() local default_buffer_session = function()
local buffer_path = vim.api.nvim_buf_get_name(0) or vim.fn.tempname() 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 temp_path = vim.fn.stdpath("run") .. "/molten-sessions" .. buffer_path .. ".json"
@ -15,7 +16,7 @@ local startsession = function(file, args)
local path = require("core.util").get_python_venv_bin() local path = require("core.util").get_python_venv_bin()
if not path then if not path then
return return
end end
vim.g["python3_host_prog"] = path vim.g["python3_host_prog"] = path
@ -44,15 +45,18 @@ vim.api.nvim_create_user_command("JupyterStart", function()
startsession(vim.b["sessionfile"] or default_buffer_session()) startsession(vim.b["sessionfile"] or default_buffer_session())
end, {}) end, {})
vim.api.nvim_create_autocmd({"InsertEnter", "BufEnter"}, { if vim.g.quarto_auto_init_molten_session then
callback = function() vim.api.nvim_create_autocmd({ "InsertEnter", "BufEnter" }, {
if vim.b["sessionfile"] == nil then callback = function()
local path = default_buffer_session() if vim.b["sessionfile"] == nil then
vim.b["sessionfile"] = path local path = default_buffer_session()
vim.schedule_wrap(startsession(path)) vim.b["sessionfile"] = path
end vim.schedule_wrap(startsession(path))
end, end
}) end,
})
end
-- -- -- TODO find better way to enable lsp key mappings for quarto buffers -- -- -- TODO find better way to enable lsp key mappings for quarto buffers
-- -- local prefix = require("which-key").register -- -- local prefix = require("which-key").register
-- -- prefix({ ["<localleader>l"] = { name = "+lsp" } }) -- -- prefix({ ["<localleader>l"] = { name = "+lsp" } })

View file

@ -1,3 +1,9 @@
-- Change (personal) plugin options
-- mainly intended for things I have not packaged as plugin but may
-- require options to be set.
vim.g.quarto_auto_init_molten_session = false
-- Change (Neo)Vim default options
local default_builtins_disabled = { "netrw", "netrwPlugin" } local default_builtins_disabled = { "netrw", "netrwPlugin" }
local disable_builtins = function(builtins) local disable_builtins = function(builtins)
for _, plugin in pairs(builtins) do for _, plugin in pairs(builtins) do