diff options
| author | Robert Günzler <r@gnzler.io> | 2022-11-04 16:43:05 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2022-11-18 18:37:24 +0100 |
| commit | c990158da1051a42fa01866b4663a0ae0f5d8f90 (patch) | |
| tree | 91a02de0bed2bd7263708cbe682a263d80169a1f /.vim | |
| parent | 439a9e48d80b5d5894d91b78c0efc039c60bf588 (diff) | |
vim: improve packer bootstrap
Diffstat (limited to '.vim')
| -rw-r--r-- | .vim/lua/plugins.lua | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/.vim/lua/plugins.lua b/.vim/lua/plugins.lua index 48f108e..d304f80 100644 --- a/.vim/lua/plugins.lua +++ b/.vim/lua/plugins.lua @@ -10,14 +10,17 @@ if not vim.fn.filewritable(vim.fn.stdpath('cache')) == 2 then return end --- local datadir = vim.fn.stdpath('data_dirs')[1] -local datadir = vim.fn.stdpath('data') -local install_path = datadir .. '/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.api.nvim_command([[packadd packer.nvim]]) +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() -- {{{ @@ -47,28 +50,34 @@ if not (vim.fn.empty(vim.fn.glob(compilepath)) > 0) then require('packer_compiled') end --- 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() +require('packer').startup({function() + -- run sync() if compilepath doesn't exist (this usually means first start) + if packer_bootstrapped then + require('packer').sync() + end + + -- 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() + end end - end - vim.cmd [[luafile $HOME/.vim/lua/plugins.lua]] - vim.cmd [[PackerCompile]] - vim.notify('packer: lazy-loading refreshed') - 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 -- }}} + vim.cmd [[luafile $HOME/.vim/lua/plugins.lua]] + vim.cmd [[PackerCompile]] + vim.notify('packer: lazy-loading refreshed') + 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 -- }}} -require('packer').startup({function() -- disable built-in plugins disable_distribution_plugins() @@ -1253,9 +1262,3 @@ config = { threshold = 1, } }}) - --- run sync() if compilepath doesn't exist (this usually means first start) -if vim.fn.empty(vim.fn.glob(compilepath)) > 0 then - require('packer').sync() -end - |