.config/nvim/plugin/tig.lua

Wed, 25 Sep 2024 15:03:13 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Wed, 25 Sep 2024 15:03:13 -0500
changeset 1179
b0a0ba3240b5
parent 1160
28e64ed03c25
permissions
-rw-r--r--

No LSP autostart when read-only

I think nvim actually threw out 'view' argc detection, I just use -R and alias
view to it.

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