diff --git a/init.lua b/init.lua index 89793b5..7d1c831 100644 --- a/init.lua +++ b/init.lua @@ -13,10 +13,9 @@ local gr = vim.api.nvim_create_augroup("custom-config", {}) _G.Config = { now = function(f) misc.safely("now", f) end, later = function(f) misc.safely("later", f) end, - autocmd = function(event, pattern, callback, desc, once) - vim.api.nvim_create_autocmd(event, { group = gr, pattern = pattern, callback = callback, desc = desc, once = once }) - end + on_event = function(ev, f) misc.safely('event:' .. ev, f) end, + on_filetype = function(ft, f) misc.safely('filetype:' .. ft, f) end, + autocmd = function(event, pattern, callback, desc) vim.api.nvim_create_autocmd(event, { group = gr, pattern = pattern, callback = callback, desc = desc }) end } Config.now_if_args = vim.fn.argc(-1) > 0 and Config.now or Config.later - diff --git a/plugin/30_mini.lua b/plugin/30_mini.lua index 387050c..03cb6e6 100644 --- a/plugin/30_mini.lua +++ b/plugin/30_mini.lua @@ -77,9 +77,9 @@ Config.now_if_args(function() }, }) - Config.autocmd('LspAttach', nil, function(ev) - vim.bo[ev.buf].omnifunc = 'v:lua.MiniCompletion.completefunc_lsp' - end, "Set 'omnifunc'") + Config.on_event('LspAttach', function() + vim.bo.omnifunc = 'v:lua.MiniCompletion.completefunc_lsp' + end) vim.lsp.config('*', { capabilities = MiniCompletion.get_lsp_capabilities() }) end) diff --git a/plugin/40_plugins.lua b/plugin/40_plugins.lua index 94dcf11..103eb01 100644 --- a/plugin/40_plugins.lua +++ b/plugin/40_plugins.lua @@ -17,11 +17,12 @@ Config.now_if_args(function() 'json', 'xml', 'toml', 'sh', 'bash', 'zsh', 'just', 'gitcommit', 'diff', 'regex', 'http' } - Config.autocmd('FileType', filetypes, function(ev) - if pcall(vim.treesitter.start, ev.buf) and vim.bo[ev.buf].filetype == 'php' then - vim.bo[ev.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + Config.on_filetype(table.concat(filetypes, ','), function() + local buf = vim.api.nvim_get_current_buf() + if pcall(vim.treesitter.start, buf) and vim.bo[buf].filetype == 'php' then + vim.bo[buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" end - end, 'Start tree-sitter') + end) Config.later(function() require('nvim-treesitter').install(vim.tbl_map(function(ft) @@ -73,16 +74,17 @@ Config.later(function() require("dap").adapters.go = { type = "server", host = "127.0.0.1", port = "${port}" } end) --- Kulala & Flutter -Config.autocmd('FileType', { 'http' }, function() +-- Kulala +Config.on_filetype('http', function() vim.pack.add({ "https://github.com/mistweaverco/kulala.nvim" }) require("kulala").setup({ default_env = "dev" }) -end, "Setup Kulala", true) +end) -Config.autocmd('FileType', 'dart', function() +-- Flutter +Config.on_filetype('dart', function() vim.pack.add({ "https://github.com/nvim-lua/plenary.nvim", "https://github.com/nvim-flutter/flutter-tools.nvim", }) require("flutter-tools").setup({ lsp = { color_capabilities = true } }) -end, "Setup Flutter", true) +end)