.config/nvim/lua/local/tig.lua

Tue, 30 Apr 2024 21:53:24 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Tue, 30 Apr 2024 21:53:24 -0500
changeset 1152
59d9ca2ec2fd
parent 1085
c2d11f022cf0
permissions
-rw-r--r--

Match LSP maps to neovim 0.10 defs

1074
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
1 local api = vim.api
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
2 local fn = vim.fn
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
3
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4 local function tig(ctx)
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
5 local cmd = ctx.fargs
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
6 local orig_number = vim.wo.number
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
7
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
8 local buf = api.nvim_create_buf(false, true)
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
9 vim.bo[buf].bufhidden = "delete"
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
10
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 api.nvim_set_current_buf(buf)
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12 vim.wo.number = false
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
14 table.insert(cmd, 1, "tig")
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
15 fn.termopen(cmd, {
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
16 on_exit = function()
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17 vim.wo.number = orig_number
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
18 vim.cmd.buffer("#")
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
19 end,
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
20 })
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
21 end
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
22
1085
c2d11f022cf0 Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents: 1076
diff changeset
23 api.nvim_create_user_command("Tig", tig, { nargs = "*", complete = "file" })
1074
91b42a87c3d9 port tig plugin to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
24
1085
c2d11f022cf0 Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents: 1076
diff changeset
25 api.nvim_create_user_command("TigBlame", function()
c2d11f022cf0 Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents: 1076
diff changeset
26 tig({ fargs = { "blame", "+" .. fn.line("."), "--", fn.expand("%") } })
c2d11f022cf0 Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents: 1076
diff changeset
27 end, {})
1074
91b42a87c3d9 port tig plugin 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: 1076
diff changeset
29 api.nvim_create_user_command("TigLog", function()
c2d11f022cf0 Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents: 1076
diff changeset
30 tig({ fargs = { "log", "-p", "--", fn.expand("%") } })
c2d11f022cf0 Port encrypted file edit to lua
Meredith Howard <mhoward@roomag.org>
parents: 1076
diff changeset
31 end, {})

mercurial