nvim: Add quarto filetype setup

This commit is contained in:
Marty Oehme 2023-03-01 17:39:03 +01:00
parent c75b7636e0
commit 7128edc57c
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
3 changed files with 108 additions and 28 deletions

View file

@ -0,0 +1,94 @@
-- Start quarto session
local startsession = function(file, args)
file = file or "/tmp/jupyter-magma-session.json"
if args then file = args[0] end
vim.fn.jobstart({ "jupyter", "console", "-f", file }, {
on_stdout = function(_)
vim.cmd("MagmaInit " .. file)
vim.cmd("JupyterAttach " .. file)
end,
on_exit = function(_)
vim.notify(string.format("jupyter kernel stopped: %s", file), vim.log.levels.INFO)
end,
stdin = nil
})
end
vim.api.nvim_create_user_command("JupyterStart", function() startsession() end,
{})
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>C', '?^```{<cr>jV/```<cr>k:<C-u>MagmaEvaluateVisual<cr>',
{ silent = true, desc = 'Evaluate current code cell' })
map('x', '<localleader>c', ':<C-u>MagmaEvaluateVisual<cr>', { silent = true })
map('n', '<localleader>c', "nvim_exec('MagmaEvaluateOperator', 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>')
-- jump to beginning of previous/ next cell code
map('n', ']c', '/^```{<cr>}:nohl<cr>', { desc = 'Next quarto cell' })
map('n', '[c', '?^```<cr>n}:nohl<cr>', { desc = 'Previous quarto cell' })
-- insert cell header above/below
map('n', '<localleader>co', 'o```{python}<cr><cr>```<esc>k',
{ desc = 'Insert quarto cell below' })
map('n', '<localleader>cO', 'O```{python}<cr><cr>```<esc>k',
{ desc = 'Insert quarto cell above' })
local bufnr = 0
map('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>',
{ buffer = bufnr, desc = 'Previous diagnostic' })
map('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>',
{ buffer = bufnr, desc = 'Next diagnostic' })
map('n', '[e',
'<cmd>lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR})<cr>',
{ buffer = bufnr, desc = 'Previous error' })
map('n', ']e',
'<cmd>lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR})<cr>',
{ buffer = bufnr, desc = 'Next error' })
-- TODO find better way to enable lsp key mappings for quarto buffers
local prefix = require('which-key').register
prefix({ ['<localleader>l'] = { name = "+lsp" } })
map('n', '<localleader>li', '<cmd>LspInfo<cr>',
{ buffer = bufnr, desc = 'Lsp Info' })
map('n', '<localleader>ld', '<cmd>lua vim.diagnostic.open_float()<cr>',
{ buffer = bufnr, desc = 'Line diagnostics' })
map('n', '<localleader>la', '<cmd>lua vim.lsp.buf.code_action()<cr>',
{ buffer = bufnr, desc = 'Codeactions' })
map('n', '<localleader>ln', '<cmd>lua vim.lsp.buf.rename()<cr>',
{ buffer = bufnr, desc = 'Rename element' })
map('n', '<localleader>lr', '<cmd>lua vim.lsp.buf.references()<cr>',
{ buffer = bufnr, desc = 'References' })
if client and client.server_capabilities.document_formatting then
map('n', '<localleader>lf', "<cmd>lua vim.lsp.buf.formatting()<CR>",
{ buffer = bufnr, desc = 'Format document' })
end
map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>',
{ buffer = bufnr, desc = 'Hover definition' })
map('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>',
{ buffer = bufnr, desc = 'Definition' })
map('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>',
{ buffer = bufnr, desc = 'Declaration' })
map('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>',
{ buffer = bufnr, desc = 'Signature help' })
map('n', 'gI', '<cmd>lua vim.lsp.buf.implementation()<cr>',
{ buffer = bufnr, desc = 'Implementation' })
map('n', 'gt', '<cmd>lua vim.lsp.buf.type_definition()<cr>',
{ buffer = bufnr, desc = 'Type definition' })
if vim.b['sessionfile'] == nil then
vim.b['sessionfile'] = vim.fn.tempname() .. '.json'
startsession(vim.b['sessionfile'])
end

View file

@ -240,30 +240,3 @@ map('n', '<leader>ww', [[:lua require 'zettelkasten'.index_open()<cr> ]],
-- PLUGIN: toggleterm.nvim
-- create a lazygit window, set up in toggleterm settings
map('n', '<leader>G', ':Lazygit<cr>')
-- PLUGIN: magma-nvim
-- Operate jupyter notebooks from within vim
map('n', '<localleader>mm', ':MagmaEvaluateLine<cr>', { silent = true })
map('n', '<localleader>M', '?^```{<cr>jV/```<cr>k:<C-u>MagmaEvaluateVisual<cr>',
{ silent = true, desc = 'Evaluate current quarto cell' })
map('x', '<localleader>m', ':<C-u>MagmaEvaluateVisual<cr>', { silent = true })
map('n', '<localleader>m', "nvim_exec('MagmaEvaluateOperator', v:true)",
{ expr = true, silent = true })
map('n', '<localleader>mr', ':MagmaReevaluateCell<cr>', { silent = true })
map('n', '<localleader>ma', ':MagmaShowOutput<cr>', { silent = true })
map('n', '<localleader>mq', ':noautocmd :MagmaEnterOutput<cr>',
{ silent = true, desc = 'MagmaEnterOutput' })
map('n', '<localleader>md', ':MagmaDelete<cr>', { silent = true })
map('n', '<localleader>ms', ':MagmaInterrupt<cr>')
map('n', '<localleader>mI', ':MagmaInit ')
map('n', '<localleader>mD', ':MagmaDeinit<cr>')
map('n', '<localleader>mR', ':MagmaRestart<cr>')
-- jump to beginning of previous/ next cell code
map('n', ']c', '/^```{<cr>}:nohl<cr>', { desc = 'Next quarto cell' })
map('n', '[c', '?^```<cr>n}:nohl<cr>', { desc = 'Previous quarto cell' })
-- insert cell header above/below
map('n', '<localleader>mo', 'o```{python}<cr><cr>```<esc>k',
{ desc = 'Insert quarto cell below' })
map('n', '<localleader>mO', 'O```{python}<cr><cr>```<esc>k',
{ desc = 'Insert quarto cell above' })

View file

@ -87,6 +87,18 @@ return {
}
end,
ft = "quarto"
}, {
"lkhphuc/jupyter-kernel.nvim",
config = true,
cmd = "JupyterAttach",
build = ":UpdateRemotePlugins",
keys = {
{
"<localleader>ck",
"<Cmd>JupyterInspect<CR>",
desc = "Inspect object in kernel"
}
}
}, { 'micarmst/vim-spellsync', event = "VeryLazy" }, -- personal dict improvements for git sync
{ 'folke/zen-mode.nvim', config = true, event = "VeryLazy" }, -- provide distraction free writing
{ 'folke/twilight.nvim', event = "VeryLazy" }, -- provide even distraction free-er writing (lowlight paragraphs)
@ -137,7 +149,8 @@ return {
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
config = function() require('plug._treesitter') end
}, { 'nvim-treesitter/playground', cmd = "TSPlaygroundToggle" }, -- interactively view and query the treesitter tree
},
{ 'nvim-treesitter/playground', cmd = "TSPlaygroundToggle" }, -- interactively view and query the treesitter tree
{ 'romgrk/nvim-treesitter-context', event = "BufReadPre", config = true }, -- show current cursor context at top of buffer
{
'RRethy/nvim-treesitter-textsubjects', -- allows using . and ; to target treesitter branches