From fc67eecc8a40bf28d3d2b190702e58c580bfba9f Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Thu, 19 Jan 2023 18:33:43 +0100 Subject: vim: format config with stylua MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- .vim/lua/internal/align.lua | 75 +- .vim/lua/internal/dap.lua | 63 +- .vim/lua/internal/exrc.lua | 49 - .vim/lua/internal/hardmode.lua | 10 +- .vim/lua/internal/job.lua | 59 +- .vim/lua/internal/lsp.lua | 258 ++-- .vim/lua/internal/misc.lua | 146 ++- .vim/lua/internal/snips.lua | 106 +- .vim/lua/internal/spell.lua | 3 +- .vim/lua/internal/statusline.lua | 215 ++-- .vim/lua/plugins.lua | 2069 ++++++++++++++++--------------- .vim/lua/telescope/_extensions/jobs.lua | 76 +- 12 files changed, 1621 insertions(+), 1508 deletions(-) delete mode 100644 .vim/lua/internal/exrc.lua (limited to '.vim/lua') diff --git a/.vim/lua/internal/align.lua b/.vim/lua/internal/align.lua index 5dcf7c0..1ada01d 100644 --- a/.vim/lua/internal/align.lua +++ b/.vim/lua/internal/align.lua @@ -14,11 +14,15 @@ function M.align_lines(pat, line1, line2, preview_ns, preview_bufnr) local max = -1 for _, line in pairs(lines) do local s = re:match_str(line) - if s and max < s then max = s end + if s and max < s then + max = s + end end -- exit if nothing was found - if max == -1 then return error('nothing found') end + if max == -1 then + return error('nothing found') + end for i, line in pairs(lines) do local s = re:match_str(line) @@ -27,33 +31,45 @@ function M.align_lines(pat, line1, line2, preview_ns, preview_bufnr) local changeset = { string.sub(line, 1, s), string.rep(' ', rep), - string.sub(line, s+1), + string.sub(line, s + 1), } local newline = table.concat(changeset) -- append to changse if not inside the preview callback if not preview_ns then - newlines[#newlines+1] = newline + newlines[#newlines + 1] = newline end if preview_ns ~= nil then -- set extmarks inside the live buffer - vim.api.nvim_buf_set_extmark(bufnr, preview_ns, line1+i - 2, 0, - { - hl_mode = 'combine', - virt_text_pos = 'overlay', - virt_text = { - {changeset[1]}, - {changeset[2], 'Substitute'}, - {changeset[3]}, - }, - }) + vim.api.nvim_buf_set_extmark(bufnr, preview_ns, line1 + i - 2, 0, { + hl_mode = 'combine', + virt_text_pos = 'overlay', + virt_text = { + { changeset[1] }, + { changeset[2], 'Substitute' }, + { changeset[3] }, + }, + }) -- modify preview buffer if preview_bufnr ~= nil then local prefix = string.format('|%d| ', line1 + i - 1) - vim.api.nvim_buf_set_lines(preview_bufnr, preview_buf_line, preview_buf_line, false, { prefix .. newline }) - vim.api.nvim_buf_add_highlight(preview_bufnr, preview_ns, 'Substitute', preview_buf_line, #prefix + s, #prefix + s + #changeset[2]) + vim.api.nvim_buf_set_lines( + preview_bufnr, + preview_buf_line, + preview_buf_line, + false, + { prefix .. newline } + ) + vim.api.nvim_buf_add_highlight( + preview_bufnr, + preview_ns, + 'Substitute', + preview_buf_line, + #prefix + s, + #prefix + s + #changeset[2] + ) preview_buf_line = preview_buf_line + 1 end end @@ -63,7 +79,9 @@ function M.align_lines(pat, line1, line2, preview_ns, preview_bufnr) -- only change buffer when not previewing if not preview_ns then -- exit if nothing was changed - if #newlines == 0 then return error('nothing changed') end + if #newlines == 0 then + return error('nothing changed') + end vim.api.nvim_buf_set_lines(bufnr, line1 - 1, line2, 0, newlines) return 0 end @@ -75,10 +93,10 @@ function M.align_lines(pat, line1, line2, preview_ns, preview_bufnr) end function M.align(pat) - local top, bot = vim.fn.getpos("'<"), vim.fn.getpos("'>") - M.align_lines(pat, top[2]-1, bot[2]) - vim.fn.setpos("'<", top) - vim.fn.setpos("'>", bot) + local top, bot = vim.fn.getpos("'<"), vim.fn.getpos("'>") + M.align_lines(pat, top[2] - 1, bot[2]) + vim.fn.setpos("'<", top) + vim.fn.setpos("'>", bot) end local function aligncmd(opts, preview_ns, preview_bufnr) @@ -86,18 +104,21 @@ local function aligncmd(opts, preview_ns, preview_bufnr) end local default_opts = { - bindings = true + bindings = true, } function M.setup(opts) opts = vim.tbl_extend('keep', opts or {}, default_opts) - vim.api.nvim_create_user_command('SimpleAlign', aligncmd, - {nargs = 1, range = '%', preview = aligncmd}) + vim.api.nvim_create_user_command( + 'SimpleAlign', + aligncmd, + { nargs = 1, range = '%', preview = aligncmd } + ) - if opts.bindings then - vim.keymap.set('v', '', ':SimpleAlign ') - end + -- if opts.bindings then + -- vim.keymap.set('v', '', ':SimpleAlign ') + -- end end return M diff --git a/.vim/lua/internal/dap.lua b/.vim/lua/internal/dap.lua index aa419ea..1790575 100644 --- a/.vim/lua/internal/dap.lua +++ b/.vim/lua/internal/dap.lua @@ -10,30 +10,43 @@ dap.listeners.after['event_initialized']['me'] = function() end -- signs -vim.fn.sign_define({{name='DapBreakpoint', text='🞱', texthl='DapBreakpoint', linehl='DapBreakpointLn'}}) -vim.fn.sign_define({{name='DapStopped', text='→', texthl='DapStopped', linehl='DapStoppedLn'}}) +vim.fn.sign_define({ + { name = 'DapBreakpoint', text = '🞱', texthl = 'DapBreakpoint', linehl = 'DapBreakpointLn' }, +}) +vim.fn.sign_define({ + { name = 'DapStopped', text = '→', texthl = 'DapStopped', linehl = 'DapStoppedLn' }, +}) -- keymaps -vim.keymap.set('n', 'dd', dap.toggle_breakpoint, {desc='toggle breakpoint'}) -- convenience -vim.keymap.set('n', 'db', dap.toggle_breakpoint, {desc='toggle breakpoint'}) -vim.keymap.set('n', 'dc', dap.continue, {desc='continue'}) -vim.keymap.set('n', 'do', dap.step_over, {desc='step over'}) -vim.keymap.set('n', 'di', dap.step_into, {desc='step into'}) -vim.keymap.set('n', 'dO', dap.step_out, {desc='step out'}) -vim.keymap.set('n', 'dR', dap.repl.toggle, {desc='toggle REPL'}) -vim.keymap.set('n', 'dL', dap.run_last, {desc='run last'}) -vim.keymap.set('n', 'dt', dap.terminate, {desc='terminate'}) +vim.keymap.set('n', 'dd', dap.toggle_breakpoint, { desc = 'toggle breakpoint' }) -- convenience +vim.keymap.set('n', 'db', dap.toggle_breakpoint, { desc = 'toggle breakpoint' }) +vim.keymap.set('n', 'dc', dap.continue, { desc = 'continue' }) +vim.keymap.set('n', 'do', dap.step_over, { desc = 'step over' }) +vim.keymap.set('n', 'di', dap.step_into, { desc = 'step into' }) +vim.keymap.set('n', 'dO', dap.step_out, { desc = 'step out' }) +vim.keymap.set('n', 'dR', dap.repl.toggle, { desc = 'toggle REPL' }) +vim.keymap.set('n', 'dL', dap.run_last, { desc = 'run last' }) +vim.keymap.set('n', 'dt', dap.terminate, { desc = 'terminate' }) local widgets = require('dap.ui.widgets') -vim.keymap.set('n', 'dh', widgets.hover, {desc='hover'}) -vim.keymap.set('n', 'dB', require('telescope').extensions.dap.list_breakpoints, {desc='list breakpoints'}) +vim.keymap.set('n', 'dh', widgets.hover, { desc = 'hover' }) +vim.keymap.set( + 'n', + 'dB', + require('telescope').extensions.dap.list_breakpoints, + { desc = 'list breakpoints' } +) -- Common local bin_from_var_or_pick = function() local ok, retval = pcall(vim.api.nvim_buf_get_var, 0, 'dap_bin') - if ok then return retval end + if ok then + return retval + end local bin = nil - vim.ui.input({prompt = 'DAP Binary: '}, function(choice) bin = choice end) + vim.ui.input({ prompt = 'DAP Binary: ' }, function(choice) + bin = choice + end) return bin end @@ -44,21 +57,29 @@ dap.adapters.go_dlv_local = function(callback, config) -- {{{ local pid_or_err local port = 38697 local opts = { - stdio = {nil, stdout}, - args = {'dap', '-l', '127.0.0.1:' .. port}, + stdio = { nil, stdout }, + args = { 'dap', '-l', '127.0.0.1:' .. port }, detached = true, } - handle, pid_or_err = vim.loop.spawn("dlv", opts, function(exit) + handle, pid_or_err = vim.loop.spawn('dlv', opts, function(exit) stdout:close() handle:close() - if exit ~= 0 then vim.notify('dlv exited with exit code ' .. exit) end + if exit ~= 0 then + vim.notify('dlv exited with exit code ' .. exit) + end end) assert(handle, 'Error running dlv: ' .. tostring(pid_or_err)) stdout:read_start(function(err, chunk) assert(not err, err) - if chunk then vim.schedule(function() require('dap.repl').append(chunk) end) end + if chunk then + vim.schedule(function() + require('dap.repl').append(chunk) + end) + end end) - vim.defer_fn(function() callback({type = 'server', host = '127.0.0.1', port = port}) end, 100) + vim.defer_fn(function() + callback({ type = 'server', host = '127.0.0.1', port = port }) + end, 100) end -- }}} dap.adapters.go_dlv_remote = { diff --git a/.vim/lua/internal/exrc.lua b/.vim/lua/internal/exrc.lua deleted file mode 100644 index 1b3b22b..0000000 --- a/.vim/lua/internal/exrc.lua +++ /dev/null @@ -1,49 +0,0 @@ -local root_pattern = require('lspconfig.util').root_pattern - -local M = { - config = { - filenames = {'.nvimrc'} - } -} - -M.setup = function (opt) - vim.validate { - filenames = { opt.filenames, 'table', true }, - } - - M.config = vim.tbl_extend('force', M.config, opt) - - local group = vim.api.nvim_create_augroup('ExrcLoad', { clear = true }) - vim.api.nvim_create_autocmd('VimEnter', { - callback = M.load, - group = group, - }) -end - -local load = function (root, filename) - local fpath = root .. '/' .. filename - if root and vim.loop.fs_stat(fpath) then - vim.cmd('luafile ' .. fpath) - vim.g.nvimrc_loaded = fpath - else - error(string.format('[exrc] %s not found', fpath)) - end -end - -M.load = function () - local root = vim.fn.getcwd() - for _, fname in ipairs(M.config.filenames) do - local ok = false - ok, _ = pcall(load, root, fname) - if ok then return true end - - -- try harder by searching up the dir tree - root = root_pattern(fname)(root) - ok, _ = pcall(load, root, fname) - if ok then return true end - end - - return false -end - -return M diff --git a/.vim/lua/internal/hardmode.lua b/.vim/lua/internal/hardmode.lua index cc71baf..2774ead 100644 --- a/.vim/lua/internal/hardmode.lua +++ b/.vim/lua/internal/hardmode.lua @@ -1,10 +1,10 @@ -- hard mode means we're not using the arrow keys! local bail = function() - vim.cmd [[silent! echohl ErrorMsg | echo "HARD MODE: hjkl operation only" | echohl None]] + vim.cmd([[silent! echohl ErrorMsg | echo "HARD MODE: hjkl operation only" | echohl None]]) end -vim.keymap.set({'n', 'v', 'i'}, '', bail) -vim.keymap.set({'n', 'v', 'i'}, '', bail) -vim.keymap.set({'n', 'v', 'i'}, '', bail) -vim.keymap.set({'n', 'v', 'i'}, '', bail) +vim.keymap.set({ 'n', 'v', 'i' }, '', bail) +vim.keymap.set({ 'n', 'v', 'i' }, '', bail) +vim.keymap.set({ 'n', 'v', 'i' }, '', bail) +vim.keymap.set({ 'n', 'v', 'i' }, '', bail) diff --git a/.vim/lua/internal/job.lua b/.vim/lua/internal/job.lua index 64d9837..42a548b 100644 --- a/.vim/lua/internal/job.lua +++ b/.vim/lua/internal/job.lua @@ -1,7 +1,5 @@ -local spinner_ok, spinner = pcall(require, 'spinner.core') - local M = { - current_jobs = {} + current_jobs = {}, } local strip_ansi = function(line) @@ -14,14 +12,15 @@ local setqf = function(opts, pid, data) end vim.fn.setqflist({}, 'a', { title = opts.format_title, - lines = {strip_ansi(data)}, + lines = { strip_ansi(data) }, efm = '%m', context = { - cmd = {opts.command, unpack(opts.args)}, + cmd = { opts.command, unpack(opts.args) }, pid = pid, source = 'jobstart', - } + }, }) + vim.cmd.doautocmd('QuickFixCmdPost') end --create a new job and register @@ -29,13 +28,14 @@ end function M.jobstart(opts) opts = opts or {} + local spinner_ok, spinner = pcall(require, 'spinner.core') + -- default options - -- opts.enable_recording = true opts.enable_spinner = (opts.enable_spinner or true) and spinner_ok opts.populate_quickfix = opts.populate_quickfix or 'onerror' if opts.format_title == nil then - opts.format_title = table.concat({opts.command, unpack(opts.args)}, ' ') + opts.format_title = table.concat({ opts.command, unpack(opts.args) }, ' ') elseif type(opts.format_title) == 'function' then opts.format_title = opts.format_title(opts.command, opts.args) elseif type(opts.format_title) == 'string' then @@ -45,7 +45,7 @@ function M.jobstart(opts) end opts.on_start = vim.schedule_wrap(function(j) - table.insert(M.current_jobs, j.pid, j) + M.current_jobs[j.pid] = j if opts.populate_quickfix then vim.fn.setqflist({}, 'r') -- clear quickfix @@ -57,7 +57,7 @@ function M.jobstart(opts) end) opts.on_exit = vim.schedule_wrap(function(j, code) - table.remove(M.current_jobs, j.pid) + M.current_jobs[j.pid] = nil if not (code == 0) then vim.notify(string.format('[%d] exit %d', j.pid, code), vim.log.levels.ERROR) @@ -67,7 +67,7 @@ function M.jobstart(opts) spinner.on_exit(nil, nil, j.pid) end if opts.populate_quickfix then - vim.cmd.doautocmd [[QuickFixCmdPost]] + vim.cmd.doautocmd('QuickFixCmdPost') end end) @@ -92,11 +92,11 @@ function M.jobstart(opts) end) -- run vim.fn.expand() on all args - for i=1, #opts.args do + for i = 1, #opts.args do opts.args[i] = vim.fn.expandcmd(opts.args[i]) end - local j = require ('plenary.job'):new(opts) + local j = require('plenary.job'):new(opts) j:start() return j @@ -116,31 +116,44 @@ function M.make(extra_args) cwd = require('lspconfig.util').root_pattern('Makefile')(cwd) end - table.foreach(extra_args or {}, function(_, v) table.insert(args, v) end) + for _, v in pairs(extra_args or {}) do + table.insert(args, v) + end + -- table.foreach(extra_args or {}, function(_, v) end) - return M.jobstart { + return M.jobstart({ command = command, args = args, cwd = cwd, - } + }) end function M.sh(command_string) - return M.jobstart { + return M.jobstart({ command = vim.env.SHELL, - args = {'-c', command_string}, + args = { '-c', command_string }, -- strip 'sh -c' from the title (used by progress reporting etc.) format_title = function(_, args) - return table.concat({unpack(args, 2, #args)}, ' ') - end - } + return table.concat({ unpack(args, 2, #args) }, ' ') + end, + }) end - function M.list() - require('telescope').load_extension('jobs') require('telescope._extensions').manager['jobs']['jobs']() end +function M.setup() + require('telescope').load_extension('jobs') + + vim.keymap.set( + 'n', + 'J', + require('internal.job').list, + { desc = 'list jobs managed by internal.job' } + ) + vim.api.nvim_create_user_command('Jobs', M.list, { desc = 'list jobs managed by internal.job' }) +end + return M diff --git a/.vim/lua/internal/lsp.lua b/.vim/lua/internal/lsp.lua index aa2794e..2bdd270 100644 --- a/.vim/lua/internal/lsp.lua +++ b/.vim/lua/internal/lsp.lua @@ -1,5 +1,9 @@ -local lsp = require('lspconfig') -local lspstatus = require('lsp-status') +-- TODO vim.api.nvim_create_autocmd('LspAttach', { +-- callback = function(args) +-- local client = vim.lsp.get_client_by_id(args.data.client_id) +-- local bufnr = args.buf +-- end, +-- }) local my_attach = function(client, bufnr) if vim.opt.diff:get() then @@ -13,67 +17,112 @@ local my_attach = function(client, bufnr) buffer = bufnr, group = group, callback = function() - if not _G.diagnostic_hidden then - vim.diagnostic.open_float(nil, { - focusable = false, - close_events = {'BufLeave', 'CursorMoved', 'InsertEnter', 'FocusLost'}, - border = _G.floating_win_border, - source = 'always', - prefix = ' ', - scope = 'cursor', - }) + if _G.diagnostic_hidden then + return + end + -- evalutate if there's already a floating preview buffer + local existing = vim.F.npcall(vim.api.nvim_buf_get_var, bufnr, 'lsp_floating_preview') + if not existing or not vim.api.nvim_win_is_valid(existing) then + vim.diagnostic.open_float() end end, }) - lspstatus.on_attach(client) + require('lsp-status').on_attach(client) if client.supports_method('textDocument/documentSymbol') then require('nvim-navic').attach(client, bufnr) -- require('aerial').on_attach(client, bufnr) -- vim.keymap.set('n', 'g0', vim.lsp.buf.document_symbol, {buffer = bufnr}) end if client.supports_method('workspace/symbol') then - vim.keymap.set('n', 'gW' , vim.lsp.buf.workspace_symbol, {buffer = bufnr, desc = 'goto symbol'}) - vim.keymap.set('n', ';s' , require('telescope.builtin').lsp_workspace_symbols, {desc='lsp workspace symbols'}) + vim.keymap.set( + 'n', + 'gW', + vim.lsp.buf.workspace_symbol, + { buffer = bufnr, desc = 'goto symbol' } + ) + vim.keymap.set( + 'n', + ';s', + require('telescope.builtin').lsp_workspace_symbols, + { desc = 'lsp workspace symbols' } + ) end if client.supports_method('textDocument/definition') then - vim.keymap.set('n', '' , vim.lsp.buf.definition, {buffer = bufnr, desc = 'goto definition'}) - vim.keymap.set('n', 'gd' , vim.lsp.buf.definition, {buffer = bufnr, desc = 'goto definition'}) - vim.keymap.set('n', 'gR' , vim.lsp.buf.references, {buffer = bufnr, desc = 'goto references'}) - vim.keymap.set('n', ';R' , require('telescope.builtin').lsp_references, {desc='lsp references'}) + vim.keymap.set( + 'n', + '', + vim.lsp.buf.definition, + { buffer = bufnr, desc = 'goto definition' } + ) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { buffer = bufnr, desc = 'goto definition' }) + vim.keymap.set('n', 'gR', vim.lsp.buf.references, { buffer = bufnr, desc = 'goto references' }) + vim.keymap.set( + 'n', + ';R', + require('telescope.builtin').lsp_references, + { desc = 'lsp references' } + ) end if client.supports_method('textDocument/hover') then - vim.keymap.set('n', 'K' , vim.lsp.buf.hover, {buffer = bufnr, desc = 'hover'}) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr, desc = 'hover' }) end if client.supports_method('textDocument/rename') then - vim.keymap.set('n', 'grr' , vim.lsp.buf.rename, {buffer = bufnr, desc = 'rename'}) + vim.keymap.set('n', 'grr', vim.lsp.buf.rename, { buffer = bufnr, desc = 'rename' }) end if client.supports_method('signatureHelp') then - vim.keymap.set('n', '' , vim.lsp.buf.signature_help, {buffer = bufnr, desc = 'signature help'}) + vim.keymap.set( + 'n', + '', + vim.lsp.buf.signature_help, + { buffer = bufnr, desc = 'signature help' } + ) end if client.supports_method('textDocument/formatting') then vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr()') - vim.keymap.set('n', 'f' , vim.lsp.buf.format, {buffer = bufnr, desc = 'format'}) + vim.keymap.set('n', 'f', vim.lsp.buf.format, { buffer = bufnr, desc = 'format' }) vim.api.nvim_create_autocmd('BufWritePre', { buffer = bufnr, group = group, - callback = function() require('internal.lsp').format(vim.fn.expand(':p')) end, + callback = function() + require('internal.lsp').format(vim.fn.expand(':p')) + end, }) end if client.supports_method('textDocument/typeDefinition') then - vim.keymap.set('n', 'gT' , vim.lsp.buf.type_definition, {buffer = bufnr, desc = 'goto typedef'}) + vim.keymap.set( + 'n', + 'gT', + vim.lsp.buf.type_definition, + { buffer = bufnr, desc = 'goto typedef' } + ) end if client.supports_method('textDocument/declaration') then - vim.keymap.set('n', 'gD' , vim.lsp.buf.declaration, {buffer = bufnr, desc = 'goto declaration'}) + vim.keymap.set( + 'n', + 'gD', + vim.lsp.buf.declaration, + { buffer = bufnr, desc = 'goto declaration' } + ) end if client.supports_method('textDocument/implementation') then - vim.keymap.set('n', 'gI' , vim.lsp.buf.implementation, {buffer = bufnr, desc = 'goto implementation'}) + vim.keymap.set( + 'n', + 'gI', + vim.lsp.buf.implementation, + { buffer = bufnr, desc = 'goto implementation' } + ) end if client.supports_method('textDocument/codeAction') then - vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, {buffer = bufnr, desc = 'code action'}) + vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, { buffer = bufnr, desc = 'code action' }) end if client.supports_method('textDocument/documentHighlight') then - vim.keymap.set('n', '8', vim.lsp.buf.document_highlight, {buffer = bufnr, desc = 'document highlight'}) + vim.keymap.set( + 'n', + '8', + vim.lsp.buf.document_highlight, + { buffer = bufnr, desc = 'document highlight' } + ) -- vim.keymap.set('n', '', vim.lsp.buf.clear_references, {buffer = bufnr, desc = 'clear references'}) vim.api.nvim_create_autocmd('CursorMoved', { callback = vim.lsp.buf.clear_references, @@ -82,8 +131,7 @@ local my_attach = function(client, bufnr) end end -local my_exit = function(_, _, _) -end +local my_exit = function(_, _, _) end local capabilities = function() local caps = vim.lsp.protocol.make_client_capabilities() @@ -94,33 +142,22 @@ local capabilities = function() 'documentation', 'detail', 'additionalTextEdits', - } + }, } -- add window/workDoneProgress capability - caps = vim.tbl_extend('keep', caps or {}, lspstatus.capabilities) + caps = vim.tbl_extend('keep', caps or {}, require('lsp-status').capabilities) return caps end local servers = { - ccls = { disabled = true, - root_dir = lsp.util.root_pattern('.ccls','meson.build','.git'), - init_options = { - compilationDatabaseDirectory = "build", - index = { threads = 0 }, - completion = { - filterAndSort = false, - }, - clang = { excludeArgs = { '-frounding-math' } }, - }, - }, clangd = {}, elixirls = { cmd = { 'elixir-ls' }, settings = { elixirLS = { dialyzerEnabled = false, - } - } + }, + }, }, gopls = { settings = { @@ -135,11 +172,12 @@ local servers = { }, gofumpt = true, -- hoverKind = 'Structured', - } - } + }, + }, }, sumneko_lua = { - cmd = { 'lua-language-server' }, + -- cmd = { 'lua-language-server' }, + cmd = { 'luals' }, settings = { Lua = { runtime = { @@ -153,7 +191,8 @@ local servers = { 'error', 'os', 'package', - 'pairs', 'ipairs', + 'pairs', + 'ipairs', 'pcall', 'require', 'string', @@ -165,14 +204,14 @@ local servers = { }, neededFileStatus = { ['code-style-check'] = 'Any', - } + }, }, format = { - enable = true, + enable = true, defaultConfig = { indent_style = 'space', indent_size = '2', - } + }, }, workspace = { -- library = vim.api.nvim_get_runtime_file("", true), @@ -180,7 +219,7 @@ local servers = { [vim.env.VIMRUNTIME .. '/lua'] = true, [vim.env.VIMRUNTIME .. '/lua/vim/lsp'] = true, [vim.fn.stdpath('config') .. '/lua'] = true, - } + }, }, telemetry = { enable = false, @@ -189,61 +228,69 @@ local servers = { }, }, rust_analyzer = { - cmd = { 'env', 'CARGO_TARGET_DIR=/tmp', 'RUST_SRC_PATH=/usr/src/rustlib/library', 'rust-analyzer' }, + -- cmd = { 'env', 'CARGO_TARGET_DIR=/tmp', 'RUST_SRC_PATH=/usr/src/rustlib/library', 'rust-analyzer' }, settings = { ['rust-analyzer'] = { checkOnSave = { - command = 'clippy' - } - } - }, - }, - tsserver = { disabled = true, - cmd = { - 'toolbox', 'run', '--', - 'sh', '-c', - '. /etc/profile.d/nvm.sh && typescript-language-server --stdio' + command = 'clippy', + }, + }, }, }, - zls = { disabled = true, - }, - zk = { disabled = true, - root_dir = lsp.util.root_pattern('.zk'), - }, + pylsp = {}, + -- tsserver = { disabled = true, + -- cmd = { + -- 'toolbox', 'run', '--', + -- 'sh', '-c', + -- '. /etc/profile.d/nvm.sh && typescript-language-server --stdio' + -- }, + -- }, + -- zls = { disabled = true }, + -- zk = { + -- cmd = {'zk', 'lsp', '--log', '/tmp/zk-lsp.log'}, + -- autostart = true, + -- }, } local setup = function() -- configure floating win handlers - vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( - vim.lsp.handlers.hover, { border = _G.floating_win_border }) - vim.lsp.handlers['textDocument/signature_help'] = vim.lsp.with( - vim.lsp.handlers.signature_help, { border = _G.floating_win_border }) + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { + focus = false, + zindex = 100, + border = _G.floating_win_border, + }) + vim.lsp.handlers['textDocument/signature_help'] = + vim.lsp.with(vim.lsp.handlers.signature_help, { border = _G.floating_win_border }) local caps = capabilities() for server, opts in pairs(servers) do if not opts.disabled then opts = vim.tbl_extend('error', opts, { - on_attach = my_attach, - on_exit = my_exit, + on_attach = my_attach, + on_exit = my_exit, capabilities = caps, }) -- lsp-status custom handlers - local ok, lspstatus_ext = pcall(lspstatus.extensions[server]) + local ok, lspstatus_ext = pcall(require('lsp-status').extensions[server]) if ok then opts = vim.tbl_extend('error', opts, { handlers = lspstatus_ext.setup(), }) end - lsp[server].setup(opts) + require('lspconfig')[server].setup(opts) end end end local format = function(afile) - if vim.g.nofmt then return end + if vim.g.nofmt then + return + end local ok, isMatch = pcall(string.match, afile, '^/home/robert/devel/upstream') - if not ok or isMatch then return end + if not ok or isMatch then + return + end local errhandler = function(err) vim.notify('fmt failed: ' .. err, vim.log.levels.ERROR) @@ -251,54 +298,21 @@ local format = function(afile) end xpcall(vim.lsp.buf.format, errhandler) if string.match(afile, '.go$') then - xpcall(vim.lsp.buf.code_action, errhandler, {context = {only = {'source.organizeImports'}}, apply = true}) + xpcall( + vim.lsp.buf.code_action, + errhandler, + { context = { only = { 'source.organizeImports' } }, apply = true } + ) end -- vim.notify('%#MoreMsg#󰃢%#Italic# fmt', vim.log.levels.INFO) vim.notify('󰃢 ', vim.log.levels.INFO) end -local symbols = { - -- 󰆼 󱆃 - Array = '󰨾 ', - Boolean = '󰦍 ', - Class = '󰙀 ', - Color = '󰉦 ', - Constant = ' ', - Constructor = '󱇿 ', - Enum = ' ', - EnumMember = ' ', - Event = '󱐋 ', - -- Field = '󰽜 ', - Field = '󰆈 ', - File = '󰈔 ', - Folder = '󰝰 ', - Function = ' ', - Interface = '󱦜 ', - Key = '󰌋 ', - Keyword = '󰓽 ', - Method = '󰒓 ', - Module = '󰏖 ', - Namespace = '󰆧 ', - Null = '󰎣 ', - Object = '󰘦 ', - Operator = '󱓉 ', - Property = '󰐱 ', - Package = '󰏗 ', - Reference = '󰌹 ', - Snippet = '󰯁 ', - Struct = '󰙅 ', - Text = '󰉿 ', - TypeParameter = '󰌨 ', - Unit = '󰠱 ', - Value = '󰎠 ', - Variable = '󱄑 ', -} - return { - my_attach = my_attach, - my_exit = my_exit, + my_attach = my_attach, + my_exit = my_exit, capabilities = capabilities, - setup = setup, - format = format, - symbols = symbols, + setup = setup, + format = format, + symbols = symbols, } diff --git a/.vim/lua/internal/misc.lua b/.vim/lua/internal/misc.lua index b7d1a06..8664cbc 100644 --- a/.vim/lua/internal/misc.lua +++ b/.vim/lua/internal/misc.lua @@ -28,19 +28,23 @@ function M.open_under_cursor(cmd, detect_cmd) if vim.regex([[^(\.\./|[\w\d_/\-])*(\.[\w\d]+)?$]]):match_str(txt) then cmd = ':edit' end - vim.notify("open_under_cursor: detected command " .. txt .. " => " .. (cmd or "")) + vim.notify('open_under_cursor: detected command ' .. txt .. ' => ' .. (cmd or '')) end if not cmd then vim.fn.inputsave() - vim.ui.input('open with: ', function(result) cmd = result end) + vim.ui.input('open with: ', function(result) + cmd = result + end) vim.fn.inputrestore() - if not cmd then return end + if not cmd then + return + end end -- detect vim command - if cmd:sub(1, 1) == ":" then + if cmd:sub(1, 1) == ':' then vim.cmd(cmd:sub(2) .. ' ' .. txt) else - vim.loop.spawn(cmd, {args = {txt}}) + vim.loop.spawn(cmd, { args = { txt } }) end end) end @@ -54,7 +58,7 @@ local function get_visual_selection() if vim.opt.selection:get() == 'inclusive' then lines[#lines] = lines[#lines]:sub(1, bot.col) else - lines[#lines] = lines[#lines]:sub(1, (bot.col -1)) + lines[#lines] = lines[#lines]:sub(1, (bot.col - 1)) end lines[1] = lines[1]:sub(top.col) return top, bot, lines @@ -64,12 +68,12 @@ function M.sort_lines(_, preview_ns, preview_bufnr) local bufnr = vim.api.nvim_get_current_buf() local top, bot, lines = get_visual_selection() - for i=1, #lines do - lines[i] = vim.fn.join(vim.fn.sort(vim.fn.split(lines[i], " "))) + for i = 1, #lines do + lines[i] = vim.fn.join(vim.fn.sort(vim.fn.split(lines[i], ' '))) end if not preview_ns then - vim.api.nvim_buf_set_lines(bufnr, top.ln-1, bot.ln, false, lines) + vim.api.nvim_buf_set_lines(bufnr, top.ln - 1, bot.ln, false, lines) vim.notify('no preview') return 0 end @@ -77,16 +81,23 @@ function M.sort_lines(_, preview_ns, preview_bufnr) -- inccommand preview if preview_ns ~= nil then for i, line in ipairs(lines) do - vim.api.nvim_buf_set_extmark(bufnr, preview_ns, top.ln+i - 2, 0, { + vim.api.nvim_buf_set_extmark(bufnr, preview_ns, top.ln + i - 2, 0, { hl_mode = 'combine', virt_text_pos = 'overlay', - virt_text = {{line, 'Substitute'}}, + virt_text = { { line, 'Substitute' } }, }) if preview_bufnr ~= nil then local prefix = string.format('|%d| ', top.ln + i - 1) - vim.api.nvim_buf_set_lines(preview_bufnr, i-1, -1, false, { prefix .. line }) - vim.api.nvim_buf_add_highlight(preview_bufnr, preview_ns, 'Substitute', i, #prefix, #prefix+#line) + vim.api.nvim_buf_set_lines(preview_bufnr, i - 1, -1, false, { prefix .. line }) + vim.api.nvim_buf_add_highlight( + preview_bufnr, + preview_ns, + 'Substitute', + i, + #prefix, + #prefix + #line + ) end end return (#lines > 1 and 2 or 1) @@ -96,20 +107,24 @@ end local get_searchdirs = function(dirs) if type(dirs) == 'table' and #dirs > 0 then return dirs - elseif type(dirs) == 'string' and not (dirs == "") then + elseif type(dirs) == 'string' and not (dirs == '') then dirs = vim.split(dirs, ',') end -- skip asking if we're looking at known filetypes local ft = vim.api.nvim_buf_get_option(0, 'filetype') if #dirs == 0 and (ft == 'dirbuf' or ft == 'alpha') then - dirs = {'%:p:h'} + dirs = { '%:p:h' } end -- ask user if #dirs == 0 then - vim.ui.input({prompt = 'Search directories: '}, function(result) dirs = {result} end) + vim.ui.input({ prompt = 'Search directories: ' }, function(result) + dirs = { result } + end) end -- default to something reasonable - if #dirs == 0 then dirs = {'%:p:h'} end + if #dirs == 0 then + dirs = { '%:p:h' } + end -- finally return for i = 1, #dirs do dirs[i] = vim.fn.expand(dirs[i]) @@ -118,11 +133,15 @@ local get_searchdirs = function(dirs) end function onchoice(opts, cb) - if not cb then return end + if not cb then + return + end opts.attach_mappings = function(prompt_bufnr) require('telescope.actions').select_default:replace(function() local selection = require('telescope.actions.state').get_selected_entry() - if selection == nil then return end + if selection == nil then + return + end require('telescope.actions').close(prompt_bufnr) on_choice(selection.path) end) @@ -134,25 +153,28 @@ function M.live_grep(dirs, opts, cb) opts = opts or {} local search_dirs = get_searchdirs(dirs) opts.search_dirs = search_dirs - opts.prompt_title = 'Grep: '.. vim.inspect(search_dirs) + opts.prompt_title = 'Grep: ' .. vim.inspect(search_dirs) onchoice(opts, cb) require('telescope.builtin').live_grep(opts) end function M.find_files(dirs, opts, cb) -- convenience aliases - if dirs == 'plugins' then dirs = vim.fn.stdpath('data') .. '/site/pack/' end + if dirs == 'plugins' then + dirs = vim.fn.stdpath('data') .. '/site/pack/' + end opts = opts or {} local search_dirs = dirs - if type(dirs) == 'string' then search_dirs = get_searchdirs(dirs) end + if type(dirs) == 'string' then + search_dirs = get_searchdirs(dirs) + end opts.search_dirs = search_dirs - opts.prompt_title = 'Find: '.. vim.inspect(search_dirs) + opts.prompt_title = 'Find: ' .. vim.inspect(search_dirs) onchoice(opts, cb) require('telescope.builtin').find_files(opts) end - function M.fold_block() -- {{{ local Comment = require('Comment.api') local m = vim.api.nvim_buf_get_mark @@ -179,51 +201,67 @@ end -- }}} function M.link_preview() local link = vim.fn.expand('') - if not link then return end + if not link then + return + end local buf = vim.api.nvim_get_current_buf() - local ln = (vim.api.nvim_win_get_cursor(0)[1]) - 1 - - require('job').jobstart({ - format_title = function() return "link-preview" end, - command = vim.env.SHELL, - args = {'-c', [[ curl -sSfL ]] .. link .. [[ | grep -iPo '(?<=property="og:title" content=")([^\"]+)(?=")' ]]}, - populate_quickfix = false, - enable_recording = true, - }):after_success( - vim.schedule_wrap(function(j, code, _) + local ln = vim.api.nvim_win_get_cursor(0)[1] - 1 + + require('job') + .jobstart({ + format_title = function() + return 'link-preview' + end, + command = vim.env.SHELL, + args = { + '-c', + [[ curl -sSfL ]] + .. link + .. [[ | grep -iPo '(?<=property="og:title" content=")([^\"]+)(?=")' ]], + }, + populate_quickfix = false, + enable_recording = true, + }) + :after_success(vim.schedule_wrap(function(j, code, _) local results = j:result() - if not code == 0 or #results == 0 then return end + if not code == 0 or #results == 0 then + return + end local ns = vim.api.nvim_create_namespace('') vim.api.nvim_buf_set_extmark(buf, ns, ln, 0, { - virt_text = {{results[1], 'Error'}}, - virt_text_pos = 'eol' + virt_text = { { results[1], 'Error' } }, + virt_text_pos = 'eol', }) - end) - ) + end)) end function M.setup(opts) if opts.sortline then - vim.api.nvim_create_user_command('SortLine', M.sort_lines, - { desc = 'sort line', range = '%', preview = M.sort_lines }) + vim.api.nvim_create_user_command( + 'SortLine', + M.sort_lines, + { desc = 'sort line', range = '%', preview = M.sort_lines } + ) end if opts.grep then - vim.api.nvim_create_user_command('Grep', function(o) M.live_grep(table.concat(o.fargs)) end, - { - desc = 'live grep (rg)', - nargs = '*', - complete = 'dir', - }) + vim.api.nvim_create_user_command('Grep', function(o) + M.live_grep(table.concat(o.fargs)) + end, { + desc = 'live grep (rg)', + nargs = '*', + complete = 'dir', + }) end if opts.find then - vim.api.nvim_create_user_command('Find', function(o) M.find_files(table.concat(o.fargs)) end, - { - desc = 'find files (fd)', - nargs = '*', - complete = 'dir', - }) + vim.api.nvim_create_user_command('Find', function(o) + M.find_files(table.concat(o.fargs)) + end, { + desc = 'find files (fd)', + nargs = '*', + complete = 'dir', + }) end end diff --git a/.vim/lua/internal/snips.lua b/.vim/lua/internal/snips.lua index 318c9f7..423eec6 100644 --- a/.vim/lua/internal/snips.lua +++ b/.vim/lua/internal/snips.lua @@ -1,4 +1,3 @@ - local ls = require('luasnip') local types = require('luasnip.util.types') @@ -13,7 +12,7 @@ vim.api.nvim_set_hl(0, 'LuasnipIndicator', { local autowrap = function(top, bot, inner) local autoinsert = function(args, _, _, wrap_with) local nodes = {} - if vim.trim(table.concat(args[1] or {})) ~= "" then + if vim.trim(table.concat(args[1] or {})) ~= '' then table.insert(nodes, wrap_with) end return ls.sn(nil, nodes) @@ -31,9 +30,11 @@ local autowrap = function(top, bot, inner) end local nodes = {} - table.insert(nodes, ls.d(maxpos+1, autoinsert, argnodes, {user_args = {top}})) - for _, e in ipairs(inner) do table.insert(nodes, e) end - table.insert(nodes, ls.d(maxpos+2, autoinsert, argnodes, {user_args = {bot}})) + table.insert(nodes, ls.d(maxpos + 1, autoinsert, argnodes, { user_args = { top } })) + for _, e in ipairs(inner) do + table.insert(nodes, e) + end + table.insert(nodes, ls.d(maxpos + 2, autoinsert, argnodes, { user_args = { bot } })) return nodes end @@ -41,61 +42,88 @@ end local comment = function(wrapped, blockcomment) -- commentstring helper local get_cstring = function() - local cs = require('Comment.ft').calculate { + local cs = require('Comment.ft').calculate({ ctype = blockcomment and 2 or 1, - range = require('Comment.utils').get_region() - } - local tbl = vim.split(cs or '', '%s', {plain = true, trimempty = true}) - return (#tbl == 0) and {'', ''} - or ((#tbl == 1) and {tbl[1] .. ' ', ''} - or {tbl[1], tbl[2]}) + range = require('Comment.utils').get_region(), + }) + local tbl = vim.split(cs or '', '%s', { plain = true, trimempty = true }) + return (#tbl == 0) and { '', '' } + or ((#tbl == 1) and { tbl[1] .. ' ', '' } or { tbl[1], tbl[2] }) end - if type(wrapped) ~= "table" then - wrapped = {wrapped} + if type(wrapped) ~= 'table' then + wrapped = { wrapped } end local nodes = {} - table.insert(nodes, ls.f(function() return get_cstring()[1] end)) - for _, n in ipairs(wrapped) do table.insert(nodes, n) end - table.insert(nodes, ls.f(function() return get_cstring()[2] end)) + table.insert( + nodes, + ls.f(function() + return get_cstring()[1] + end) + ) + for _, n in ipairs(wrapped) do + table.insert(nodes, n) + end + table.insert( + nodes, + ls.f(function() + return get_cstring()[2] + end) + ) return nodes end -- exec: inserts the output of command local exec = function(command) return ls.f(function(_, _, ...) - local results, code = require('plenary.job'):new({ - command = vim.env.SHELL, - args = {'-c', ...}, - enable_recording = true, - }):sync() + local results, code = require('plenary.job') + :new({ + command = vim.env.SHELL, + args = { '-c', ... }, + enable_recording = true, + }) + :sync() if not code == 0 or #results == 0 then error(string.format('exec "%s" failed', ...)) end return results - end, {}, {user_args = {command}}) + end, {}, { user_args = { command } }) +end + +local file_contents = function(path, vargs) + return ls.d(1, function(_, _, _, ...) + local lines = {} + for line in io.lines(path) do + table.insert(lines, line) + end + return ls.sn(nil, require('luasnip.extras.fmt').fmt(table.concat(lines, '\n'), ...)) + end, {}, { user_args = { vargs } }) end -ls.setup { +ls.setup({ ext_opts = { [types.snippet] = { - active = { virt_text = {{ '<-- luasnip', 'LuasnipIndicator' }}, virt_text_pos = 'right_align' } + active = { + virt_text = { { '<-- luasnip', 'LuasnipIndicator' } }, + virt_text_pos = 'right_align', + }, }, [types.insertNode] = { - unvisited = { hl_group = 'LuasnipIndicator' } + unvisited = { hl_group = 'LuasnipIndicator' }, }, [types.choiceNode] = { active = { - virt_text = {{'<-- choice node', 'LuasnipIndicator'}}, - } - } + virt_text = { { '<-- choice node', 'LuasnipIndicator' } }, + }, + }, }, snip_env = vim.tbl_extend('keep', ls.session.config.snip_env, { autowrap = autowrap, exec = exec, comment = comment, + file_contents = file_contents, user_email = { exec([[git config --get user.name]]), @@ -107,18 +135,16 @@ ls.setup { }), ls.t('>'), }, - }) -} + }), +}) -- snipmate snippets -require('luasnip.loaders.from_snipmate').lazy_load {paths = './after/snippets'} +require('luasnip.loaders.from_snipmate').lazy_load({ paths = './after/snippets' }) -- lua snippets -require("luasnip.loaders.from_lua").lazy_load {paths = './snippets'} +require('luasnip.loaders.from_lua').lazy_load({ paths = './snippets' }) -vim.api.nvim_create_user_command('LuaSnipUnlinkAll', - function() - while #package.loaded.luasnip.session.current_nodes > 0 do - package.loaded.luasnip.unlink_current() - end - end, - { desc = 'unlink all active snippets' }) +vim.api.nvim_create_user_command('LuaSnipUnlinkAll', function() + while #package.loaded.luasnip.session.current_nodes > 0 do + package.loaded.luasnip.unlink_current() + end +end, { desc = 'unlink all active snippets' }) diff --git a/.vim/lua/internal/spell.lua b/.vim/lua/internal/spell.lua index 57cbad2..3c37dad 100644 --- a/.vim/lua/internal/spell.lua +++ b/.vim/lua/internal/spell.lua @@ -1,8 +1,7 @@ - vim.opt_local.spell = true vim.opt.spellfile = vim.fn['spellfile#WritableSpellDir']() .. '/spellfile.utf-8.add' vim.opt.spellcapcheck = '' -vim.opt.spelloptions = {'camel'} +vim.opt.spelloptions = { 'camel' } vim.opt.spellsuggest = 'double' vim.keymap.set('n', '', require('telescope.builtin').spell_suggest) diff --git a/.vim/lua/internal/statusline.lua b/.vim/lua/internal/statusline.lua index 97f5031..1c09271 100644 --- a/.vim/lua/internal/statusline.lua +++ b/.vim/lua/internal/statusline.lua @@ -5,28 +5,21 @@ function _G.statusline() local sl = hi -- sl = sl .. statusline_append([[ ⢷]], 'StatusLineIcon', hi) - sl = sl .. statusline_append(statusline_lightbulb(), - 'StatusLineLightbulb', hi) + sl = sl .. statusline_append(statusline_lightbulb(), 'StatusLineLightbulb', hi) - sl = sl .. statusline_append(statusline_ts(), - 'StatusLineTreesitter', hi) + sl = sl .. statusline_append(statusline_ts(), 'StatusLineTreesitter', hi) - sl = sl .. statusline_append(statusline_lsp_diagnostics(bufnr, hi), - 'StatusLineDiagnostics', hi) + sl = sl .. statusline_append(statusline_lsp_diagnostics(bufnr, hi), 'StatusLineDiagnostics', hi) - sl = sl .. statusline_append(statusline_lspstatus(), - 'StatusLineLsp', hi) + sl = sl .. statusline_append(statusline_lspstatus(), 'StatusLineLsp', hi) - sl = sl .. statusline_append(statusline_dap(), - 'StatusLineDap', hi) + sl = sl .. statusline_append(statusline_dap(), 'StatusLineDap', hi) sl = sl .. [[ %= ]] -- spacer - sl = sl .. statusline_append(statusline_notify(hi), - 'StatusLineNotify', hi) + sl = sl .. statusline_append(statusline_notify(hi), 'StatusLineNotify', hi) - sl = sl .. statusline_append(statusline_spinner(bufnr), - 'StatusLineJobs', hi) + sl = sl .. statusline_append(statusline_spinner(bufnr), 'StatusLineJobs', hi) sl = sl .. statusline_append([[ %l:%v --%p%%-- %y]], hi, hi) @@ -49,83 +42,123 @@ function _G.statusline_color(mode) end -- does item highlighting and conditionnal spacing function _G.statusline_append(element, hi, default_hi, opts) - if not element or element == '' then return '' end + if not element or element == '' then + return '' + end opts = opts or { append_space = true } - if hi ~= nil then hi = '%#' .. hi .. '#' end - if not (default_hi == '%*') then hi = default_hi end + if hi ~= nil then + hi = '%#' .. hi .. '#' + end + if not (default_hi == '%*') then + hi = default_hi + end local el = hi .. element .. default_hi - if opts.append_space then el = el .. ' ' end + if opts.append_space then + el = el .. ' ' + end return el end function _G.statusline_combine_hi(outer_name, inner_name) local outer = vim.api.nvim_get_hl_by_id(vim.api.nvim_get_hl_id_by_name(outer_name), true) local inner = vim.api.nvim_get_hl_by_id(vim.api.nvim_get_hl_id_by_name(inner_name), true) local hi = 'auto' .. outer_name .. inner_name - if pcall(vim.api.nvim_get_hl_by_name, hi, true) then return hi end + if pcall(vim.api.nvim_get_hl_by_name, hi, true) then + return hi + end local gui gui = inner.bold and 'bold' gui = inner.italic and 'italic' gui = inner.underline and 'underline' - vim.api.nvim_set_hl(0, hi, {bg = outer.background, fg = inner.foreground, gui = gui}) + vim.api.nvim_set_hl(0, hi, { bg = outer.background, fg = inner.foreground, gui = gui }) return hi end function _G.statusline_lsp_diagnostics(bufnr, default_hi) - local error_num = vim.diagnostic.get(bufnr, {severity=vim.diagnostic.severity.ERROR}) - local warn_num = vim.diagnostic.get(bufnr, {severity=vim.diagnostic.severity.WARN}) + local error_num = vim.diagnostic.get(bufnr, { severity = vim.diagnostic.severity.ERROR }) + local warn_num = vim.diagnostic.get(bufnr, { severity = vim.diagnostic.severity.WARN }) local s = '' if #error_num > 0 then local errs = vim.fn.sign_getdefined('DiagnosticSignError')[1].text .. #error_num - s = s .. statusline_append(errs, statusline_combine_hi('StatusLineDiagnostics', 'DiagnosticError'), default_hi) + s = s + .. statusline_append( + errs, + statusline_combine_hi('StatusLineDiagnostics', 'DiagnosticError'), + default_hi + ) end if #warn_num > 0 then local warns = vim.fn.sign_getdefined('DiagnosticSignWarn')[1].text .. #warn_num - s = s .. statusline_append(warns, statusline_combine_hi('StatusLineDiagnostics', 'DiagnosticWarn'), default_hi) + s = s + .. statusline_append( + warns, + statusline_combine_hi('StatusLineDiagnostics', 'DiagnosticWarn'), + default_hi + ) end return vim.trim(s) end function _G.statusline_ts() local navic = package.loaded['nvim-navic'] - if not navic then return '' end + if not navic then + return '' + end local data = navic.get_data() - if not data then return '' end + if not data then + return '' + end local s = {} for i = 1, #data do - table.insert(s, string.format('%%#CmpItemKind%s#%s%%* %%#StatusLine#%s%%*', data[i].type, data[i].icon, data[i].name)) + table.insert( + s, + string.format( + '%%#CmpItemKind%s#%s%%* %%#StatusLine#%s%%*', + data[i].type, + data[i].icon, + data[i].name + ) + ) end return table.concat(s, ' > ') end function _G.statusline_lspstatus() local lst = package.loaded['lsp-status'] - if not lst then return '' end + if not lst then + return '' + end return vim.trim(lst.status()) end function _G.statusline_lightbulb() local lb = package.loaded['nvim-lightbulb'] - if not lb then return '' end + if not lb then + return '' + end return lb.get_status_text() end function _G.statusline_spinner(bufnr) local sp = package.loaded.spinner - if not sp then return '' end + if not sp then + return '' + end return sp.status(bufnr) end function _G.statusline_dap() local dap = package.loaded.dap - if not dap then return '' end + if not dap then + return '' + end local s = dap.status() - if s == '' then return s end + if s == '' then + return s + end return '[DAP: ' .. s .. ']' end --- notifications cache -_G.statusline_notifications = {} -_G.statusline_notifications_archive = {} - function _G.statusline_notify(default_hi) - if #_G.statusline_notifications == 0 then return '' end + if not _G.statusline_notifications or #_G.statusline_notifications == 0 then + return '' + end local n = _G.statusline_notifications[1] local timeout = (n.options and n.options.timeout) or 2000 -- pop message after and move to archive @@ -140,110 +173,18 @@ function _G.statusline_notify(default_hi) local s = '' if n.hi then - s = s .. statusline_append(n.lvl_string .. ' ', statusline_combine_hi('StatusLineNotify', n.hi), default_hi, { append_space = false }) + s = s + .. statusline_append( + n.lvl_string .. ' ', + statusline_combine_hi('StatusLineNotify', n.hi), + default_hi, + { append_space = false } + ) end - s = s .. statusline_append(n.message, 'StatusLineNotify', default_hi) + s = s .. statusline_append(vim.inspect(n.message), 'StatusLineNotify', default_hi) return vim.trim(s) end --- out vim.notify implementation -local notify = function(m, l, o) - local lvl_string = l - local hi = nil - if l and type(l) == 'number' then - if l == vim.log.levels.TRACE then - hi = 'deEmph' - elseif l == vim.log.levels.DEBUG then - hi = 'DiagnosticHint' - elseif l == vim.log.levels.INFO then - hi = 'DiagnosticInfo' - elseif l == vim.log.levels.WARN then - hi = 'DiagnosticWarn' - elseif l == vim.log.levels.ERROR then - hi = 'DiagnosticError' - end - -- get level string - lvl_string = vim.lsp.log_levels[l] - end - local display = m - if lvl_string then display = lvl_string .. ' ' .. display end - table.insert(_G.statusline_notifications, { - message = m, - level = l, - options = o, - lvl_string = lvl_string, - hi = hi, - display = display, - }) - - if _G.statusline_enable_notifysend then - local args = {} - if lvl_string then - if lvl_string == 'ERROR' then - table.insert(args, '--category=error') - end - if lvl_string == 'WARN' then - table.insert(args, '--category=warning') - end - end - table.insert(args, 'nvim') - table.insert(args, display) - require('internal.job').jobstart { command = 'notify-send', args = args } - end -end - --- overwrite vim.notify -vim.notify = function( m, l, o) - if vim.in_fast_event() then - vim.schedule(function() - notify(m, l, o) - end) - else - return notify(m, l, o) - end -end - -vim.keymap.set('n', 'n', function() - local pickers = require('telescope.pickers') - local finders = require('telescope.finders') - local conf = require('telescope.config').values - local actions = require('telescope.actions') - -- local action_state = require('telescope.actions.state') - -- local previewers = require('telescope.previewers') - - local opts = {} - pickers.new(opts, { - prompt_title = "Notifications", - finder = finders.new_dynamic { - fn = function() - return _G.statusline_notifications_archive - end, - entry_maker = function(n) - return { - value = n, - display = n.display, - ordinal = n.message, - } - end, - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr, _) - actions.select_default:replace(function() - actions.close(prompt_bufnr) - -- noop - -- local sel = action_state.get_selected_entry() - -- vim.notify(sel.value.message, sel.value.level, sel.value.options) - end) - return true - end, - -- previewer = previewers.new_buffer_previewer { - -- define_preview = function(self, entry) - -- vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, {entry.value.display}) - -- end, - -- }, - }):find() -end, {desc='notifications'}) - -- vim.opt.statusline = '%!luaeval("statusline()")' vim.opt.statusline = '%{%v:lua.statusline()%}' diff --git a/.vim/lua/plugins.lua b/.vim/lua/plugins.lua index cc008bc..d250a4a 100644 --- a/.vim/lua/plugins.lua +++ b/.vim/lua/plugins.lua @@ -1,485 +1,314 @@ --- vim: fdm=marker fdl=0 ----@diagnostic disable: undefined-global --- load by calling `lua require('plugins')` from init.vim - -local g = vim.g - --- force packer into a system directory {{{ -if not vim.fn.filewritable(vim.fn.stdpath('cache')) == 2 then --- TODO: what does this check for? - return -end - -local ensure_packer = function() - local install_path = vim.fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' - if vim.fn.empty(vim.fn.glob(install_path)) > 0 then - vim.notify('Installing packer.nvim...') - vim.fn.system({ 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }) - vim.cmd.packadd [[packer.nvim]] - return true - end - return false -end -local packer_bootstrapped = ensure_packer() --- }}} - -local function disable_distribution_plugins() -- {{{ - g.loaded_gzip = 1 - g.loaded_tar = 1 - g.loaded_tarPlugin = 1 - g.loaded_zip = 1 - g.loaded_zipPlugin = 1 - g.loaded_getscript = 1 - g.loaded_getscriptPlugin = 1 - g.loaded_vimball = 1 - g.loaded_vimballPlugin = 1 - g.loaded_matchit = 1 - -- g.loaded_matchparen = 1 - g.loaded_2html_plugin = 1 - g.loaded_logiPat = 1 - g.loaded_rrhelper = 1 - g.loaded_netrw = 1 - g.loaded_netrwPlugin = 1 - g.loaded_netrwSettings = 1 - g.loaded_netrwFileHandlers = 1 -end -- }}} - --- we change the packer.compile_path below, so we need to require it here... -local compilepath = vim.fn.stdpath('config') .. '/lua/packer_compiled.lua' -if not (vim.fn.empty(vim.fn.glob(compilepath)) > 0) then - require('packer_compiled') +-- disable distribution plugins +vim.g.loaded_gzip = 1 +vim.g.loaded_tar = 1 +vim.g.loaded_tarPlugin = 1 +vim.g.loaded_zip = 1 +vim.g.loaded_zipPlugin = 1 +vim.g.loaded_getscript = 1 +vim.g.loaded_getscriptPlugin = 1 +vim.g.loaded_vimball = 1 +vim.g.loaded_vimballPlugin = 1 +vim.g.loaded_matchit = 1 +-- vim.g.loaded_matchparen = 1 +vim.g.loaded_2html_plugin = 1 +vim.g.loaded_logiPat = 1 +vim.g.loaded_rrhelper = 1 +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 +vim.g.loaded_netrwSettings = 1 +vim.g.loaded_netrwFileHandlers = 1 + +local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + 'git', + 'clone', + '--filter=blob:none', + 'https://github.com/folke/lazy.nvim.git', + '--branch=stable', + lazypath, + }) end - -require('packer').startup({function() - -- auto-compile on save -- {{{ - do - vim.api.nvim_create_user_command('PackerRecompile', - function() - for _, client in pairs(vim.lsp.get_active_clients()) do - if vim.tbl_contains(client.config.filetypes, 'lua') then - client.stop() +vim.opt.rtp:prepend(lazypath) + +local pluginspec = { + { + 'lewis6991/gitsigns.nvim', + lazy = false, + opts = { + signs = { + change = { hl = 'GitSignsChange', text = '▋', numhl = 'GitSignsChangeLn' }, + add = { hl = 'GitSignsAdd', text = '▋', numhl = 'GitSignsAddLn' }, + delete = { hl = 'GitSignsDelete', text = '_', numhl = 'GitSignsDeleteLn' }, + topdelete = { hl = 'GitSignsDelete', text = '‾', numhl = 'GitSignsDeleteLn' }, + changedelete = { hl = 'GitSignsChange', text = '~', numhl = 'GitSignsChangeLn' }, + }, + signcolumn = true, + numhl = false, + linehl = false, + word_diff = false, + preview_config = { + border = _G.floating_win_border, + }, + on_attach = function(bufnr) + local gs = require('gitsigns') + vim.keymap.set('n', ']c', function() + if vim.wo.diff then + return ']c' end - end - vim.cmd [[luafile $HOME/.vim/lua/plugins.lua]] - vim.cmd [[PackerCompile]] - vim.notify('packer: lazy-loading refreshed') + vim.schedule(gs.next_hunk) + return '' + end, { buffer = bufnr, expr = true, desc = 'next hunk' }) + vim.keymap.set('n', '[c', function() + if vim.wo.diff then + return '[c' + end + vim.schedule(gs.prev_hunk) + return '' + end, { buffer = bufnr, expr = true, desc = 'previous hunk' }) + vim.keymap.set('n', 'hb', function() + gs.blame_line({ full = true }) + end, { buffer = bufnr, desc = 'show line blame (full)' }) + vim.keymap.set('n', 'hB', function() + gs.blame_line({ full = false }) + end, { buffer = bufnr, desc = 'show line blame (compact)' }) + vim.keymap.set( + 'n', + 'hp', + gs.preview_hunk, + { buffer = bufnr, desc = 'preview hunk' } + ) + vim.keymap.set('n', 'hd', gs.diffthis, { buffer = bufnr, desc = 'diff this' }) + vim.keymap.set('n', 'hl', function() + gs.setqflist(0, { open = false }) + vim.schedule(function() + require('telescope.builtin').quickfix() + end) + end, { buffer = bufnr, desc = 'list hunks' }) end, - {desc = 'recompile packer lazy-loading files'}) - - vim.api.nvim_create_autocmd('BufWritePost', { - pattern = 'plugins.lua', - command = [[PackerRecompile]], - group = vim.api.nvim_create_augroup('PackerAutoCompile', {}), - }) - end -- }}} - - -- run sync() if packer was just bootstrapped, usually means fresh install - if packer_bootstrapped then - -- require('packer').sync() - vim.cmd.PackerRecompile() - end - - -- disable built-in plugins - disable_distribution_plugins() - - -- manage packer itself - use {'wbthomason/packer.nvim'} - - -- improve startup time by optimizing lua `require` - use {'lewis6991/impatient.nvim'} - - -- neat helper for when you don't remember your keymap - use {'folke/which-key.nvim', -- {{{ - config = function() - require('which-key').setup { - icons = { separator = '→ ', group = '🞱 ' }, - triggers = {'', '', ';', 'g', '[', ']'}, - } - end} -- }}} - - use {'lewis6991/gitsigns.nvim', --- {{{ - requires = {'nvim-lua/plenary.nvim'}, - config = function() - require('gitsigns').setup { - signs = { - change = {hl='GitSignsChange', text='▋', numhl='GitSignsChangeLn'}, - add = {hl='GitSignsAdd', text='▋', numhl='GitSignsAddLn'}, - delete = {hl='GitSignsDelete', text='_', numhl='GitSignsDeleteLn'}, - topdelete = {hl='GitSignsDelete', text='‾', numhl='GitSignsDeleteLn'}, - changedelete = {hl='GitSignsChange', text='~', numhl='GitSignsChangeLn'}, - }, - signcolumn = true, - numhl = false, - linehl = false, - word_diff = false, - preview_config = { - border = _G.floating_win_border, - }, - - on_attach = function(bufnr) - local gs = package.loaded.gitsigns - - vim.keymap.set('n', ']c', function() - if vim.wo.diff then return ']c' end - vim.schedule(gs.next_hunk) - return '' - end, {expr=true, buffer=bufnr, desc='next hunk'}) - - vim.keymap.set('n', '[c', function() - if vim.wo.diff then return '[c' end - vim.schedule(gs.prev_hunk) - return '' - end, {expr=true, buffer=bufnr, desc='previous hunk'}) - - vim.keymap.set('n', 'hb', function() gs.blame_line {full=true} end, {buffer=bufnr, desc='show line blame (full)'}) - vim.keymap.set('n', 'hB', function() gs.blame_line {full=false} end, {buffer=bufnr, desc='show line blame (compact)'}) - vim.keymap.set('n', 'hp', gs.preview_hunk, {buffer=bufnr, desc='preview hunk'}) - vim.keymap.set('n', 'hd', gs.diffthis, {buffer=bufnr, desc='diff this'}) - vim.keymap.set('n', 'hl', function() - gs.setqflist(0, {open=false}) - vim.schedule(function() require('telescope.builtin').quickfix() end) - end, {buffer=bufnr, desc='list hunks'}) - end, - } - end} -- }}} + }, + }, - use {'lukas-reineke/indent-blankline.nvim', -- {{{ - config = function() - require('indent_blankline').setup { - char = '▏', - char_highlight_list = {'Whitespace'}, - -- space_char = ' ', - -- space_char_highlight_list = {}, - show_first_indent_level = true, - show_trailing_blankline_indent = false, - show_end_of_line = true, - use_treesitter = true, - disable_with_nolist = true, - buftype_exclude = {'terminal'}, - bufname_exclude = {'README.md'}, - strict_tabs = true, - show_current_context = true, - context_patterns = {'class', 'function', 'method', 'block'}, - -- context_highlight_list = {'Folded'}, - context_highlight_list = {'deEmph'}, - } - end} -- }}} + { + 'lukas-reineke/indent-blankline.nvim', + lazy = false, + opts = { + char = '▏', + char_highlight_list = { 'Whitespace' }, + -- space_char = ' ', + -- space_char_highlight_list = {}, + show_first_indent_level = true, + show_trailing_blankline_indent = false, + show_end_of_line = true, + use_treesitter = true, + disable_with_nolist = true, + buftype_exclude = { 'terminal' }, + bufname_exclude = { 'README.md' }, + filetype_exclude = { 'alpha' }, + strict_tabs = true, + show_current_context = true, + context_patterns = { 'class', 'function', 'method', 'block' }, + -- context_highlight_list = {'Folded'}, + context_highlight_list = { 'deEmph' }, + }, + }, - -- gcc to comment out text - use {'numToStr/Comment.nvim', -- {{{ - config = function() - require('Comment').setup { - opleader = { - block = 'gC', - } - } - end} -- }}} + { + 'numToStr/Comment.nvim', + opts = { + opleader = { block = 'gC' }, + }, + keys = { + 'gcc', + { 'gc', mode = 'v' }, + { 'gC', mode = 'v' }, + }, + }, - use {'editorconfig/editorconfig-vim', -- {{{ + { + 'editorconfig/editorconfig-vim', + event = 'VeryLazy', config = function() - local group = vim.api.nvim_create_augroup('EditorConfigDisable', { clear = true }) vim.api.nvim_create_autocmd('FileType', { - pattern = {'gitcommit'}, + pattern = { 'gitcommit' }, command = [[let b:EditorConfig_disable = 1]], - group = group, + group = vim.api.nvim_create_augroup('EditorConfigDisable', {}), }) - end} -- }}} + end, + }, - use {'windwp/nvim-autopairs', -- {{{ - config = function() - require('nvim-autopairs').setup() - end} -- }}} + { 'windwp/nvim-autopairs', priority = 40, event = 'InsertEnter', config = true }, - use {'elihunter173/dirbuf.nvim', -- {{{ + { + 'elihunter173/dirbuf.nvim', + lazy = false, config = function() - require('dirbuf').setup { + require('dirbuf').setup({ hash_padding = 4, sort_order = 'directories_first', - } + }) vim.api.nvim_create_autocmd('FileType', { pattern = 'dirbuf', callback = function() vim.keymap.set('n', 'gT', function() - vim.loop.spawn('swaymsg', {args = {'exec', '--', 'foot', '-D', vim.fn.expand('%')}}) + vim.loop.spawn('swaymsg', { args = { 'exec', '--', 'foot', '-D', vim.fn.expand('%') } }) -- vim.fn.system('swaymsg exec -- foot -D ' .. vim.fn.expand('%')) - end, {buffer=0, desc='open in foot terminal'}) + end, { buffer = 0, desc = 'open in foot terminal' }) end, group = vim.api.nvim_create_augroup('DirBufEnter', {}), }) - end} -- }}} - - _G.treesitter_enabled = { -- {{{ - 'bash', - 'bibtex', - 'c', - 'c_sharp', - 'cpp', - 'cmake', - 'comment', - 'css', - 'dockerfile', - -- 'elixir', - 'go', - 'gomod', - 'gowork', - 'hcl', - 'help', - 'html', - 'java', - 'javascript', - 'json', - 'jsonc', - 'latex', - 'ledger', - 'lua', - 'make', - 'markdown', - 'markdown_inline', - 'ninja', - 'norg', - 'regex', - 'rust', - 'scss', - 'toml', - 'typescript', - 'vim', - 'yaml', - 'zig', + end, + }, - 'org', - 'hare', - 'gotmpl', - 'vimdoc', - } -- }}} - use {'nvim-treesitter/nvim-treesitter', -- {{{ - run = ':TSUpdate', - requires = { - 'nvim-treesitter/nvim-treesitter-refactor', - 'nvim-treesitter/nvim-treesitter-textobjects', - 'nvim-treesitter/playground', - }, - config = function() + { + 'nvim-treesitter/nvim-treesitter', + lazy = false, + build = ':TSUpdate', + config = function(_, opts) local tsconf = require('nvim-treesitter.parsers').get_parser_configs() - tsconf.org = { - install_info = { - url = 'https://github.com/milisims/tree-sitter-org', - files = {'src/parser.c', 'src/scanner.cc'}, - revision = 'main', - } - } tsconf.hare = { install_info = { url = 'https://git.sr.ht/~ecmma/tree-sitter-hare', - files = {'src/parser.c'}, - } + files = { 'src/parser.c' }, + }, } tsconf.gotmpl = { install_info = { url = 'https://github.com/ngalaiko/tree-sitter-go-template', - files = {'src/parser.c'}, + files = { 'src/parser.c' }, }, filetype = 'gotmpl', - used_by = {'gotmpl.html', 'gotmpl.yaml', 'gotmpl'}, + used_by = { 'gotmpl.html', 'gotmpl.yaml', 'gotmpl' }, } - - require('nvim-treesitter.configs').setup { - ensure_installed = _G.treesitter_enabled, - disable = {'jsonc'}, - highlight = { - enable = true, - additional_vim_regex_highlighting = {'markdown'}, - }, - indent = { - enable = true, + require('nvim-treesitter.configs').setup(opts) + end, + opts = { + ensure_installed = { + 'bash', + 'bibtex', + 'c', + 'c_sharp', + 'cpp', + 'cmake', + 'comment', + 'css', + 'dockerfile', + -- 'elixir', + 'go', + 'gomod', + 'gowork', + 'hcl', + 'help', + 'html', + 'java', + 'javascript', + 'json', + 'jsonc', + 'latex', + 'ledger', + 'lua', + 'make', + 'markdown', + 'markdown_inline', + 'ninja', + 'norg', + 'regex', + 'rust', + 'scss', + 'toml', + 'typescript', + 'vim', + 'yaml', + 'zig', + -- experimental + 'hare', + 'gotmpl', + }, + -- disable = { 'jsonc' }, + highlight = { + enable = true, + additional_vim_regex_highlighting = { 'markdown' }, + }, + indent = { + enable = true, + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = 'gnn', + node_incremental = 'grn', + node_decremental = 'grm', }, - incremental_selection = { + }, + refactor = { + navigation = { enable = true, keymaps = { - init_selection = 'gnn', - node_incremental = 'grn', - node_decremental = 'grm', + goto_definition = '', }, }, - refactor = { - navigation = { - enable = true, - keymaps = { - goto_definition = "", - }, - }, - smart_rename = { - enable = true, - keymaps = { - smart_rename = "grr", - }, + smart_rename = { + enable = true, + keymaps = { + smart_rename = 'grr', }, }, - textobjects = { - select = { - enable = true, - keymaps = { - ["ib"] = '@block.inner', - ["ob"] = '@block.outer', - ["ic"] = '@conditional.inner', - ["oc"] = '@conditional.outer', - ["if"] = '@function.inner', - ["of"] = '@function.outer', - ["il"] = '@loop.inner', - ["ol"] = '@loop.outer', - ["is"] = '@scopename.inner', - ["os"] = '@scopename.outer', - }, + }, + textobjects = { + select = { + enable = true, + keymaps = { + ['ib'] = '@block.inner', + ['ob'] = '@block.outer', + ['ic'] = '@conditional.inner', + ['oc'] = '@conditional.outer', + ['if'] = '@function.inner', + ['of'] = '@function.outer', + ['il'] = '@loop.inner', + ['ol'] = '@loop.outer', + ['is'] = '@scopename.inner', + ['os'] = '@scopename.outer', }, }, - } - end} -- }}} - - use {'neovim/nvim-lspconfig', -- {{{ + }, + }, + }, + { 'nvim-treesitter/nvim-treesitter-refactor', keys = { '', 'grr' } }, + { + 'nvim-treesitter/nvim-treesitter-textobjects', + keys = { 'ib', 'ob', 'ic', 'oc', 'if', 'of', 'il', 'ol', 'is', 'os' }, + }, + { 'nvim-treesitter/playground', cmd = 'TSPlaygroundToggle' }, + + { + 'neovim/nvim-lspconfig', + lazy = false, + -- event = 'InsertEnter', + priority = 100, + dependencies = { + { + 'nvim-lua/lsp-status.nvim', + config = function() + local lspstatus = require('lsp-status') + lspstatus.config({ + diagnostics = false, + current_function = false, + status_symbol = '', + }) + lspstatus.register_progress() + end, + }, + }, config = function() require('telescope').load_extension('lsp_handlers') require('internal.lsp').setup() - end} -- }}} - - use {'nvim-lua/lsp-status.nvim', module = {'lsp-status'}, -- {{{ - config = function() - local lspstatus = require('lsp-status') - lspstatus.config { - diagnostics = false, - current_function = false, - status_symbol = '', - } - lspstatus.register_progress() - end} -- }}} - - use {'stevearc/aerial.nvim', module = {'aerial'}, cmd = {'AerialOpen', 'AerialToggle'}, disable = false, -- {{{ - config = function() - require('aerial').setup({ - backends = { 'lsp', 'treesitter', 'markdown' }, - filter_kind = { - -- default: - 'Class', - 'Constructor', - 'Enum', - 'Function', - 'Interface', - 'Module', - 'Method', - 'Struct', - -- custom: - 'Constant', - 'Variable', - }, - icons = require('internal.lsp').symbols, - close_automatic_events = { 'unsupported' }, - placement = 'edge', - open_automatic = false, - -- open_automatic = function(bufnr) - -- return vim.api.nvim_buf_line_count(bufnr) > 200 - -- and package.loaded.aerial.num_symbols(bufnr) > 4 - -- and not package.loaded.aerial.was_closed() - -- end, - default_keybinds = false, - show_guides = true, - }) - -- TODO: https://github.com/neovim/neovim/issues/18660 - -- vim.api.nvim_create_autocmd('FileType', { pattern = 'aerial', - -- callback = function() vim.opt_local.winbar = '' end, - -- }) - end} --- }}} - - use {'SmiteshP/nvim-navic', module = 'nvim-navic', -- {{{ - requires = {'neovim/nvim-lspconfig'}, - config = function() - local navic = require('nvim-navic') - navic.setup { - icons = require('internal.lsp').symbols, - } - end} -- }}} - - use {'kosayoda/nvim-lightbulb', disable = true, -- {{{ - config = function() - require('nvim-lightbulb').setup { - ignore = {'null-ls'}, - sign = { enabled = false }, - virtual_text = { enabled = false, text = '← 󰌵' }, - status_text = { enabled = true, text = '󰌵', text_unavailable = '' }, - autocmd = { enabled = true }, - } - vim.fn.sign_define({{name='LightBulbSign', text='󰌵', texthl='LightBulbSign'}}) - end} -- }}} - - use {'weilbith/nvim-code-action-menu', - config = function() - vim.lsp.handlers['textDocument/codeAction'] = require('code_action_menu').open_code_action_menu - end} - - use {'jose-elias-alvarez/null-ls.nvim', -- {{{ - requires = {'nvim-lua/plenary.nvim'}, - config = function() - local nls = require('null-ls') - nls.setup { - -- debug = true, - sources = { - nls.builtins.diagnostics.shellcheck, - nls.builtins.formatting.shfmt, - nls.builtins.formatting.yapf, -- python - -- nls.builtins.formatting.clang_format, - -- nls.builtins.formatting.gofumpt, - -- nls.builtins.formatting.json_tool, - -- nls.builtins.formatting.rustfmt, - -- nls.builtins.formatting.stylua, - }, - on_attach = require('internal.lsp').my_attach, - } - - local h = require('null-ls.helpers') - - nls.register({ - h.make_builtin({ - name = 'html-beautify', - filetypes = {'html', 'gotmpl.html'}, - method = nls.methods.FORMATTING, - generator_opts = { - command = vim.env.HOME .. '/.yarn/bin/html-beautify', - args = {'--file', '-', '--editorconfig'}, - to_stdin = true, - }, - factory = h.formatter_factory, - }), - h.make_builtin({ - name = 'html-beautify', - filetypes = {'html', 'gotmpl.html'}, - method = nls.methods.FORMATTING, - generator_opts = { - command = vim.env.HOME .. '/.yarn/bin/html-beautify', - args = {'--file', '-', '--editorconfig'}, - to_stdin = true, - }, - factory = h.formatter_factory, - }), - h.make_builtin({ - name = 'css-beautify', - filetypes = {'css', 'scss'}, - method = nls.methods.FORMATTING, - generator_opts = { - command = vim.env.HOME .. '/.yarn/bin/css-beautify', - args = {'--file', '-', '--editorconfig'}, - to_stdin = true, - }, - factory = h.formatter_factory, - }), - }) - end} -- }}} - - use {'mfussenegger/nvim-dap', module = {'dap'}, -- {{{ - requires = {'nvim-telescope/telescope-dap.nvim'}, - config = function() - require('telescope').load_extension('dap') - require('internal.dap') - end} -- }}} + end, + }, - use {'hrsh7th/nvim-cmp', -- {{{ - requires = { + { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + dependencies = { -- 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-path', @@ -489,130 +318,102 @@ require('packer').startup({function() 'hrsh7th/cmp-nvim-lsp-signature-help', 'saadparwaiz1/cmp_luasnip', 'f3fora/cmp-spell', - 'windwp/nvim-autopairs', - 'neovim/nvim-lspconfig', }, config = function() local cmp = require('cmp') local luasnip = require('luasnip') - cmp.setup { + cmp.setup({ + experimental = { ghost_text = true }, -- disable completion in comments enabled = function() - local ctx = require('cmp.config.context') - if vim.api.nvim_get_mode().mode == 'c' then + local ok, enable = pcall(function() + local ctx = require('cmp.config.context') + if vim.api.nvim_get_mode().mode == 'i' then + if ctx.in_treesitter_capture('comment') or ctx.in_syntax_group('Comment') then + return false + end + if vim.opt.filetype:get() == 'TelescopePrompt' then + return false + end + end return true - else - return ctx.in_treesitter_capture('comment') - and not ctx.in_syntax_group('Comment') - end + end) + return not ok or enable end, preselect = cmp.PreselectMode.Item, window = { + completion = { + border = 'none', + }, documentation = { - border = _G.floating_win_border, + border = 'solid', }, }, - mapping = { -- {{{2 - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.mapping.confirm({ select = true }) - elseif luasnip.expandable() then - luasnip.expand() - else - fallback() - end - end), + mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.complete(), + [''] = cmp.mapping(function(fallback) + if luasnip.expandable() then + luasnip.expand() + elseif cmp.visible() then + cmp.mapping.confirm({ select = true }) + else + fallback() + end + end), [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.locally_jumpable(1) then - luasnip.jump(1) - else - fallback() - end - end, { 'c', 'i', 's', 'n' }), + if luasnip.locally_jumpable(1) then + luasnip.jump(1) + elseif cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end), [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { 'c', 'i', 's', 'n' }), - [''] = cmp.mapping({ - i = function(fallback) - if cmp.visible() then - cmp.mapping.confirm({ select = true }) - elseif luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, - s = function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, - c = function(fallback) - if cmp.visible() then - cmp.select_next_item() - else - fallback() - end - end, - }), - [''] = cmp.mapping({ - i = function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, - s = function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, - c = function(fallback) - if cmp.visible() then - cmp.select_prev_item() - else - fallback() - end - end, - }), + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + elseif cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end), + [''] = cmp.mapping(function(fallback) + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + elseif cmp.visible() then + cmp.mapping.confirm({ select = true }) + else + fallback() + end + end), + [''] = cmp.mapping(function(fallback) + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + elseif cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end), -- map c-j/k for luasnip choice nodes [''] = cmp.mapping(function(fallback) - if luasnip.choice_active() then - luasnip.change_choice(1) - else - fallback() - end - end, { 'i', 's'}), + if luasnip.choice_active() then + luasnip.change_choice(1) + else + fallback() + end + end, { 'i', 's' }), [''] = cmp.mapping(function(fallback) - if luasnip.choice_active() then - luasnip.change_choice(-1) - else - fallback() - end - end, { 'i', 's'}), + if luasnip.choice_active() then + luasnip.change_choice(-1) + else + fallback() + end + end, { 'i', 's' }), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), - }, -- 2}}} + }), snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) @@ -624,79 +425,100 @@ require('packer').startup({function() { name = 'luasnip' }, { name = 'nvim_lua' }, }, { - { name = 'neorg' }, + -- { name = 'neorg' }, -- { name = 'orgmode' }, { name = 'spell', keyword_length = 3, max_item_count = 5 }, { name = 'path' }, -- { name = 'buffer', keyword_length = 3 }, }), formatting = { - fields = {'kind', 'abbr', 'menu'}, + fields = { 'kind', 'abbr', 'menu' }, format = function(entry, item) local menus = { nvim_lsp = '░ lsp', - luasnip = '░ snip', + luasnip = '░ snip', nvim_lua = '░ nvim', -- orgmode = '░ org', - spell = '░ spell', - path = '░ path', - buffer = '░ buf', + spell = '░ spell', + path = '░ path', + buffer = '░ buf', } - item.kind = require('internal.lsp').symbols[item.kind] or '' + item.kind = require('internal.lsp_symbols')[item.kind] or '' item.menu = menus[entry.source.name] return item end, }, - } - cmp.setup.cmdline({'/', '?', '@'}, { + }) + cmp.setup.cmdline({ '/', '?', '@' }, { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = 'nvim_lsp_document_symbol' }, - { name = 'buffer' } + -- { name = 'buffer' } }), formatting = { - fields = {'abbr', 'menu'}, + fields = { 'abbr', 'menu' }, }, }) cmp.setup.cmdline(':', { mapping = vim.tbl_extend('force', cmp.mapping.preset.cmdline(), { - [''] = cmp.mapping({ c = function() vim.cmd.Telescope 'command_history' end}), + [''] = cmp.mapping({ + c = function() + vim.cmd.Telescope('command_history') + end, + }), }), sources = cmp.config.sources({ { name = 'path' }, }, { - { name = 'cmdline' } + { name = 'cmdline' }, }), formatting = { - fields = {'abbr', 'menu'}, + fields = { 'abbr', 'menu' }, }, }) - -- insert `(` after selecting function/method items - cmp.event:on('confirm_done', require('nvim-autopairs.completion.cmp').on_confirm_done { - map_char = {tex = ''} - }) - end} -- }}} + cmp.event:on( + 'confirm_done', + require('nvim-autopairs.completion.cmp').on_confirm_done({ + map_char = { tex = '' }, + }) + ) + end, + }, - use {'L3MON4D3/LuaSnip', -- {{{ + { + 'L3MON4D3/LuaSnip', config = function() require('internal.snips') - end} -- }}} + end, + }, - use {'nvim-telescope/telescope.nvim', --- {{{ - requires = { + { + 'nvim-telescope/telescope.nvim', + cmd = 'Telescope', + dependencies = { 'nvim-lua/popup.nvim', 'nvim-lua/plenary.nvim', - -- telescope plugins: - {'nvim-telescope/telescope-fzf-native.nvim', run = 'make'}, - {'nvim-telescope/telescope-ui-select.nvim'}, - {'gbrlsnchs/telescope-lsp-handlers.nvim'}, + { + 'nvim-telescope/telescope-fzf-native.nvim', + build = 'make', + config = function() + require('telescope').load_extension('fzf') + end, + }, + { + 'nvim-telescope/telescope-ui-select.nvim', + config = function() + require('telescope').load_extension('ui-select') + end, + }, + 'gbrlsnchs/telescope-lsp-handlers.nvim', }, config = function() - require('telescope').setup{ + require('telescope').setup({ defaults = { - prompt_prefix = '> ', - selection_caret = '* ', + prompt_prefix = '', + selection_caret = '⯈ ', sorting_strategy = 'ascending', preview = false, @@ -707,18 +529,15 @@ require('packer').startup({function() -- preview_cutoff = 1, -- height = 20, }, - border = true, borderchars = { - preview = { '─', '│', '─', '│', '┌', '┐', '┘', '└'}, - prompt = { '─', ' ', ' ', ' ', '─', '─', ' ', ' ' }, + preview = { '─', '│', '─', '│', '┌', '┐', '┘', '└' }, + prompt = { '─', '', '', '', '╾', '╼', '', '' }, results = { '' }, }, - - file_previewer = require('telescope.previewers').vim_buffer_cat.new, - grep_previewer = require('telescope.previewers').vim_buffer_vimgrep.new, + file_previewer = require('telescope.previewers').vim_buffer_cat.new, + grep_previewer = require('telescope.previewers').vim_buffer_vimgrep.new, qflist_previewer = require('telescope.previewers').vim_buffer_qflist.new, - mappings = { i = { [''] = require('telescope.actions.layout').toggle_preview, @@ -727,341 +546,536 @@ require('packer').startup({function() [''] = require('telescope.actions.layout').toggle_preview, }, }, - - extensions = { - ['fzf'] = { - fuzzy = true, - override_generic_sorter = true, - override_file_sorter = true, - case_mode = 'smart_case', - }, - - ['lsp_handlers'] = { - disable = { - -- ['textDocument/codeAction'] = true, - }, + }, + extensions = { + ['fzf'] = { + fuzzy = true, + override_generic_sorter = true, + override_file_sorter = true, + case_mode = 'smart_case', + }, + ['lsp_handlers'] = { + disable = { + -- ['textDocument/codeAction'] = true, }, - - ['ui-select'] = { - require("telescope.themes").get_cursor { - initial_mode = 'normal', - previewer = false, - } - } - } - } - } - - -- required to get fzf-native working - require('telescope').load_extension('fzf') - require('telescope').load_extension('ui-select') - - vim.keymap.set('n', ';Q', require('telescope.builtin').quickfix, {desc='quickfix'}) - vim.keymap.set('n', ';C', require('telescope.builtin').loclist, {desc='loclist'}) - vim.keymap.set('n', ';H', require('telescope.builtin').help_tags, {desc='help_tags'}) - vim.keymap.set('n', ';b', require('telescope.builtin').buffers, {desc='buffer'}) - vim.keymap.set('n', ';c', require('telescope.builtin').commands, {desc='commands'}) - vim.keymap.set('n', ';f', require('telescope.builtin').fd, {desc='fd'}) - vim.keymap.set('n', ';g', require('telescope.builtin').live_grep, {desc='grep'}) - vim.keymap.set('n', ';h', require('telescope.builtin').command_history, {desc='command history'}) - vim.keymap.set('n', ';l', require('telescope.builtin').current_buffer_fuzzy_find, {desc='buffer'}) - vim.keymap.set('n', ';o', require('telescope.builtin').oldfiles, {desc='oldfiles'}) - vim.keymap.set('n', ';d', require('telescope.builtin').diagnostics, {desc='diagnostics'}) - vim.keymap.set('n', ';v', function() + }, + ['ui-select'] = { + require('telescope.themes').get_cursor({ + initial_mode = 'normal', + previewer = false, + }), + }, + }, + }) + end, + keys = { + { + ';Q', + function() + require('telescope.builtin').quickfix() + end, + desc = 'quickfix', + }, + { + ';C', + function() + require('telescope.builtin').loclist() + end, + desc = 'loclist', + }, + { + ';H', + function() + require('telescope.builtin').help_tags() + end, + desc = 'help_tags', + }, + { + ';b', + function() + require('telescope.builtin').buffers() + end, + desc = 'buffer', + }, + { + ';c', + function() + require('telescope.builtin').commands() + end, + desc = 'commands', + }, + { + ';f', + function() + require('telescope.builtin').fd() + end, + desc = 'fd', + }, + { + ';g', + function() + require('telescope.builtin').live_grep() + end, + desc = 'grep', + }, + { + ';h', + function() + require('telescope.builtin').command_history() + end, + desc = 'command history', + }, + { + ';l', + function() + require('telescope.builtin').current_buffer_fuzzy_find() + end, + desc = 'buffer', + }, + { + ';o', + function() + require('telescope.builtin').oldfiles() + end, + desc = 'oldfiles', + }, + { + ';d', + function() + require('telescope.builtin').diagnostics() + end, + desc = 'diagnostics', + }, + { + ';v', + function() require('telescope.builtin').find_files({ prompt_title = 'vimrc', previewer = false, cwd = vim.fn.stdpath('config'), }) - end, {desc='vim config'}) - - vim.keymap.set('n', 'gw', function() - misc.word_under_cursor(function(s) require('telescope.builtin').grep_string({ search = s }) end) - end, {desc='grep for word under cursor'}) - -- vim.keymap.set('n', 'ge', function() - -- misc.expr_under_cursor(function(s) require('telescope.builtin').grep_string({ search = s }) end) - -- end) - -- vim.keymap.set('n', 'gf', function() - -- misc.file_under_cursor(function(s) require('telescope.builtin').grep_string({ search = s }) end) - -- end) - end} -- }}} + end, + desc = 'vim config', + }, + { + 'gw', + function() + require('internal.misc').word_under_cursor(function(s) + require('telescope.builtin').grep_string({ search = s }) + end) + end, + desc = 'grep for word under cursor', + }, + }, + }, - use {'tpope/vim-surround'} - use {'tpope/vim-repeat'} -- extend '.' to plugins - use {'michaeljsmith/vim-indent-object'} -- indentation text-objects - use {'kshenoy/vim-signature', disable = true} -- toggle, display and navigate marks - use {'norcalli/nvim-colorizer.lua', -- {{{ + { + 'norcalli/nvim-colorizer.lua', + -- event = 'VeryLazy', config = function() require('colorizer').setup(nil, { - name = true; - RRGGBB = true; - RRGGBBAA = false; - rgb_fn = true; - hsl_fn = true; - mode = 'background'; + name = true, + RRGGBB = true, + RRGGBBAA = false, + rgb_fn = true, + hsl_fn = true, + mode = 'background', }) - end} -- }}} + end, + }, + + { 'gentoo/gentoo-syntax', lazy = false }, + + { + 'NMAC427/guess-indent.nvim', + opts = { + auto_cmd = true, + filetype_exclude = { 'netrw', 'tutor', 'dirbuf' }, + buftype_exclude = { 'help', 'nofile', 'terminal', 'prompt' }, + }, + }, - use {'rhysd/conflict-marker.vim', disable = true} - use {'kassio/neoterm', disable = true} + { + url = 'https://git.sr.ht/~robertgzr/spinner.nvim', + opts = { + spinner = { '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏' }, + interval = 120, -- spinner frame rate in ms + }, + }, - use {'kristijanhusak/orgmode.nvim', ft = {'org'}, module = {'orgmode'}, disable = true, -- {{{ + { + 'stevearc/aerial.nvim', + cmd = { 'AerialOpen', 'AerialToggle' }, + opts = { + backends = { 'lsp', 'treesitter', 'markdown' }, + filter_kind = { + -- default: + 'Class', + 'Constructor', + 'Enum', + 'Function', + 'Interface', + 'Module', + 'Method', + 'Struct', + -- custom: + 'Constant', + 'Variable', + }, + icons = require('internal.lsp_symbols'), + close_automatic_events = { 'unsupported' }, + placement = 'edge', + open_automatic = false, + -- open_automatic = function(bufnr) + -- return vim.api.nvim_buf_line_count(bufnr) > 200 + -- and package.loaded.aerial.num_symbols(bufnr) > 4 + -- and not package.loaded.aerial.was_closed() + -- end, + default_keybinds = false, + show_guides = true, + }, + }, + + { + 'SmiteshP/nvim-navic', + opts = { + icons = require('internal.lsp_symbols'), + }, + }, + + -- {'kosayoda/nvim-lightbulb', + -- config = { + -- ignore = {'null-ls'}, + -- sign = { enabled = false }, + -- virtual_text = { enabled = false, text = '← 󰌵' }, + -- status_text = { enabled = true, text = '󰌵', text_unavailable = '' }, + -- autocmd = { enabled = true }, + -- }, + -- init = function() + -- vim.fn.sign_define({{name='LightBulbSign', text='󰌵', texthl='LightBulbSign'}}) + -- end, + -- }, + + { + 'weilbith/nvim-code-action-menu', + event = 'VeryLazy', config = function() - require('orgmode').setup_ts_grammar() - require('orgmode').setup { - org_agenda_files = {vim.env.HOME..'/Documents/org/*.org'}, - org_default_notes_file = vim.env.HOME..'/Documents/org/todo.org', - org_todo_keywords = {'TODO', 'DONE'}, - -- org_indent_mode = 'noindent', - org_agenda_templates = { - t = { - description = 'Todo', - template = '* TODO %?', - }, - n = { - description = 'Note', - template = '* %?', - target = vim.env.HOME..'/Documents/org/notes.org', - }, - }, - mappings = { - agenda = { - org_agenda_close = nil, - } + vim.lsp.handlers['textDocument/codeAction'] = + require('code_action_menu').open_code_action_menu + end, + }, + + { + 'jose-elias-alvarez/null-ls.nvim', + ft = { 'sh', 'bash', 'lua', 'rust', 'c', 'cpp' }, + dependencies = { 'nvim-lua/plenary.nvim' }, + config = function() + local nls = require('null-ls') + nls.setup({ + -- debug = true, + sources = { + nls.builtins.diagnostics.shellcheck, + nls.builtins.formatting.shfmt, + nls.builtins.formatting.yapf, -- python + nls.builtins.formatting.clang_format, + nls.builtins.formatting.rustfmt, + nls.builtins.formatting.stylua, + -- nls.builtins.formatting.gofumpt, + -- nls.builtins.formatting.json_tool, }, - } + on_attach = require('internal.lsp').my_attach, + }) + + local h = require('null-ls.helpers') - local pickers = require('telescope.pickers') - local finders = require('telescope.finders') + nls.register({ + h.make_builtin({ + name = 'html-beautify', + filetypes = { 'html', 'gotmpl.html' }, + method = nls.methods.FORMATTING, + generator_opts = { + command = vim.env.HOME .. '/.yarn/bin/html-beautify', + args = { '--file', '-', '--editorconfig' }, + to_stdin = true, + }, + factory = h.formatter_factory, + }), + h.make_builtin({ + name = 'html-beautify', + filetypes = { 'html', 'gotmpl.html' }, + method = nls.methods.FORMATTING, + generator_opts = { + command = vim.env.HOME .. '/.yarn/bin/html-beautify', + args = { '--file', '-', '--editorconfig' }, + to_stdin = true, + }, + factory = h.formatter_factory, + }), + h.make_builtin({ + name = 'css-beautify', + filetypes = { 'css', 'scss' }, + method = nls.methods.FORMATTING, + generator_opts = { + command = vim.env.HOME .. '/.yarn/bin/css-beautify', + args = { '--file', '-', '--editorconfig' }, + to_stdin = true, + }, + factory = h.formatter_factory, + }), + }) + end, + }, - vim.keymap.set('s', ';O', function() - pickers.new(opts, { - prompt_title = 'Orgmode', - finder = finders.new_table(require('orgmode.config'):get_all_files()), - }):find() - end) + { + 'mfussenegger/nvim-dap', + dependencies = { 'nvim-telescope/telescope-dap.nvim' }, + config = function() + require('telescope').load_extension('dap') + require('internal.dap') + end, + keys = { 'd' }, + }, - -- wk_register { - -- ['o'] = {name = '+Orgmode', - -- a = {'agenda prompt'}, - -- c = {'capture prompt'}, - -- r = {'refile'}, - -- [','] = {'set priority'}, - -- ['*'] = {'toggle headline'}, - -- ['o'] = {'follow link/date'}, - -- ['\''] = {'create source block'}, - -- ['$'] = {'archive current headline'}, - -- [''] = {'insert heading/item/row'}, - -- t = {'set tags'}, - -- A = {'toggle ARCHIVE tag'}, - -- K = {'subtree up'}, - -- J = {'subtree down'}, - -- e = {'export'}, - -- ['i'] = { - -- name = '+Timestamp', - -- d = {'set deadline'}, - -- s = {'set scheduled'}, - -- h = {'insert heading (respect content)'}, - -- T = {'insert todo'}, - -- t = {'insert todo (respect content)'}, - -- ['.'] = {'set date'}, - -- ['!'] = {'set inactive'}, - -- }, - -- ['x'] = { - -- name = '+Clock', - -- i = {'clock in'}, - -- o = {'clock out'}, - -- q = {'cancel active clock'}, - -- j = {'jump to active clock'}, - -- e = {'set effort estimate property'}, - -- } - -- }, - -- } - end} -- }}} + { 'farmergreg/vim-lastplace', event = 'VeryLazy' }, -- restore last cursor position (and handle many edge cases) + { 'tpope/vim-surround', event = 'VeryLazy' }, + { 'tpope/vim-repeat', event = 'VeryLazy' }, -- extend '.' to plugins + { 'michaeljsmith/vim-indent-object', event = 'VeryLazy' }, -- indentation text-objects + -- {'kshenoy/vim-signature'}, -- toggle, display and navigate marks + -- {'rhysd/conflict-marker.vim'}, + -- {'kassio/neoterm'}, + + { + 'kristijanhusak/orgmode.nvim', + ft = 'org', + build = function() + require('orgmode').setup_ts_grammar() + vim.cmd.TSUpdate() + end, + opts = { + org_agenda_files = { vim.env.HOME .. '/documents/org/*.org' }, + org_default_notes_file = vim.env.HOME .. '/documents/org/todo.org', + org_todo_keywords = { 'TODO', 'DONE' }, + -- org_indent_mode = 'noindent', + org_agenda_templates = { + t = { + description = 'Todo', + template = '* TODO %?', + }, + n = { + description = 'Note', + template = '* %?', + target = vim.env.HOME .. '/documents/org/notes.org', + }, + }, + mappings = { + agenda = { + org_agenda_close = nil, + }, + }, + }, + -- keys = { + -- { mode = 's', ';O', function() + -- local pickers = require('telescope.pickers') + -- local finders = require('telescope.finders') + -- pickers.new(opts, { + -- prompt_title = 'Orgmode', + -- finder = finders.new_table(require('orgmode.config'):get_all_files()), + -- }):find() + -- end }, + -- }, + }, - use {'nvim-neorg/neorg', ft = {'norg'}, module = {'neorg'}, cmd = {'Neorg'}, -- {{{ - run = ':Neorg sync-parsers', - requires = { + { + 'nvim-neorg/neorg', + enabled = false, + ft = 'norg', + cmd = { 'Neorg' }, + build = ':Neorg sync-parsers', + dependencies = { 'nvim-lua/plenary.nvim', 'nvim-neorg/neorg-telescope', 'nvim-treesitter/nvim-treesitter', }, - setup = vim.cmd [[autocmd BufRead,BufNewFile *.norg setlocal filetype=norg]], - after = {'nvim-treesitter'}, - config = function() - require('neorg').setup { - load = { - ['core.defaults'] = {}, - ['core.keybinds'] = { - config = { - default_keybinds = true, - -- NOTE: neorg uses localleader by default, see init.lua:6 - -- neorg_leader = 'n', - } - }, - ['core.norg.concealer'] = { - config = { - icons = { - todo = { enabled = true } - }, - } - }, - ['core.norg.dirman'] = { - config = { - workspaces = { - default = '$HOME/Documents/neorg/default', - work = '$HOME/Documents/neorg/work', - gtd = '$HOME/Documents/neorg/gtd', - } - } - }, - ['core.norg.completion'] = { - config = { engine = 'nvim-cmp' } - }, - ['core.integrations.telescope'] = {}, - ['core.norg.qol.todo_items'] = {}, - ['core.presenter'] = {}, - ['core.gtd.base'] = { - config = { - workspace = 'gtd' - } + init = function() + -- vim.cmd [[autocmd BufRead,BufNewFile *.norg setlocal filetype=norg]], + end, + opts = { + load = { + ['core.defaults'] = {}, + ['core.keybinds'] = { + config = { default_keybinds = true }, + }, + ['core.norg.concealer'] = { + config = { icons = { todo = { enabled = true } } }, + }, + ['core.norg.dirman'] = { + config = { + workspaces = { + default = '$HOME/documents/neorg/default', + work = '$HOME/documents/neorg/work', + gtd = '$HOME/documents/neorg/gtd', + }, }, }, - } - end} -- }}} + ['core.norg.completion'] = { + config = { engine = 'nvim-cmp' }, + }, + ['core.integrations.telescope'] = {}, + ['core.norg.qol.todo_items'] = {}, + ['core.presenter'] = {}, + ['core.gtd.base'] = { + config = { workspace = 'gtd' }, + }, + }, + }, + }, - use {'mickael-menu/zk-nvim', module = {'zk', 'telescope._extensions.zk'}, -- {{{ + { + 'mickael-menu/zk-nvim', + cmd = { 'ZkNew', 'ZkNotes' }, + ft = { 'markdown', 'neorg' }, config = function() - local lsp = require('internal.lsp') - require('telescope').load_extension('zk') - require('zk').setup { + require('zk').setup({ picker = 'telescope', lsp = { config = { - cmd = {'/home/robert/devel/upstream/github.com/mickael-menu/zk/zk', 'lsp', '--log', '/tmp/zk-lsp.log'}, - on_attach = lsp.my_attach, - on_exit = lsp.my_exit, - capabilities = lsp.capabilities(), + cmd = { 'zk', 'lsp', '--log', '/tmp/zk-lsp.log' }, + on_attach = require('internal.lsp').my_attach, + on_exit = require('internal.lsp').my_exit, + capabilities = require('internal.lsp').capabilities(), }, auto_attach = { enabled = true, - filetypes = { 'markdown', 'norg' }, + filetypes = { 'markdown', 'neorg' }, }, }, - } - vim.keymap.set('n', ';z', function() require('zk').edit(nil, { multi_select = false }) end, {desc='zk'}) - end} -- }}} - - -- languages - -- NOTE: these should only be loaded when they are required... - -- use {'rhysd/vim-grammarous', - -- ft = {'markdown', 'latex', 'tex'} - -- } + }) + end, + keys = { + { + ';z', + function() + require('zk').edit(nil, { multi_select = false }) + end, + desc = 'zk', + }, + }, + }, - use {'lervag/vimtex', ft = {'latex','tex'}, -- {{{ - config = function() - vim.g.tex_flavor = 'latex' - vim.g.vimtex_compiler_enabled = 0 - vim.g.vimtex_compiler_method = 'tectonic' - vim.g.vimtex_compiler_tectonic = "{'executable': 'tectonic'}" - vim.g.vimtex_view_method = 'zathura' - -- vim.g.vimtex_view_zathura_check_libsynctex = false - -- vim.g.vimtex_view_use_temp_files = true - -- vim.g.vimtex_view_forward_search_on_start = false - end} -- }}} + -- {'rhysd/vim-grammarous', + -- ft = {'markdown', 'latex', 'tex'} + -- }, - use {'plasticboy/vim-markdown', ft = {'markdown'}, -- {{{ + { + 'lervag/vimtex', + ft = { 'latex', 'tex' }, config = function() - vim.g.vim_markdown_folding_disabled = true - vim.g.vim_markdown_math = true - vim.g.vim_markdown_frontmatter = true - vim.g.vim_markdown_json_frontmatter = true - vim.g.vim_markdown_toml_frontmatter = true - vim.g.vim_markdown_yaml_frontmatter = true - -- vim.g.vim_markdown_folding_level = 2 - vim.g.vim_markdown_strikethrough = true - vim.g.vim_markdown_auto_insert_bullets = true - vim.g.vim_markdown_new_list_item_indent = false - vim.g.vim_markdown_conceal = true - vim.g.vim_markdown_conceal_code_blocks = true - end} -- }}} - - use {'gentoo/gentoo-syntax'} + local g = vim.g + g.tex_flavor = 'latex' + g.vimtex_compiler_enabled = 0 + g.vimtex_compiler_method = 'tectonic' + g.vimtex_compiler_tectonic = "{'executable': 'tectonic'}" + g.vimtex_view_method = 'zathura' + -- g.vimtex_view_zathura_check_libsynctex = false + -- g.vimtex_view_use_temp_files = true + -- g.vimtex_view_forward_search_on_start = false + end, + }, - use {'NMAC427/guess-indent.nvim', disable = false, -- {{{ + { + 'plasticboy/vim-markdown', + ft = 'markdown', config = function() - require('guess-indent').setup { - auto_cmd = true, - filetype_exclude = {'netrw', 'tutor', 'dirbuf'}, - buftype_exclude = {'help', 'nofile', 'terminal', 'prompt'}, - } - end} -- }}} + local g = vim.g + g.vim_markdown_folding_disabled = true + g.vim_markdown_math = true + g.vim_markdown_frontmatter = true + g.vim_markdown_json_frontmatter = true + g.vim_markdown_toml_frontmatter = true + g.vim_markdown_yaml_frontmatter = true + -- g.vim_markdown_folding_level = 2 + g.vim_markdown_strikethrough = true + g.vim_markdown_auto_insert_bullets = true + g.vim_markdown_new_list_item_indent = false + g.vim_markdown_conceal = true + g.vim_markdown_conceal_code_blocks = true + end, + }, - use {'folke/zen-mode.nvim', cmd = {'ZenMode'}, -- {{{ - module = {'zen-mode'}, - config = function() - require('zen-mode').setup { - window = { - backdrop = 1, - width = 0.3, - -- height = 1, - options = { - number = false, - list = false, + { + 'folke/zen-mode.nvim', + dependencies = { + { + 'folke/twilight.nvim', + opts = { + context = 15, + dimming = { + alpha = 0.3, + color = { 'Normal', '#ffffff' }, }, }, - plugins = { - options = { - enabled = true, - ruler = false, - showcmd = false, - }, - twilight = { enabled = true }, - } - } - end} -- }}} - - use {'folke/twilight.nvim', module = {'twilight'}, -- {{{ - config = function() - require('twilight').setup { - context = 15, - dimming = { - alpha = 0.3, - color = { 'Normal', '#ffffff' }, + }, + }, + cmd = { 'ZenMode' }, + opts = { + window = { + backdrop = 1, + width = 0.3, + -- height = 1, + options = { + number = false, + list = false, }, - } - end} -- }}} + }, + plugins = { + options = { + enabled = true, + ruler = false, + showcmd = false, + }, + twilight = { enabled = true }, + }, + }, + }, - use {'goolord/alpha-nvim', cmd = {'Alpha'}, module = {'alpha'}, -- {{{ - setup = function() - vim.keymap.set('n', 'a', function() vim.cmd [[Alpha]] end, {desc='alpha'}) - end, + { + 'folke/which-key.nvim', + event = 'VeryLazy', + opts = { + icons = { separator = '→ ', group = '🞱 ' }, + triggers = { '', '', ';', 'g', '[', ']' }, + }, + }, + + { + 'goolord/alpha-nvim', + cmd = 'Alpha', config = function() local MAX_WIDTH = 80 local alpha = require('alpha') local them = require('alpha.themes.theta') - local button = function(...) -- {{{ + local button = function(...) local b = require('alpha.themes.dashboard').button(...) b.opts = vim.tbl_extend('force', b.opts, { hl = 'Normal', width = MAX_WIDTH, }) return b - end -- }}} - local fit_path = function(path, max_width) -- {{{ + end + local fit_path = function(path, max_width) local Path = require('plenary.path') path = vim.fn.fnamemodify(path, ':.') if vim.fn.strdisplaywidth(path) > max_width then - path = Path.new(path):shorten(1, {-2, -1}) + path = Path.new(path):shorten(1, { -2, -1 }) end if vim.fn.strdisplaywidth(path) > max_width then path = '_ ' .. path:sub((vim.fn.strdisplaywidth(path) - max_width), -1) end return path - end -- }}} - local hr = function(margin, max_width, label, opts) -- {{{ - max_width = max_width - (2*margin) + end + local hr = function(margin, max_width, label, opts) + max_width = max_width - (2 * margin) label = label and (' ' .. label .. ' ') or '' opts = vim.tbl_extend('force', opts or {}, { position = 'center', hl = 'Comment' }) return { @@ -1071,46 +1085,52 @@ require('packer').startup({function() local label_len = vim.fn.strdisplaywidth(label) -- exit here if we're not showing a label if label_len == 0 then - return string.rep(' ', margin) .. string.rep('─', max_width) .. string.rep(' ', margin) + return string.rep(' ', margin) + .. string.rep('─', max_width) + .. string.rep(' ', margin) end if label_len > max_width then return error('overfull box: ' .. label) end max_width = max_width - label_len - return string.rep(' ', margin) .. string.rep('─', max_width/2) .. label .. string.rep('─', max_width/2) .. string.rep(' ', margin) + return string.rep(' ', margin) + .. string.rep('─', max_width / 2) + .. label + .. string.rep('─', max_width / 2) + .. string.rep(' ', margin) end, } - end -- }}} - local fortune = function(margin, max_width) -- {{{ - max_width = max_width - (margin*2) - local Job = require('plenary.job') - local ok, j = pcall(Job.new, Job, { - command = 'sh', - args = {'-c', 'fortune ' .. vim.env.HOME..'/devel/projects/zig/fortune/fortunes' .. ' | fmt -w ' .. max_width}, - enable_recording = true, - }) - if not ok then return {} end - local lines, exit_code = j:sync() - if not exit_code == 0 then return {} end - local val = {} - for i = 1, #lines do - if vim.fn.strdisplaywidth(lines[i]) > max_width then - return error('overful box: ' .. lines[i]) - end - table.insert(val, - (string.rep(' ', margin) .. lines[i] .. string.rep(' ', margin))) - end - if vim.trim(val[#val]) == '' then table.remove(val, #val) end + end + local fortune = function(margin, max_width) + max_width = max_width - (margin * 2) + -- local Job = require('plenary.job') + -- local ok, j = pcall(Job.new, Job, { + -- command = 'sh', + -- args = {'-c', 'fortune ' .. vim.env.HOME..'/devel/projects/zig/fortune/fortunes' .. ' | fmt -w ' .. max_width}, + -- enable_recording = true, + -- }) + -- if not ok then return {} end + -- local lines, exit_code = j:sync() + -- if not exit_code == 0 then return {} end + -- local val = {} + -- for i = 1, #lines do + -- if vim.fn.strdisplaywidth(lines[i]) > max_width then + -- return error('overful box: ' .. lines[i]) + -- end + -- table.insert(val, + -- (string.rep(' ', margin) .. lines[i] .. string.rep(' ', margin))) + -- end + -- if vim.trim(val[#val]) == '' then table.remove(val, #val) end return { type = 'text', - val = val, + val = 'noop', opts = { position = 'center', hl = 'AlphaFortune', }, } - end -- }}} - local mru = function(max_width) -- {{{ + end + local mru = function(max_width) return { type = 'group', val = function() @@ -1120,21 +1140,29 @@ require('packer').startup({function() local oldfiles = {} local cwd = vim.loop.cwd() for _, v in pairs(vim.v.oldfiles) do - if #oldfiles == 10 then break end + if #oldfiles == 10 then + break + end if vim.startswith(v, cwd) and (vim.fn.filereadable(v) == 1) then table.insert(oldfiles, v) end end -- exit early if there's nothing to show - if not oldfiles or #oldfiles == 0 then return {} end + if not oldfiles or #oldfiles == 0 then + return {} + end table.insert(items, hr(0, max_width, 'MRU: ' .. fit_path(cwd, max_width))) table.insert(items, { type = 'padding', val = 1 }) for i, fn in pairs(oldfiles) do - table.insert(items, button( - tostring(i-1), -- keybind is - fit_path(fn, max_width), - ":edit " .. fn .. " ")) + table.insert( + items, + button( + tostring(i - 1), -- keybind is + fit_path(fn, max_width), + ':edit ' .. fn .. ' ' + ) + ) end return items end, @@ -1142,8 +1170,8 @@ require('packer').startup({function() position = 'center', }, } - end -- }}} - local buffers = function(max_width) -- {{{ + end + local buffers = function(max_width) return { type = 'group', val = function() @@ -1163,15 +1191,18 @@ require('packer').startup({function() end) -- exit early if there's nothing to show - if not bufnrs or #bufnrs == 0 then return {} end + if not bufnrs or #bufnrs == 0 then + return {} + end - table.insert(items, {type = 'padding', val = 1}) + table.insert(items, { type = 'padding', val = 1 }) table.insert(items, hr(0, max_width, 'Buffers')) - table.insert(items, {type = 'padding', val = 1}) + table.insert(items, { type = 'padding', val = 1 }) for _, bufnr in ipairs(bufnrs) do - local bufpath = require('plenary.path').new(vim.fn.getbufinfo(bufnr)[1].name):shorten(1, {-2, -1}) - table.insert(items, button('b'..bufnr, bufpath, ':b'..bufnr..'')) + local bufpath = + require('plenary.path').new(vim.fn.getbufinfo(bufnr)[1].name):shorten(1, { -2, -1 }) + table.insert(items, button('b' .. bufnr, bufpath, ':b' .. bufnr .. '')) end return items end, @@ -1179,134 +1210,184 @@ require('packer').startup({function() position = 'center', }, } - end -- }}} - them.config.layout = { -- {{{ - {type = 'padding', val = 2}, + end + them.config.layout = { + { type = 'padding', val = 2 }, require('alpha.themes.dashboard').section.header, - {type = 'padding', val = 1}, + { type = 'padding', val = 1 }, fortune(5, MAX_WIDTH), - {type = 'padding', val = 1}, + { type = 'padding', val = 1 }, hr(0, MAX_WIDTH), - {type = 'padding', val = 1}, - {type = 'group', val = { -- buttons {{{ - button('e', '󰈔 new', [[ene startinsert]]), - button('r', '󰈸 live grep', [[lua require('internal.misc').live_grep()]]), - button('f', '󰝰 find files', [[lua require('internal.misc').find_files()]]), - button('m', '󰥔 mru', [[lua require('telescope.builtin').oldfiles()]]), - -- button('o', '󰃶 orgmode', [[lua require('packer').loader('orgmode.nvim'); require('orgmode').action('agenda.prompt')]]), - button('T', '󰃶 todos', [[lua require('telescope._extensions.todo-comments').exports.todo {cwd=vim.env.ZK_NOTEBOOK_DIR}]]), - button('u', '󰚰 update plugins', [[lua require('packer').sync()]]), - button('v', '󰂓 edit config', [[lua require('telescope.builtin').find_files {search_dirs={vim.env.HOME..'/.vim/'}}]]), - button('M', '󰇮 mail', [[K2]]), - }}, -- }}} - {type = 'padding', val = 1}, + { type = 'padding', val = 1 }, + { + type = 'group', + val = { + button('e', '󰈔 new', [[ene startinsert]]), + button('r', '󰈸 live grep', [[lua require('internal.misc').live_grep()]]), + button('f', '󰝰 find files', [[lua require('internal.misc').find_files()]]), + button('m', '󰥔 mru', [[lua require('telescope.builtin').oldfiles()]]), + button( + 'o', + '󰃶 orgmode', + [[lua require('orgmode').action('agenda.prompt')]] + ), + button( + 't', + '󰃶 todos', + [[lua require('telescope._extensions.todo-comments').exports.todo {cwd=vim.env.ZK_NOTEBOOK_DIR}]] + ), + button('u', '󰚰 update plugins', [[lua require('lazy').update()]]), + button( + 'v', + '󰂓 edit config', + [[lua require('telescope.builtin').find_files {search_dirs={vim.env.HOME..'/.vim/'}}]] + ), + }, + }, + { type = 'padding', val = 1 }, mru(MAX_WIDTH), buffers(MAX_WIDTH), - } -- }}} + } alpha.setup(them.config) - - do - local group = vim.api.nvim_create_augroup('AlphaIndent', { clear = true }) - vim.api.nvim_create_autocmd('FileType', { - pattern = 'alpha', - command = [[IndentBlanklineDisable]], - group = group, - }) - end - end} -- }}} - - use {'ruifm/gitlinker.nvim', module = {'gitlinker'}, -- {{{ - requires = {'nvim-lua/plenary.nvim'}, - setup = function() - vim.keymap.set({'n', 'v'}, 'gy', function() require('gitlinker').get_buf_range_url() end, {desc='gitlinker'}) end, - config = function() - require('gitlinker').setup { - opts = { - action_callback = require('gitlinker.actions').copy_to_clipboard, - }, - } - end} -- }}} + keys = { + { 'a', vim.cmd.Alpha, desc = 'alpha' }, + }, + }, - use {'rhysd/git-messenger.vim', cmd = {'GitMessenger'}, -- {{{ - setup = function() - vim.keymap.set('n', 'gm', function() vim.cmd.GitMessenger() end, {desc='git-messenger'}) - end, + { + 'ruifm/gitlinker.nvim', + dependencies = { 'nvim-lua/plenary.nvim' }, + config = { + opts = { + -- action_callback = require('gitlinker.actions').copy_to_clipboard, + }, + }, + keys = { + { + 'gy', + function() + require('gitlinker').get_buf_range_url() + end, + desc = 'gitlinker', + }, + { + mode = 'v', + 'gy', + function() + require('gitlinker').get_buf_range_url() + end, + desc = 'gitlinker', + }, + }, + }, + + { + 'rhysd/git-messenger.vim', + cmd = 'GitMessenger', config = function() -- vim.g.git_messenger_include_diff = false vim.g.git_messenger_always_into_popup = true vim.g.git_messenger_close_on_cursor_moved = true vim.g.git_messenger_no_default_mappings = true - end} -- }}} - - -- restore last cursor position (and handle many edge cases) - use {'farmergreg/vim-lastplace'} - - use {'folke/todo-comments.nvim', module = {'telescope._extensions.todo-comments'}, cmd = {'TodoTelescope'}, -- {{{ - setup = function() - vim.keymap.set('n', ';t', function() vim.cmd [[TodoTelescope]] end, {desc='todo-comments'}) end, - config = function() - require('todo-comments').setup {} - end} -- }}} - - -- spelling related stuff - use {'lewis6991/spellsitter.nvim', disable = true, -- {{{ - config = function() - require('spellsitter').setup { - enable = true, - -- spellchecker = 'ffi' - } - end} -- }}} - - -- TODO: experimental section + keys = { + { 'gm', vim.cmd.GitMessenger, desc = 'git-messenger' }, + }, + }, - use {'tjdevries/sg.nvim', disable = true, -- {{{ - requires = {'nvim-lua/plenary.nvim'}, - config = function() - end} -- }}} + { + 'folke/todo-comments.nvim', + cmd = { 'TodoTelescope' }, + config = true, + keys = { + { ';t', vim.cmd.TodoTelescope, desc = 'todo-comments' }, + }, + }, - use {'yorik1984/newpaper.nvim', disable = true, -- {{{ - config = function() - if vim.g.night_and_day == 'day' then - require('newpaper').setup() - end - end} -- }}} + { + 'cbochs/grapple.nvim', + dependencies = { 'nvim-lua/plenary.nvim' }, + cmd = 'GrapplePopup', + opts = { + popup_options = { + border = 'none', + }, + }, + keys = { + { + 'm', + function() + require('grapple').popup_tags() + end, + desc = 'grapple: show tags', + }, + { + 'ms', + function() + require('grapple').popup_scopes() + end, + desc = 'grapple: show scopes', + }, + { + 'mm', + function() + require('grapple').toggle() + end, + desc = 'grapple: anonymous tag', + }, + { + 'mn', + function() + require('grapple').cycle_forward() + end, + desc = 'grapple: next tag', + }, + { + 'mp', + function() + require('grapple').cycle_backward() + end, + desc = 'grapple: prev tag', + }, + }, + }, - use {'nyoom-engineering/oxocarbon.nvim', disable = false, -- {{{ - config = function() - if vim.g.night_and_day == 'day' then - vim.opt.background = 'light' - vim.cmd.colorscheme 'oxocarbon' - end - end} -- }}} + { + url = 'https://git.sr.ht/~robertgzr/karafuru', + lazy = false, + -- build = 'make colorscheme', + priority = 1000, + cond = vim.g.night_and_day == 'night', + config = function(plugin) + vim.opt.rtp:append(plugin.dir .. '/vim') + vim.cmd.colorscheme('karafuru') + end, + }, - use {'https://git.sr.ht/~robertgzr/karafuru', rtp = 'vim', -- {{{ - run = 'make colorscheme', + { + 'yorik1984/newpaper.nvim', + lazy = false, + priority = 1000, + cond = vim.g.night_and_day == 'day', config = function() - if not vim.g.night_and_day or vim.g.night_and_day == 'night' then - vim.cmd.colorscheme "karafuru" - end - end} -- }}} + vim.cmd.colorscheme('newpaper') + end, + }, - use {'https://git.sr.ht/~robertgzr/spinner.nvim', module = {'spinner'}, -- {{{ + { + 'nyoom-engineering/oxocarbon.nvim', + lazy = false, + enabled = false, + priority = 1000, + cond = vim.g.night_and_day == 'night', config = function() - require('spinner').setup { - spinner = {'⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'}, - interval = 120, -- spinner frame rate in ms - } - end} -- }}} - -end, -config = { - compile_path = compilepath, - git = { - subcommands = { - update = 'pull --ff-only --progress --rebase=true', - } + vim.opt.background = 'dark' + vim.cmd.colorscheme('oxocarbon') + end, }, - profile = { - enable = false, - threshold = 1, - } -}}) +} + +require('lazy').setup(pluginspec, { + defaults = { lazy = true }, +}) diff --git a/.vim/lua/telescope/_extensions/jobs.lua b/.vim/lua/telescope/_extensions/jobs.lua index ea97ed0..be55a47 100644 --- a/.vim/lua/telescope/_extensions/jobs.lua +++ b/.vim/lua/telescope/_extensions/jobs.lua @@ -1,4 +1,4 @@ -local job = require('job') +local job = require('internal.job') local pickers = require('telescope.pickers') local finders = require('telescope.finders') @@ -10,7 +10,7 @@ local entry_display = require('telescope.pickers.entry_display') local function job_entry_maker(_) return function(j) local displayer = entry_display.create({ - separator = " ", + separator = ' ', items = { { width = 8 }, { remaining = true }, @@ -18,7 +18,7 @@ local function job_entry_maker(_) }) local make_display = function(e) return displayer({ - { e.value.pid, "TelescopeResultsNumber" }, + { e.value.pid, 'TelescopeResultsNumber' }, (e.value.command .. ' ' .. table.concat(e.value.args, ' ')), }) end @@ -35,42 +35,50 @@ local function list_jobs(opts) for _, j in pairs(job.current_jobs) do table.insert(jobs, j) end - if #jobs == 0 then return end + if #jobs == 0 then + vim.notify('no jobs') + return + end - opts = vim.tbl_extend("force", { prompt_title = 'Jobs' }, opts or {}) - pickers.new(opts, { - finder = finders.new_table { - results = jobs, - entry_maker = job_entry_maker(opts), - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr, _) - actions.select_default:replace(function() - local entry = action_state.get_selected_entry() - if not entry then return end - actions.close(prompt_bufnr) - vim.ui.select( - {'Terminate', 'Kill', 'Show', 'Cancel'}, - {prompt = 'Select an action:'}, - function(choice) - if choice == 'Cancel' then - return - elseif choice == 'Show' then - vim.fn.getqflist({ id = entry.value.pid }) - elseif choice == 'Kill' then - entry.value.handle:kill('sigkill') - elseif choice == 'Terminate' then - entry.value.handle:kill('sigterm') + opts = vim.tbl_extend('force', { prompt_title = 'Jobs' }, opts or {}) + pickers + .new(opts, { + finder = finders.new_table({ + results = jobs, + entry_maker = job_entry_maker(opts), + }), + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr, _) + actions.select_default:replace(function() + local entry = action_state.get_selected_entry() + if not entry then + return + end + actions.close(prompt_bufnr) + vim.ui.select( + { 'Terminate', 'Kill', 'Show', 'Cancel' }, + { prompt = 'Select an action:' }, + function(choice) + if choice == 'Cancel' then + return + elseif choice == 'Show' then + vim.fn.getqflist({ id = entry.value.pid }) + elseif choice == 'Kill' then + entry.value.handle:kill('sigkill') + elseif choice == 'Terminate' then + entry.value.handle:kill('sigterm') + end end - end) - end) - return true - end, - }):find() + ) + end) + return true + end, + }) + :find() end return require('telescope').register_extension({ exports = { jobs = list_jobs, - } + }, }) -- cgit 1.4.1