From 90c0c328c5bd12c3e6b7c3f9a08a3a9ccd28bdb2 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Fri, 15 Apr 2022 15:19:16 +0200 Subject: vim: rework packer auto-compile --- .vim/lua/plugins.lua | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/.vim/lua/plugins.lua b/.vim/lua/plugins.lua index 49748e8..237a64c 100644 --- a/.vim/lua/plugins.lua +++ b/.vim/lua/plugins.lua @@ -1,22 +1,23 @@ --- vim: fen fdm=marker fdl=0 +-- vim: fdm=marker fdl=0 ---@diagnostic disable: undefined-global -- load by calling `lua require('plugins')` from your init.vim local g = vim.g +local augroup = vim.api.nvim_create_augroup +local autocmd = vim.api.nvim_create_autocmd --- force packer into a system directory +-- force packer into a system directory {{{ -- local datadir = vim.fn.stdpath('data_dirs')[1] local datadir = vim.fn.stdpath('data') - local install_path = require('packer.util').join_paths(datadir, '/site/pack/packer/start/packer.nvim') if vim.fn.empty(vim.fn.glob(install_path)) > 0 then vim.fn.system({ 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path }) vim.api.nvim_command 'packadd packer.nvim' end - if not vim.fn.filewritable(vim.fn.stdpath('cache')) == 2 then return end +-- }}} local function disable_distribution_plugins() -- {{{ g.loaded_gzip = 1 @@ -41,10 +42,23 @@ end -- }}} -- we change the packer.compile_path below, so we need to require it here... require('packer_compiled') --- auto-compile on save -augroup { - autocompile = {{ 'BufWritePost', 'plugins.lua', [[ exe 'luafile %:p' | PackerCompile ]] }} -} +-- auto-compile on save -- {{{ +do + vim.api.nvim_create_user_command( + 'PackerRecompile', + function() + vim.cmd [[luafile $HOME/.vim/lua/plugins.lua]] + vim.cmd [[PackerCompile]] + vim.notify('packer: lazy-loading refreshed') + end, + {}) + local group = vim.api.nvim_create_augroup('PackerAutoCompile', { clear = true }) + vim.api.nvim_create_autocmd('BufWritePost', { + pattern = 'plugins.lua', + command = [[PackerRecompile]], + group = group + }) +end -- }}} return require('packer').startup({function() -- disable built-in plugins -- cgit 1.4.1