Skip to content

Commit

Permalink
refactor(modules): refactore plugins for quarto
Browse files Browse the repository at this point in the history
into sensible modules
  • Loading branch information
jmbuhr committed Apr 4, 2024
1 parent 6464e7f commit cb3e80b
Show file tree
Hide file tree
Showing 6 changed files with 579 additions and 574 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ https://youtube.com/playlist?list=PLabWm-zCaD1axcMGvf7wFxJz8FZmyHSJ7
Clone this repo into `~/.config/nvim/` or copy-paste just the parts you like.

If you already have your own configuration, check out `lua/plugins/quarto.lua`
for the configuration of all plugins directly relevant to your Quarto experience.
for the configuration of plugins directly relevant to your Quarto experience.
The comments in this file will also point to to other plugins required for
the full functionality.

This configuration can make use of a "Nerd Font" for icons and symbols.
Download one here: <https://www.nerdfonts.com/> and set it as your terminal font.
Expand Down Expand Up @@ -48,10 +50,8 @@ rm -r ~/.local/state/nvim

## Screenshots

![image](https://user-images.githubusercontent.com/17450586/210392216-a99815ac-1872-4c48-bf24-5a50df14c6d2.png)
![image](https://user-images.githubusercontent.com/17450586/210392419-3ee2b3e3-e805-4e36-99ab-6922abe3a66b.png)
![image](https://user-images.githubusercontent.com/17450586/210392573-57c0ad1c-5db0-4f2a-9119-608bd2398494.png)
![image](https://user-images.githubusercontent.com/17450586/210392838-1c643a65-e792-4a54-bbdb-3ae959995a79.png)

Use the integrated neovim terminal to execute code chunks:

Expand Down
177 changes: 177 additions & 0 deletions lua/plugins/completion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
return {
{
'windwp/nvim-autopairs',
config = function()
require('nvim-autopairs').setup {}
require('nvim-autopairs').remove_rule '`'
end,
},

{ -- completion
'hrsh7th/nvim-cmp',
event = 'InsertEnter',
dependencies = {
{ 'hrsh7th/cmp-nvim-lsp' },
{ 'hrsh7th/cmp-nvim-lsp-signature-help' },
{ 'hrsh7th/cmp-buffer' },
{ 'hrsh7th/cmp-path' },
{ 'hrsh7th/cmp-calc' },
{ 'hrsh7th/cmp-emoji' },
{ 'saadparwaiz1/cmp_luasnip' },
{ 'f3fora/cmp-spell' },
{ 'ray-x/cmp-treesitter' },
{ 'kdheepak/cmp-latex-symbols' },
{ 'jmbuhr/cmp-pandoc-references' },
{ 'L3MON4D3/LuaSnip' },
{ 'rafamadriz/friendly-snippets' },
{ 'onsails/lspkind-nvim' },
},
config = function()
local cmp = require 'cmp'
local luasnip = require 'luasnip'
local lspkind = require 'lspkind'

local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil
end

cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
completion = { completeopt = 'menu,menuone,noinsert' },
mapping = {
['<C-f>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),

['<C-n>'] = cmp.mapping(function(fallback)
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
fallback()
end
end, { 'i', 's' }),
['<C-p>'] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
['<C-e>'] = cmp.mapping.abort(),
['<c-y>'] = cmp.mapping.confirm {
select = true,
},
['<CR>'] = cmp.mapping.confirm {
select = true,
},

['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { 'i', 's' }),

['<C-l>'] = cmp.mapping(function()
if luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
end
end, { 'i', 's' }),
['<C-h>'] = cmp.mapping(function()
if luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
end
end, { 'i', 's' }),
},
autocomplete = false,

---@diagnostic disable-next-line: missing-fields
formatting = {
format = lspkind.cmp_format {
mode = 'symbol',
menu = {
otter = '[🦦]',
nvim_lsp = '[LSP]',
luasnip = '[snip]',
buffer = '[buf]',
path = '[path]',
spell = '[spell]',
pandoc_references = '[ref]',
tags = '[tag]',
treesitter = '[TS]',
calc = '[calc]',
latex_symbols = '[tex]',
emoji = '[emoji]',
},
},
},
sources = {
{ name = 'otter' }, -- for code chunks in quarto
{ name = 'path' },
{ name = 'nvim_lsp' },
{ name = 'nvim_lsp_signature_help' },
{ name = 'luasnip', keyword_length = 3, max_item_count = 3 },
{ name = 'pandoc_references' },
{ name = 'buffer', keyword_length = 5, max_item_count = 3 },
{ name = 'spell' },
{ name = 'treesitter', keyword_length = 5, max_item_count = 3 },
{ name = 'calc' },
{ name = 'latex_symbols' },
{ name = 'emoji' },
},
view = {
entries = 'native',
},
window = {
documentation = {
border = require('misc.style').border,
},
},
}

-- for friendly snippets
require('luasnip.loaders.from_vscode').lazy_load()
-- for custom snippets
require('luasnip.loaders.from_vscode').lazy_load { paths = { vim.fn.stdpath 'config' .. '/snips' } }
-- link quarto and rmarkdown to markdown snippets
luasnip.filetype_extend('quarto', { 'markdown' })
luasnip.filetype_extend('rmarkdown', { 'markdown' })
end,
},

{ -- gh copilot
'zbirenbaum/copilot.lua',
enabled = false,
config = function()
require('copilot').setup {
suggestion = {
enabled = true,
auto_trigger = true,
debounce = 75,
keymap = {
accept = '<c-a>',
accept_word = false,
accept_line = false,
next = '<M-]>',
prev = '<M-[>',
dismiss = '<C-]>',
},
},
panel = { enabled = false },
}
end,
},
}
61 changes: 53 additions & 8 deletions lua/plugins/editing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ return {
opts = {},
},

{
'windwp/nvim-autopairs',
config = function()
require('nvim-autopairs').setup {}
require('nvim-autopairs').remove_rule '`'
end,
},

-- commenting with e.g. `gcc` or `gcip`
-- respects TS, so it works in quarto documents
{
Expand All @@ -28,6 +20,59 @@ return {
config = true,
},

{ -- Autoformat
'stevearc/conform.nvim',
enabled = true,
config = function()
require('conform').setup {
notify_on_error = false,
format_on_save = {
timeout_ms = 500,
lsp_fallback = true,
},
formatters_by_ft = {
lua = { 'mystylua' },
python = { 'isort', 'black' },
},
formatters = {
mystylua = {
command = 'stylua',
args = { '--indent-type', 'Spaces', '--indent-width', '2', '-' },
},
},
}
-- Customize the "injected" formatter
require('conform').formatters.injected = {
-- Set the options field
options = {
-- Set to true to ignore errors
ignore_errors = false,
-- Map of treesitter language to file extension
-- A temporary file name with this extension will be generated during formatting
-- because some formatters care about the filename.
lang_to_ext = {
bash = 'sh',
c_sharp = 'cs',
elixir = 'exs',
javascript = 'js',
julia = 'jl',
latex = 'tex',
markdown = 'md',
python = 'py',
ruby = 'rb',
rust = 'rs',
teal = 'tl',
r = 'r',
typescript = 'ts',
},
-- Map of treesitter language to formatters to use
-- (defaults to the value from formatters_by_ft)
lang_to_formatters = {},
},
}
end,
},

{ -- generate docstrings
'danymat/neogen',
cmd = { 'Neogen' },
Expand Down
Loading

0 comments on commit cb3e80b

Please sign in to comment.