init.lua 733 B

123456789101112131415161718192021222324252627
  1. local lv_utils = {}
  2. function lv_utils.define_augroups(definitions) -- {{{1
  3. -- Create autocommand groups based on the passed definitions
  4. --
  5. -- The key will be the name of the group, and each definition
  6. -- within the group should have:
  7. -- 1. Trigger
  8. -- 2. Pattern
  9. -- 3. Text
  10. -- just like how they would normally be defined from Vim itself
  11. for group_name, definition in pairs(definitions) do
  12. vim.cmd('augroup ' .. group_name)
  13. vim.cmd('autocmd!')
  14. for _, def in pairs(definition) do
  15. local command = table.concat(vim.tbl_flatten {'autocmd', def}, ' ')
  16. vim.cmd(command)
  17. end
  18. vim.cmd('augroup END')
  19. end
  20. end
  21. return lv_utils