diff --git a/docs/Notebook-Setup.md b/docs/Notebook-Setup.md index b534033..e244d94 100644 --- a/docs/Notebook-Setup.md +++ b/docs/Notebook-Setup.md @@ -276,23 +276,25 @@ We can make importing/exporting outputs seamless with a few autocommands: -- tries to find a kernel that matches the kernel in the jupyter notebook -- falls back to a kernel that matches the name of the active venv (if any) local imb = function(e) -- init molten buffer - local kernels = vim.fn.MoltenAvailableKernels() - local try_kernel_name = function() - local metadata = vim.json.decode(io.open(e.file, "r"):read("a"))["metadata"] - return metadata.kernelspec.name - end - local ok, kernel_name = pcall(try_kernel_name) - if not ok or not vim.tbl_contains(kernels, kernel_name) then - kernel_name = nil - local venv = os.getenv("VIRTUAL_ENV") - if venv ~= nil then - kernel_name = string.match(venv, "/.+/(.+)") + vim.schedule(function() + local kernels = vim.fn.MoltenAvailableKernels() + local try_kernel_name = function() + local metadata = vim.json.decode(io.open(e.file, "r"):read("a"))["metadata"] + return metadata.kernelspec.name end - end - if kernel_name ~= nil and vim.tbl_contains(kernels, kernel_name) then - vim.cmd(("MoltenInit %s"):format(kernel_name)) - end - vim.cmd("MoltenImportOutput") + local ok, kernel_name = pcall(try_kernel_name) + if not ok or not vim.tbl_contains(kernels, kernel_name) then + kernel_name = nil + local venv = os.getenv("VIRTUAL_ENV") + if venv ~= nil then + kernel_name = string.match(venv, "/.+/(.+)") + end + end + if kernel_name ~= nil and vim.tbl_contains(kernels, kernel_name) then + vim.cmd(("MoltenInit %s"):format(kernel_name)) + end + vim.cmd("MoltenImportOutput") + end) end -- automatically import output chunks from a jupyter notebook