Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Commit 71743dd

Browse files
committed
Allow palette of any size, fix gitgnore
1 parent 2bb471f commit 71743dd

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lua/colors/colors.lua
1+
lua/rainbow/colors.lua

lua/rainbow/internal.lua

+21-18
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,38 @@ local queries = require "nvim-treesitter.query"
22
local nsid = vim.api.nvim_create_namespace("rainbow_ns")
33
local colors = require "rainbow.colors"
44

5-
local function color_no(mynode)
5+
local function color_no(mynode, len)
66
local counter = 0
77
local current = mynode
88
while current:parent() ~= nil do
99
counter = counter + 1
1010
current = current:parent()
1111
end
12-
if (counter % 7 == 0) then
13-
return 7
12+
if (counter % len == 0) then
13+
return len
1414
else
15-
return (counter % 7)
15+
return (counter % len)
1616
end
1717
end
1818

1919
local callbackfn = function(bufnr)
2020
local matches = queries.get_capture_matches(bufnr, "@punctuation.bracket", "highlights")
2121
for _, node in ipairs(matches) do
2222
-- set colour for this nesting level
23-
if (node ~= nil and node.node ~= nil) then
24-
local color_no_ = color_no(node.node)
25-
local _, _, endRow, endCol = node.node:range() -- range of the capture, zero-indexed
26-
vim.highlight.range(
27-
bufnr,
28-
nsid,
29-
("rainbowcol" .. color_no_),
30-
{endRow, endCol - 1},
31-
{endRow, endCol - 1},
32-
"blockwise",
33-
true
34-
)
23+
if node ~= nil then
24+
if node.node ~= nil then
25+
local color_no_ = color_no(node.node, #colors)
26+
local _, _, endRow, endCol = node.node:range() -- range of the capture, zero-indexed
27+
vim.highlight.range(
28+
bufnr,
29+
nsid,
30+
("rainbowcol" .. color_no_),
31+
{endRow, endCol - 1},
32+
{endRow, endCol - 1},
33+
"blockwise",
34+
true
35+
)
36+
end
3537
end
3638
end
3739
end
@@ -69,12 +71,13 @@ function M.detach(bufnr)
6971
vim.api.nvim_buf_attach(
7072
bufnr,
7173
false,
72-
{on_lines = function() return true end}
74+
{on_lines = function()
75+
return true
76+
end}
7377
)
7478
require "nvim-treesitter.highlight"
7579
local hlmap = vim.treesitter.highlighter.hl_map
7680
hlmap["punctuation.bracket"] = "TSPunctBracket"
77-
-- vim.cmd[[highlight link TSPunctBracket Delimiter]]
7881
end
7982

8083
return M

0 commit comments

Comments
 (0)