generated from nvim-treesitter/module-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnvim-treeclimber.lua
108 lines (81 loc) · 3.42 KB
/
nvim-treeclimber.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
local M = {}
local tc = require("nvim-treeclimber.api")
-- Re-export nvim-treeclimber.api
for k, v in pairs(tc) do
M[k] = v
end
function M.setup_keymaps()
vim.keymap.set("n", "<leader>k", tc.show_control_flow, {})
vim.keymap.set({ "x", "o" }, "i.", tc.select_current_node, { desc = "select current node" })
vim.keymap.set({ "x", "o" }, "a.", tc.select_expand, { desc = "select parent node" })
vim.keymap.set(
{ "n", "x", "o" },
"<M-e>",
tc.select_forward_end,
{ desc = "select and move to the end of the node, or the end of the next node" }
)
vim.keymap.set(
{ "n", "x", "o" },
"<M-b>",
tc.select_backward,
{ desc = "select and move to the begining of the node, or the beginning of the next node" }
)
vim.keymap.set({ "n", "x", "o" }, "<M-[>", tc.select_siblings_backward, {})
vim.keymap.set({ "n", "x", "o" }, "<M-]>", tc.select_siblings_forward, {})
vim.keymap.set(
{ "n", "x", "o" },
"<M-g>",
tc.select_top_level,
{ desc = "select the top level node from the current position" }
)
vim.keymap.set({ "n", "x", "o" }, "<M-h>", tc.select_backward, { desc = "select previous node" })
vim.keymap.set({ "n", "x", "o" }, "<M-j>", tc.select_shrink, { desc = "select child node" })
vim.keymap.set({ "n", "x", "o" }, "<M-k>", tc.select_expand, { desc = "select parent node" })
vim.keymap.set({ "n", "x", "o" }, "<M-l>", tc.select_forward, { desc = "select the next node" })
vim.keymap.set({ "n", "x", "o" }, "<M-L>", tc.select_grow_forward, { desc = "Add the next node to the selection" })
vim.keymap.set({ "n", "x", "o" }, "<M-H>", tc.select_grow_backward, { desc = "Add the next node to the selection" })
end
function M.setup_user_commands()
vim.api.nvim_create_user_command("TCDiffThis", tc.diff_this, { force = true, range = true, desc = "" })
vim.api.nvim_create_user_command(
"TCHighlightExternalDefinitions",
tc.highlight_external_definitions,
{ force = true, range = true, desc = "WIP" }
)
vim.api.nvim_create_user_command("TCShowControlFlow", tc.show_control_flow, {
force = true,
range = true,
desc = "Populate the quick fix with all branches required to reach the current node",
})
end
function M.setup_highlight()
-- Must run after colorscheme or TermOpen to ensure that terminal_colors are available
local hi = require("nvim-treeclimber.hi")
local Normal = hi.get_hl("Normal", { follow = true })
assert(not vim.tbl_isempty(Normal), "hi Normal not found")
local normal = hi.HSLUVHighlight:new(Normal)
local Visual = hi.get_hl("Visual", { follow = true })
assert(not vim.tbl_isempty(Visual), "hi Visual not found")
local visual = hi.HSLUVHighlight:new(Visual)
vim.api.nvim_set_hl(0, "TreeClimberHighlight", { background = visual.bg.hex })
vim.api.nvim_set_hl(0, "TreeClimberSiblingBoundary", { background = visual.bg.mix(normal.bg, 50).hex })
vim.api.nvim_set_hl(0, "TreeClimberSibling", { background = visual.bg.mix(normal.bg, 50).hex })
vim.api.nvim_set_hl(0, "TreeClimberParent", { background = visual.bg.mix(normal.bg, 50).hex })
vim.api.nvim_set_hl(0, "TreeClimberParentStart", { background = visual.bg.mix(normal.bg, 50).hex })
end
function M.setup_augroups()
local group = vim.api.nvim_create_augroup("nvim-treeclimber-colorscheme", { clear = true })
vim.api.nvim_create_autocmd({ "Colorscheme" }, {
group = group,
pattern = "*",
callback = function()
M.setup_highlight()
end,
})
end
function M.setup()
M.setup_keymaps()
M.setup_user_commands()
M.setup_augroups()
end
return M