Thu, 16 Mar 2023 12:30:54 -0500
Cleaner conflict resolution
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
1 | local M = {} |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
2 | |
1085
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
3 | local api = vim.api |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
4 | local fn = vim.fn |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
5 | |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
6 | function M.calias(abbrev, expand) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
7 | vim.cmd.cnoreabbrev( |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
8 | string.format( |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
9 | [[<expr> %s (getcmdtype() == ":" && getcmdline() == "%s") ? "%s" : "%s"]], |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
10 | abbrev, |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
11 | abbrev, |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
12 | expand, |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
13 | abbrev |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
14 | ) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
15 | ) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
16 | end |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
17 | |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
18 | function M.autocmd(group, event, pattern, opts) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
19 | if type(opts) == "function" then |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
20 | local func = opts |
1085
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
21 | opts = { |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
22 | callback = function(_) |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
23 | func() |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
24 | end, |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
25 | } |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
26 | end |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
27 | |
1085
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
28 | api.nvim_create_autocmd( |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
29 | event, |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
30 | vim.tbl_extend("keep", opts, { |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
31 | group = group, |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
32 | pattern = pattern, |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
33 | }) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
34 | ) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
35 | end |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
36 | |
1085
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
37 | function M.safe_filter_file(cmd) |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
38 | local errorfile = fn.tempname() |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
39 | vim.cmd([[silent %!]] .. cmd .. [[ 2>]] .. fn.shellescape(errorfile)) |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
40 | if vim.v.shell_error ~= 0 then |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
41 | vim.cmd("silent undo") |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
42 | api.nvim_err_write(io.open(errorfile):read("*a")) |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
43 | end |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
44 | fn.delete(errorfile) |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
45 | end |
c2d11f022cf0
Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents:
1078
diff
changeset
|
46 | |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
47 | return M |