13 end |
16 end |
14 |
17 |
15 function M.autocmd(group, event, pattern, opts) |
18 function M.autocmd(group, event, pattern, opts) |
16 if type(opts) == "function" then |
19 if type(opts) == "function" then |
17 local func = opts |
20 local func = opts |
18 opts = { callback = function (_) |
21 opts = { |
19 func() |
22 callback = function(_) |
20 end } |
23 func() |
|
24 end, |
|
25 } |
21 end |
26 end |
22 |
27 |
23 vim.api.nvim_create_autocmd( |
28 api.nvim_create_autocmd( |
24 event, |
29 event, |
25 vim.tbl_extend("keep", opts, { |
30 vim.tbl_extend("keep", opts, { |
26 group = group, |
31 group = group, |
27 pattern = pattern, |
32 pattern = pattern, |
28 }) |
33 }) |
29 ) |
34 ) |
30 end |
35 end |
31 |
36 |
|
37 function M.safe_filter_file(cmd) |
|
38 local errorfile = fn.tempname() |
|
39 vim.cmd([[silent %!]] .. cmd .. [[ 2>]] .. fn.shellescape(errorfile)) |
|
40 if vim.v.shell_error ~= 0 then |
|
41 vim.cmd("silent undo") |
|
42 api.nvim_err_write(io.open(errorfile):read("*a")) |
|
43 end |
|
44 fn.delete(errorfile) |
|
45 end |
|
46 |
32 return M |
47 return M |