nvim: call lua function directly in autogroup

This commit is contained in:
tastytea 2022-08-08 22:13:19 +02:00
parent a74aecc68c
commit b46408a64a
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM

View File

@ -22,19 +22,19 @@ packer.use {
} }
-- remove trailing whitespace -- remove trailing whitespace
function remove_trailing_whitespace() function my_remove_trailing_whitespace()
local curpos = vim.api.nvim_win_get_cursor(0) local curpos = vim.api.nvim_win_get_cursor(0)
vim.cmd([[keeppatterns %s/\s\+$//e]]) vim.cmd([[keeppatterns %s/\s\+$//e]])
vim.api.nvim_win_set_cursor(0, curpos) vim.api.nvim_win_set_cursor(0, curpos)
end end
vim.api.nvim_create_autocmd( vim.api.nvim_create_autocmd(
{ "BufWritePre" }, { 'BufWritePre' },
{ {
pattern = { pattern = {
"*.lua", "*.cpp", "*.hpp" '*.lua', '*.cpp', '*.hpp'
}, },
command = 'lua remove_trailing_whitespace()' callback = my_remove_trailing_whitespace
} }
) )