aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshkan Kiani <ashkan.k.kiani@gmail.com>2019-10-18 21:53:28 -0700
committerAshkan Kiani <ashkan.k.kiani@gmail.com>2019-10-18 21:53:28 -0700
commita6a1a236aa3d3b00294a5642409c84a75c2c4e79 (patch)
treec2f3809f19b423626ab9cded2265ff7b5bdbea9f
parentImprove algorithm performance and correctness. (#15) (diff)
Add experimental, but functional implementation.cursor-highlight
-rw-r--r--lua/colorizer.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/lua/colorizer.lua b/lua/colorizer.lua
index f127b19..d60c5d4 100644
--- a/lua/colorizer.lua
+++ b/lua/colorizer.lua
@@ -605,6 +605,49 @@ local function get_buffer_options(buf)
return merge({}, BUFFER_OPTIONS[buf])
end
+nvim.o.guicursor = "n-v-c-sm:block-Cursor,i-ci-ve:ver25,r-cr-o:hor20"
+local CURSOR_HIGHLIGHTS
+local CURSOR_LINE
+local function follow_cursor()
+ local pos = nvim.win_get_cursor(0)
+ local buf = nvim_get_current_buf()
+ local options = BUFFER_OPTIONS[buf]
+ if not options then return end
+
+ if pos[1] ~= CURSOR_LINE then
+ CURSOR_LINE = pos[1]
+ CURSOR_HIGHLIGHTS = {}
+ local line = nvim_buf_get_lines(buf, CURSOR_LINE-1, CURSOR_LINE, true)[1]
+ local loop_parse_fn = make_matcher(options)
+ local i = 1
+ while i < #line do
+ local length, rgb_hex = loop_parse_fn(line, i)
+ if length then
+ table.insert(CURSOR_HIGHLIGHTS, {i, i+length, rgb_hex})
+ i = i + length
+ else
+ i = i + 1
+ end
+ end
+ end
+ local col = pos[2]+1
+ local highlight_found = false
+ for _, highlight in ipairs(CURSOR_HIGHLIGHTS) do
+ local i, j, rgb_hex = unpack(highlight)
+ if i <= col and j > col then
+ print(col, i, j, rgb_hex)
+ nvim.ex.highlight("Cursor", "guibg=#"..rgb_hex, "guifg=#"..rgb_hex)
+ highlight_found = true
+ break
+ end
+ end
+ if not highlight_found then
+ nvim.ex.highlight("Cursor NONE")
+ end
+end
+FOLLOW_CURSOR = follow_cursor
+nvim.ex.autocmd("CursorMoved,CursorMovedI * lua FOLLOW_CURSOR()")
+
--- @export
return {
DEFAULT_NAMESPACE = DEFAULT_NAMESPACE;