Skip to content

Commit

Permalink
Don't base trail sign group on list/listchars
Browse files Browse the repository at this point in the history
  • Loading branch information
dstein64 committed Jun 19, 2024
1 parent fd334e5 commit 5b70052
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 56 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ with the same positioning logic as the scrollbar.
* `spell`: spell check items when the `spell` option is enabled
* `textwidth`: line lengths exceeding the value of the textwidth option, when
non-zero
* `trail`: trailing whitespace, when the `list` option is enabled and the
`listchars` option includes "trail"
* `trail`: trailing whitespace

`search` and `diagnostics` groups are enabled by default (`marks` too for
`nvim>=0.10`). To modify which sign groups are enabled, set
Expand Down
3 changes: 1 addition & 2 deletions doc/scrollview.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ Group Information
`spell` spell check items when the |'spell'| option is enabled
`textwidth` line lengths exceeding the value of the |'textwidth'| option, when
non-zero
`trail` trailing whitespace, when the |'list'| option is enabled and the
|'listchars'| option includes "trail"
`trail` trailing whitespace

*scrollview-restricted*
Under certain scenarios, the plugin enters a restricted mode to prevent a
Expand Down
70 changes: 18 additions & 52 deletions lua/scrollview/signs/trail.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,26 @@ function M.init(enable)
local lines = {}
local bufnr = api.nvim_win_get_buf(winid)
local changedtick = vim.b[bufnr].changedtick
local list = api.nvim_win_get_option(winid, 'list')
if list then
-- Use getwinvar instead of nvim_win_get_option, since that will return
-- the relevant window-local value (window value if set, global value
-- otherwise).
local listchars = vim.split(fn.getwinvar(winid, '&listchars'), ',')
local trail = false
for _, x in ipairs(listchars) do
if vim.startswith(x, 'trail:') then
trail = true
break
end
end
if trail then
local changedtick_cached
= winvars.scrollview_trail_changedtick_cached
local bufnr_cached
= winvars.scrollview_trail_bufnr_cached
local cache_hit = changedtick_cached == changedtick
and bufnr_cached == bufnr
if cache_hit then
lines = winvars.scrollview_trail_cached
else
local line_count = api.nvim_buf_line_count(bufnr)
for line = 1, line_count do
local string = fn.getbufline(bufnr, line)[1]
if string.match(string, "%s$") then
table.insert(lines, line)
end
end
-- luacheck: ignore 122 (setting read-only field w.?.? of global vim)
winvars.scrollview_trail_changedtick_cached = changedtick
-- luacheck: ignore 122 (setting read-only field w.?.? of global vim)
winvars.scrollview_trail_bufnr_cached = bufnr
-- luacheck: ignore 122 (setting read-only field w.?.? of global vim)
winvars.scrollview_trail_cached = lines
local changedtick_cached = winvars.scrollview_trail_changedtick_cached
local bufnr_cached = winvars.scrollview_trail_bufnr_cached
local cache_hit = changedtick_cached == changedtick
and bufnr_cached == bufnr
if cache_hit then
lines = winvars.scrollview_trail_cached
else
local line_count = api.nvim_buf_line_count(bufnr)
for line = 1, line_count do
local string = fn.getbufline(bufnr, line)[1]
if string.match(string, "%s$") then
table.insert(lines, line)
end
end
-- luacheck: ignore 122 (setting read-only field w.?.? of global vim)
winvars.scrollview_trail_changedtick_cached = changedtick
-- luacheck: ignore 122 (setting read-only field w.?.? of global vim)
winvars.scrollview_trail_bufnr_cached = bufnr
-- luacheck: ignore 122 (setting read-only field w.?.? of global vim)
winvars.scrollview_trail_cached = lines
end
-- luacheck: ignore 122 (setting read-only field w.?.? of global vim)
winvars[name] = lines
Expand All @@ -85,22 +67,6 @@ function M.init(enable)
scrollview.refresh()
end
})

api.nvim_create_autocmd('OptionSet', {
pattern = 'list',
callback = function()
if not scrollview.is_sign_group_active(group) then return end
scrollview.refresh()
end
})

api.nvim_create_autocmd('OptionSet', {
pattern = 'listchars',
callback = function()
if not scrollview.is_sign_group_active(group) then return end
scrollview.refresh()
end
})
end

return M

0 comments on commit 5b70052

Please sign in to comment.