.config/nvim/lua/config/util.lua

Mon, 26 Jun 2023 14:11:01 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 26 Jun 2023 14:11:01 -0500
changeset 1122
8a56361b077f
parent 1095
226221dc1d6b
child 1156
0a7162df160d
permissions
-rw-r--r--

Replace nvim_lsp_signature_help with lsp_signature.nvim

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

mercurial