-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
label-mode: replace conceal with virtual text in nvim ≥ 0.5
Problem: Using conceal for label interferes with usual syntax highlights that use conceal. Solution: In nvim, set decoration provider that renders labels as virtual text only in the current window.
- Loading branch information
Showing
2 changed files
with
81 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
local M = {} | ||
|
||
local ns = vim.api.nvim_create_namespace('sneak') | ||
|
||
local matches | ||
|
||
function M.before() | ||
matches = {} | ||
end | ||
|
||
function M.placematch(c, row, col) | ||
matches[#matches+1] = { c, row, col } | ||
end | ||
|
||
function M.after() | ||
matches = nil | ||
end | ||
|
||
function M.init() | ||
vim.api.nvim_set_decoration_provider(ns, { | ||
on_start = function(_, _) | ||
if not matches then | ||
return false | ||
end | ||
end, | ||
on_win = function(_, win, _, _, _) | ||
if win ~= vim.api.nvim_get_current_win() then | ||
return false | ||
end | ||
for _, m in ipairs(matches) do | ||
local c, row, col = unpack(m) | ||
vim.api.nvim_buf_set_extmark(0, ns, row, col, { | ||
priority = 1000, | ||
virt_text = { {c, 'SneakLabel'} }, | ||
virt_text_pos = 'overlay', | ||
ephemeral = true, | ||
}) | ||
end | ||
end | ||
}) | ||
end | ||
|
||
return M |