FollieHiyuki-dotfiles/home/.config/nvim/lua/events.lua

66 lines
2.3 KiB
Lua
Raw Normal View History

2021-07-03 20:19:46 -04:00
local plug_dir = vim.fn.stdpath('config') .. '/lua'
local M = {}
function M.packer_compile()
local file = vim.fn.expand('%:p')
if file:match(plug_dir) then
vim.api.nvim_command('PackerCompile')
end
end
function M.nvim_create_augroups(definitions)
for group_name, definition in pairs(definitions) do
vim.api.nvim_command('augroup '..group_name)
vim.api.nvim_command('autocmd!')
for _, def in ipairs(definition) do
local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ')
vim.api.nvim_command(command)
end
vim.api.nvim_command('augroup END')
end
end
function M.load_autocmds()
local definitions = {
packer = {
{"BufWritePost", "*.lua", "lua require('events').packer_compile()"};
};
-- Edit binary files in hex with xxd (:%!xxd and :%!xxd -r)
-- or using nvim -b to edit files using xxd-format
binary = {
{"BufReadPre" , "*.bin,*.exe", "let &bin=1"};
{"BufReadPost" , "*.bin,*.exe", "if &bin | %!xxd"};
{"BufReadPost" , "*.bin,*.exe", "set ft=xxd | endif"};
{"BufWritePre" , "*.bin,*.exe", "if &bin | %!xxd -r"};
{"BufWritePre" , "*.bin,*.exe", "endif"};
{"BufWritePost", "*.bin,*.exe", "if &bin | %!xxd"};
{"BufWritePost", "*.bin,*.exe", "set nomod | endif"};
};
document = {
{"BufNewFile,BufEnter,BufRead", "*.md,*.mkd", "setfiletype markdown"};
{"BufNewFile,BufEnter,BufRead", "*.tex", "setfiletype tex"};
{"BufNewFile,BufRead", "*.md,*.mkd", "setlocal spell"};
{"BufNewFile,BufRead", "*.tex", "setlocal spell"};
};
wins = {
-- Equalize window dimensions when resizing vim window
{"VimResized", "*", [[tabdo wincmd =]]};
-- Force write shada on leaving nvim
{"VimLeave", "*", [[if has('nvim') | wshada! | else | wviminfo! | endif]]};
-- Check if file changed when its window is focus, more eager than 'autoread'
{"FocusGained", "* checktime"};
};
yank = {
{"TextYankPost", [[* silent! lua vim.highlight.on_yank({higroup="IncSearch", timeout=300})]]};
};
}
M.nvim_create_augroups(definitions)
end
return M