From 5f2dd220d9be828f65715f9fb8bd9abc6b9c9073 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Sun, 18 Feb 2024 01:46:46 +0100 Subject: [PATCH] vim: use the `opts` key in plugin specs where possible --- .../nvim/lua/fschauen/plugins/colorizer.lua | 4 +- config/nvim/lua/fschauen/plugins/fidget.lua | 54 ++++++++----------- config/nvim/lua/fschauen/plugins/fugitive.lua | 5 +- .../nvim/lua/fschauen/plugins/gitlinker.lua | 9 ++-- .../lua/fschauen/plugins/indent-blankline.lua | 35 ++++++------ .../lua/fschauen/plugins/markdown-preview.lua | 2 +- config/nvim/lua/fschauen/plugins/neogit.lua | 11 ++-- .../nvim/lua/fschauen/plugins/nvim-notify.lua | 15 +++--- .../nvim/lua/fschauen/plugins/nvim-tree.lua | 22 ++++---- .../plugins/telescope-file-browser.lua | 4 +- .../nvim/lua/fschauen/plugins/telescope.lua | 25 ++++----- .../nvim/lua/fschauen/plugins/text-case.lua | 11 +--- .../lua/fschauen/plugins/todo-comments.lua | 14 ++--- config/nvim/lua/fschauen/plugins/trouble.lua | 14 ++--- config/nvim/lua/fschauen/plugins/undotree.lua | 2 - .../nvim/lua/fschauen/plugins/virt-column.lua | 5 +- .../nvim/lua/fschauen/plugins/whitespace.lua | 7 +-- 17 files changed, 96 insertions(+), 143 deletions(-) diff --git a/config/nvim/lua/fschauen/plugins/colorizer.lua b/config/nvim/lua/fschauen/plugins/colorizer.lua index 306149b..ca5786d 100644 --- a/config/nvim/lua/fschauen/plugins/colorizer.lua +++ b/config/nvim/lua/fschauen/plugins/colorizer.lua @@ -10,8 +10,8 @@ M.event = { } M.config = function(--[[plugin]]_, --[[opts]]_) - require('colorizer').setup(--[[ filetypes ]] nil, { - css = true, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB + require('colorizer').setup(--[[filetypes]]nil, { + css = true, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB mode = 'foreground', }) end diff --git a/config/nvim/lua/fschauen/plugins/fidget.lua b/config/nvim/lua/fschauen/plugins/fidget.lua index 1f8aa80..e8b5a39 100644 --- a/config/nvim/lua/fschauen/plugins/fidget.lua +++ b/config/nvim/lua/fschauen/plugins/fidget.lua @@ -4,38 +4,30 @@ M.branch = 'legacy' M.event = 'LspAttach' -M.config = function(--[[plugin]]_, --[[opts]]_) - require('fidget').setup { - text = { - done = require('fschauen.icons').ui.Checkmark, - spinner = { - '▱▱▱▱▱▱▱', - '▰▱▱▱▱▱▱', - '▰▰▱▱▱▱▱', - '▰▰▰▱▱▱▱', - '▰▰▰▰▱▱▱', - '▰▰▰▰▰▱▱', - '▰▰▰▰▰▰▱', - '▰▰▰▰▰▰▰', - '▱▰▰▰▰▰▰', - '▱▱▰▰▰▰▰', - '▱▱▱▰▰▰▰', - '▱▱▱▱▰▰▰', - '▱▱▱▱▱▰▰', - '▱▱▱▱▱▱▰', - }, +M.opts = { + text = { + done = require('fschauen.icons').ui.Checkmark, + spinner = { + '▱▱▱▱▱▱▱', + '▰▱▱▱▱▱▱', + '▰▰▱▱▱▱▱', + '▰▰▰▱▱▱▱', + '▰▰▰▰▱▱▱', + '▰▰▰▰▰▱▱', + '▰▰▰▰▰▰▱', + '▰▰▰▰▰▰▰', + '▱▰▰▰▰▰▰', + '▱▱▰▰▰▰▰', + '▱▱▱▰▰▰▰', + '▱▱▱▱▰▰▰', + '▱▱▱▱▱▰▰', + '▱▱▱▱▱▱▰', }, - timer = { - spinner_rate = 75, - }, - window = { - blend = 50, - }, - fmt = { - max_messages = 10, - } - } -end + }, + timer = { spinner_rate = 75 }, + window = { blend = 50 }, + fmt = { max_messages = 10 } +} return M diff --git a/config/nvim/lua/fschauen/plugins/fugitive.lua b/config/nvim/lua/fschauen/plugins/fugitive.lua index 6907d36..5cfb59b 100644 --- a/config/nvim/lua/fschauen/plugins/fugitive.lua +++ b/config/nvim/lua/fschauen/plugins/fugitive.lua @@ -1,9 +1,6 @@ local M = { 'tpope/vim-fugitive' } -M.cmd = { - 'G', - 'Git', -} +M.cmd = { 'G', 'Git' } M.keys = { { 'gS', 'tab Git', desc = ' [S]status with fugitive' }, diff --git a/config/nvim/lua/fschauen/plugins/gitlinker.lua b/config/nvim/lua/fschauen/plugins/gitlinker.lua index 9982d3a..46dc720 100644 --- a/config/nvim/lua/fschauen/plugins/gitlinker.lua +++ b/config/nvim/lua/fschauen/plugins/gitlinker.lua @@ -26,14 +26,13 @@ M.keys = { { 'gL', browser('v'), desc = ' open perma[L]ink in browser', mode = 'v' }, } -M.config = function(--[[plugin]]_, --[[opts]]_) - require('gitlinker').setup { - mappings = nil, -- I'm defining me own mappings above. - +M.opts = function(--[[plugin]]_, opts) + return vim.tbl_deep_extend('force', opts, { + mappings = nil, -- I'm defining my own mappings above. callbacks = { ['git.schauenburg.me'] = require('gitlinker.hosts').get_gitea_type_url, }, - } + }) end return M diff --git a/config/nvim/lua/fschauen/plugins/indent-blankline.lua b/config/nvim/lua/fschauen/plugins/indent-blankline.lua index 1bccc37..1f533ae 100644 --- a/config/nvim/lua/fschauen/plugins/indent-blankline.lua +++ b/config/nvim/lua/fschauen/plugins/indent-blankline.lua @@ -1,22 +1,5 @@ local M = { 'lukas-reineke/indent-blankline.nvim' } -local icons = require('fschauen.icons') - -M.config = function(--[[plugin]]_, --[[opts]]_) - require('ibl').setup { - enabled = false, - indent = { - char = icons.ui.LineLeft, - }, - scope = { - char = icons.ui.LineLeftBold, - enabled = false, - show_start = false, - show_end = false, - }, - } -end - M.cmd = { 'IBLEnable', 'IBLDisable', @@ -31,4 +14,22 @@ M.keys = { { 'so', 'IBLToggleScope' }, } +M.main = 'ibl' + +M.opts = function(--[[plugin]]_, opts) + local icons = require('fschauen.icons') + return vim.tbl_deep_extend('force', opts, { + enabled = false, + indent = { + char = icons.ui.LineLeft, + }, + scope = { + char = icons.ui.LineLeftBold, + enabled = false, + show_start = false, + show_end = false, + }, + }) +end + return M diff --git a/config/nvim/lua/fschauen/plugins/markdown-preview.lua b/config/nvim/lua/fschauen/plugins/markdown-preview.lua index eacb992..dfabb6f 100644 --- a/config/nvim/lua/fschauen/plugins/markdown-preview.lua +++ b/config/nvim/lua/fschauen/plugins/markdown-preview.lua @@ -14,7 +14,7 @@ M.ft = { 'markdown', } -M.init = function(--[[plugin]]__) +M.init = function(--[[plugin]]_) vim.g.mkdp_theme = 'dark' end diff --git a/config/nvim/lua/fschauen/plugins/neogit.lua b/config/nvim/lua/fschauen/plugins/neogit.lua index f880cce..4166738 100644 --- a/config/nvim/lua/fschauen/plugins/neogit.lua +++ b/config/nvim/lua/fschauen/plugins/neogit.lua @@ -2,18 +2,15 @@ local M = { 'NeogitOrg/neogit' } M.cmd = 'Neogit' -M.dependencies = { - 'nvim-lua/plenary.nvim', -} +M.dependencies = { 'nvim-lua/plenary.nvim' } M.keys = { { 'gs', 'Neogit', desc = ' [s]tatus with neogit' }, } -M.config = function(--[[plugin]]_, --[[opts]]_) +M.opts = function(--[[plugin]]_, opts) local icons = require('fschauen.icons') - - require('neogit').setup { + return vim.tbl_deep_extend('force', opts, { disable_hint = true, signs = { section = { icons.ui.Folder, icons.ui.EmptyFolderOpen }, @@ -26,7 +23,7 @@ M.config = function(--[[plugin]]_, --[[opts]]_) ['='] = 'Toggle', }, }, - } + }) end return M diff --git a/config/nvim/lua/fschauen/plugins/nvim-notify.lua b/config/nvim/lua/fschauen/plugins/nvim-notify.lua index e0f9a44..3205640 100644 --- a/config/nvim/lua/fschauen/plugins/nvim-notify.lua +++ b/config/nvim/lua/fschauen/plugins/nvim-notify.lua @@ -20,11 +20,9 @@ M.keys = { M.lazy = false -M.config = function(--[[plugin]]_, --[[opts]]_) +M.opts = function(--[[plugin]]_, opts) local icons = require('fschauen.icons') - local notify = require('notify') - - notify.setup { + return vim.tbl_deep_extend('force', opts, { icons = { ERROR = icons.diagnostics_bold.Error, WARN = icons.diagnostics_bold.Warn, @@ -37,10 +35,13 @@ M.config = function(--[[plugin]]_, --[[opts]]_) minimum_width = 50, render = 'wrapped-compact', stages = 'fade', - time_formats = { notification_history = '%F %T' }, - top_down = true, - } + time_formats = { notification_history = '%F %T │ ' }, + }) +end +M.config = function(--[[plugin]]_, opts) + local notify = require('notify') + notify.setup(opts) vim.notify = notify end diff --git a/config/nvim/lua/fschauen/plugins/nvim-tree.lua b/config/nvim/lua/fschauen/plugins/nvim-tree.lua index 137336e..e6ee4af 100644 --- a/config/nvim/lua/fschauen/plugins/nvim-tree.lua +++ b/config/nvim/lua/fschauen/plugins/nvim-tree.lua @@ -9,29 +9,27 @@ M.keys = { { 'tf', 'NvimTreeFindFile', desc = '󰙅 Open [t]ree to current [f]ile ' }, } -M.config = function(--[[plugin]]_, --[[opts]]_) +M.opts = function(--[[plugin]]_, opts) local icons = require('fschauen.icons') - - require('nvim-tree').setup { + return vim.tbl_deep_extend('force', opts, { disable_netrw = true, -- replace netrw with nvim-tree hijack_cursor = true, -- keep the cursor on begin of the filename sync_root_with_cwd = true, -- watch for `DirChanged` and refresh the tree on_attach = function(buffer) local api = require('nvim-tree.api') - local map = vim.keymap.set - local opts = function(desc) - return { desc = 'nvim-tree: ' .. desc, buffer = buffer, silent = true } - end -- Give me the default mappings except , which I replace with . api.config.mappings.default_on_attach(buffer) vim.keymap.del('n', '', { buffer = buffer }) - map('n', 'l', api.node.open.edit, opts('Open')) - map('n', '', api.node.open.edit, opts('Open')) - map('n', '', api.node.open.horizontal, opts('Open: Horizontal Split')) - map('n', 'h', api.node.navigate.parent_close, opts('Close directory')) + local opt = function(desc) + return { desc = '󰙅 nvim-tree: ' .. desc, buffer = buffer, silent = true } + end + vim.keymap.set('n', 'l', api.node.open.edit, opt('Open')) + vim.keymap.set('n', '', api.node.open.edit, opt('Open')) + vim.keymap.set('n', '', api.node.open.horizontal, opt('Open: Horizontal Split')) + vim.keymap.set('n', 'h', api.node.navigate.parent_close, opt('Close directory')) end, git = { @@ -79,7 +77,7 @@ M.config = function(--[[plugin]]_, --[[opts]]_) }, }, }, - } + }) end return M diff --git a/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua b/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua index 320f3f3..ee145fb 100644 --- a/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua +++ b/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua @@ -1,8 +1,6 @@ local M = { 'nvim-telescope/telescope-file-browser.nvim' } -M.dependencies = { - 'nvim-telescope/telescope.nvim', -} +M.dependencies = { 'nvim-telescope/telescope.nvim' } M.keys = { { 'fB', 'Telescope file_browser' , desc = ' Telescope file [B]rowser' }, diff --git a/config/nvim/lua/fschauen/plugins/telescope.lua b/config/nvim/lua/fschauen/plugins/telescope.lua index fa97f51..979baf7 100644 --- a/config/nvim/lua/fschauen/plugins/telescope.lua +++ b/config/nvim/lua/fschauen/plugins/telescope.lua @@ -122,11 +122,10 @@ M.keys = { { 'f', pickers.resume '󰐎 Resume' , desc = desc('Resume ') }, } -local icons = require('fschauen.icons') - -M.config = function(--[[plugin]]_, --[[opts]]_) +M.opts = function(--[[plugin]]_, opts) local actions = require('telescope.actions') local layout = require('telescope.actions.layout') + local icons = require('fschauen.icons') local trouble = vim.F.npcall(require, 'trouble.providers.telescope') or {} local mappings = { @@ -145,12 +144,9 @@ M.config = function(--[[plugin]]_, --[[opts]]_) [''] = trouble.smart_open_with_trouble, } - require('telescope').setup { + return vim.tbl_deep_extend('force', opts, { defaults = { - mappings = { - i = mappings, - n = mappings, - }, + mappings = { i = mappings, n = mappings }, prompt_prefix = '  ', selection_caret = icons.ui.Play .. ' ', @@ -172,11 +168,7 @@ M.config = function(--[[plugin]]_, --[[opts]]_) }, pickers = { buffers = { - mappings = { - n = { - x = actions.delete_buffer, - }, - }, + mappings = { n = { x = actions.delete_buffer } }, }, colorscheme = { theme = 'dropdown', @@ -190,10 +182,13 @@ M.config = function(--[[plugin]]_, --[[opts]]_) theme = 'ivy' }, }, - } + }) +end - require('telescope').load_extension 'fzf' +M.config = function(--[[plugin]]_, opts) + require('telescope').setup(opts) + require('telescope').load_extension('fzf') vim.api.nvim_create_autocmd('User', { desc = 'Enable line number in Telescope previewers.', group = vim.api.nvim_create_augroup('fschauen.telescope', { clear = true } ), diff --git a/config/nvim/lua/fschauen/plugins/text-case.lua b/config/nvim/lua/fschauen/plugins/text-case.lua index a5eb364..43a86c4 100644 --- a/config/nvim/lua/fschauen/plugins/text-case.lua +++ b/config/nvim/lua/fschauen/plugins/text-case.lua @@ -1,15 +1,8 @@ local M = { 'johmsalas/text-case.nvim' } -M.event = { - 'BufReadPost', - 'BufNewFile', -} +M.event = { 'BufReadPost', 'BufNewFile' } -M.config = function(--[[plugin]]_, --[[opts]]_) - require('textcase').setup { - prefix = 'c', - } -end +M.opts = { prefix = 'c' } return M diff --git a/config/nvim/lua/fschauen/plugins/todo-comments.lua b/config/nvim/lua/fschauen/plugins/todo-comments.lua index 07ef8e3..eedbf5c 100644 --- a/config/nvim/lua/fschauen/plugins/todo-comments.lua +++ b/config/nvim/lua/fschauen/plugins/todo-comments.lua @@ -5,19 +5,15 @@ M.dependencies = { 'nvim-telescope/telescope.nvim', } -M.event = { - 'BufReadPost', - 'BufNewFile' -} +M.event = { 'BufReadPost', 'BufNewFile' } M.keys = { { 'ft', 'TodoTelescope', desc = ' Telescope [t]odos' }, } -local icons = require('fschauen.icons') - -M.config = function(--[[plugin]]_, --[[opts]]_) - require('todo-comments').setup { +M.opts = function(--[[plugin]]_, opts) + local icons = require('fschauen.icons') + return vim.tbl_deep_extend('force', opts, { keywords = { TODO = { icon = icons.ui.Checkbox }, FIX = { icon = icons.ui.Bug }, @@ -27,7 +23,7 @@ M.config = function(--[[plugin]]_, --[[opts]]_) NOTE = { icon = icons.ui.Note }, TEST = { icon = icons.ui.TestTube }, }, - } + }) end return M diff --git a/config/nvim/lua/fschauen/plugins/trouble.lua b/config/nvim/lua/fschauen/plugins/trouble.lua index 561a779..5fd1ad9 100644 --- a/config/nvim/lua/fschauen/plugins/trouble.lua +++ b/config/nvim/lua/fschauen/plugins/trouble.lua @@ -1,8 +1,6 @@ local M = { 'folke/trouble.nvim' } -M.dependencies = { - 'nvim-tree/nvim-web-devicons', -} +M.dependencies = { 'nvim-tree/nvim-web-devicons' } M.keys = { { 'lt', 'TroubleToggle', desc = '󱠪 trouble [t]toggle' }, @@ -10,12 +8,10 @@ M.keys = { { 'ld', 'TroubleToggle document_diagnostics', desc = '󱠪 trouble [d]ocument' }, } -M.config = function(--[[plugin]]_, --[[opts]]_) - require('trouble').setup { - padding = false, -- don't add an extra new line of top of the list - auto_preview = false, -- don't preview automatically - } -end +M.opts = { + padding = false, -- don't add an extra new line of top of the list + auto_preview = false, -- don't preview automatically +} return M diff --git a/config/nvim/lua/fschauen/plugins/undotree.lua b/config/nvim/lua/fschauen/plugins/undotree.lua index ee27268..ff2a6f1 100644 --- a/config/nvim/lua/fschauen/plugins/undotree.lua +++ b/config/nvim/lua/fschauen/plugins/undotree.lua @@ -14,7 +14,5 @@ M.keys = { { 'u', 'UndotreeToggle' }, } -M.config = false - return M diff --git a/config/nvim/lua/fschauen/plugins/virt-column.lua b/config/nvim/lua/fschauen/plugins/virt-column.lua index 02b6712..725be64 100644 --- a/config/nvim/lua/fschauen/plugins/virt-column.lua +++ b/config/nvim/lua/fschauen/plugins/virt-column.lua @@ -1,9 +1,6 @@ local M = { 'lukas-reineke/virt-column.nvim' } -M.event = { - 'BufReadPost', - 'BufNewFile' -} +M.event = { 'BufReadPost', 'BufNewFile' } local toggle_colorcolumn = function() if vim.o.colorcolumn == '' then diff --git a/config/nvim/lua/fschauen/plugins/whitespace.lua b/config/nvim/lua/fschauen/plugins/whitespace.lua index 85ec6c0..248ebc4 100644 --- a/config/nvim/lua/fschauen/plugins/whitespace.lua +++ b/config/nvim/lua/fschauen/plugins/whitespace.lua @@ -10,10 +10,7 @@ M.init = function(--[[plugin]]_) } end -M.event = { - 'BufReadPost', - 'BufNewFile' -} +M.event = { 'BufReadPost', 'BufNewFile' } M.keys = { { 'ww', 'ToggleWhitespace' }, @@ -22,7 +19,5 @@ M.keys = { { 'W', 'StripWhitespace' }, } -M.config = false - return M