Skip to content

Commit

Permalink
feat(general behavior)!: deprecate opts.general.update_events
Browse files Browse the repository at this point in the history
1. Deprecate opts.general.update_events in favor of
   opts.general.update_events.win, opts.general.update_events.buf, and
   opts.general.update_events.global
2. Originally all events under opts.general.update_events triggers an
   update on a single winbar attached to a window, however, for some events
   we should update all winbars attached to a buffer, e.g. TextChanged,
   TextChangedI, or BufModifiedSet; on events such as DirChanged, we should
   update all winbars
  • Loading branch information
bekaboo committed Jun 3, 2023
1 parent 06e233a commit 415a587
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 53 deletions.
59 changes: 43 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,24 @@ https://github.com/Bekaboo/dropbar.nvim/assets/76579810/e8c1ac26-0321-4762-9975-
and not vim.wo[win].diff
end,
update_events = {
'BufModifiedSet',
'CursorMoved',
'CursorMovedI',
'DirChanged',
'FileChangedShellPost',
'TextChanged',
'TextChangedI',
'VimResized',
'WinResized',
'WinScrolled',
win = {
'CursorMoved',
'CursorMovedI',
'WinEnter',
'WinLeave',
'WinResized',
'WinScrolled',
},
buf = {
'BufModifiedSet',
'FileChangedShellPost',
'TextChanged',
'TextChangedI',
},
global = {
'DirChanged',
'VimResized',
},
},
},
icons = {
Expand Down Expand Up @@ -496,21 +504,40 @@ general behavior of the plugin:
and not vim.wo[win].diff
end
```
- `opts.general.update_events`: `string[]`
- List of events that should trigger an update of the dropbar
- `opts.general.update_events.win`: `string[]`
- List of events that should trigger an update on the dropbar attached to
a single window
- Default:
```lua
{
'BufModifiedSet',
'CursorMoved',
'CursorMovedI',
'DirChanged',
'WinEnter',
'WinLeave',
'WinResized',
'WinScrolled',
}
```
- `opts.general.update_events.buf`: `string[]`
- List of events that should trigger an update on all dropbars attached to a
buffer
- Default:
```lua
{
'BufModifiedSet',
'FileChangedShellPost',
'TextChanged',
'TextChangedI',
}
```
- `opts.general.update_events.global`: `string[]`
- List of events that should trigger an update of all dropbars in current
nvim session
- Default:
```lua
{
'DirChanged',
'VimResized',
'WinResized',
'WinScrolled',
}
```

Expand Down
43 changes: 31 additions & 12 deletions doc/dropbar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,42 @@ behavior of the plugin:
and not vim.wo[win].diff
end
<
- `opts.general.update_events`: `string[]`
- List of events that should trigger an update of the dropbar
- `opts.general.update_events.win`: `string[]`
- List of events that should trigger an update on the dropbar attached to
a single window
- Default: >lua

{
'BufModifiedSet',
'CursorMoved',
'CursorMovedI',
'DirChanged',
'FileChangedShellPost',
'TextChanged',
'TextChangedI',
'VimResized',
'WinResized',
'WinScrolled',
'CursorMoved',
'CursorMovedI',
'WinEnter',
'WinLeave',
'WinResized',
'WinScrolled',
}
<
- `opts.general.update_events.buf`: `string[]`
- List of events that should trigger an update on all dropbars attached to a
buffer
- Default: >lua

{
'BufModifiedSet',
'FileChangedShellPost',
'TextChanged',
'TextChangedI',
}
<
- `opts.general.update_events.global`: `string[]`
- List of events that should trigger an update of all dropbars in current
nvim session
- Default: >lua

{
'DirChanged',
'VimResized',
}
<

..............................................................................
ICONS *dropbar-configuration-options-icons*
Expand Down
56 changes: 42 additions & 14 deletions lua/dropbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,48 @@ local function setup(opts)
end,
desc = 'Remove dropbar from cache on buffer delete/unload/wipeout.',
})
vim.api.nvim_create_autocmd(configs.opts.general.update_events, {
group = groupid,
callback = function(info)
local win = info.event == 'WinScrolled' and tonumber(info.match)
or vim.api.nvim_get_current_win()
local buf = vim.api.nvim_win_get_buf(win)
if
rawget(_G.dropbar.bars, buf) and rawget(_G.dropbar.bars[buf], win)
then
_G.dropbar.bars[buf][win]:update()
end
end,
desc = 'Update dropbar on cursor move, window/buffer enter, text change.',
})
if not vim.tbl_isempty(configs.opts.general.update_events.win) then
vim.api.nvim_create_autocmd(configs.opts.general.update_events.win, {
group = groupid,
callback = function(info)
local win = info.event == 'WinScrolled' and tonumber(info.match)
or vim.api.nvim_get_current_win()
local buf = vim.api.nvim_win_get_buf(win)
if
rawget(_G.dropbar.bars, buf) and rawget(_G.dropbar.bars[buf], win)
then
_G.dropbar.bars[buf][win]:update()
end
end,
desc = 'Update a single winbar.',
})
end
if not vim.tbl_isempty(configs.opts.general.update_events.buf) then
vim.api.nvim_create_autocmd(configs.opts.general.update_events.buf, {
group = groupid,
callback = function(info)
if rawget(_G.dropbar.bars, info.buf) then
for win, _ in pairs(_G.dropbar.bars[info.buf]) do
_G.dropbar.bars[info.buf][win]:update()
end
end
end,
desc = 'Update all winbars associated with buf.',
})
end
if not vim.tbl_isempty(configs.opts.general.update_events.global) then
vim.api.nvim_create_autocmd(configs.opts.general.update_events.global, {
group = groupid,
callback = function()
for buf, _ in pairs(_G.dropbar.bars) do
for win, _ in pairs(_G.dropbar.bars[buf]) do
_G.dropbar.bars[buf][win]:update()
end
end
end,
desc = 'Update all winbars.',
})
end
vim.api.nvim_create_autocmd({ 'WinClosed' }, {
group = groupid,
callback = function(info)
Expand Down
51 changes: 40 additions & 11 deletions lua/dropbar/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@ M.opts = {
and not vim.wo[win].diff
end,
update_events = {
'BufModifiedSet',
'CursorMoved',
'CursorMovedI',
'DirChanged',
'FileChangedShellPost',
'TextChanged',
'TextChangedI',
'VimResized',
'WinResized',
'WinScrolled',
win = {
'CursorMoved',
'CursorMovedI',
'WinEnter',
'WinLeave',
'WinResized',
'WinScrolled',
},
buf = {
'BufModifiedSet',
'FileChangedShellPost',
'TextChanged',
'TextChangedI',
},
global = {
'DirChanged',
'VimResized',
},
},
},
icons = {
Expand Down Expand Up @@ -318,7 +326,28 @@ M.opts = {
---Set dropbar options
---@param new_opts dropbar_configs_t?
function M.set(new_opts)
M.opts = vim.tbl_deep_extend('force', M.opts, new_opts or {})
new_opts = new_opts or {}
-- Notify deprecated options
if new_opts.general and vim.tbl_islist(new_opts.general.update_events) then
vim.api.nvim_echo({
{ '[dropbar.nvim] ', 'Normal' },
{ 'opts.general.update_events', 'WarningMsg' },
{ ' is deprecated.\n', 'Normal' },
{ '[dropbar.nvim] ', 'Normal' },
{ 'Please use\n', 'Normal' },
{ ' opts.general.update_events.win ', 'WarningMsg' },
{ 'for updating a winbar attached to a single window,\n', 'Normal' },
{ ' opts.general.update_events.buf ', 'WarningMsg' },
{ 'for updating all winbars attached to a buffer, or\n', 'Normal' },
{ ' opts.general.update_events.global ', 'WarningMsg' },
{ 'for updating all winbars in current nvim session ', 'Normal' },
{ 'instead.\n', 'Normal' },
}, true, {})
new_opts.general.update_events = {
win = new_opts.general.update_events,
}
end
M.opts = vim.tbl_deep_extend('force', M.opts, new_opts)
end

---Evaluate a dynamic option value (with type T|fun(...): T)
Expand Down

0 comments on commit 415a587

Please sign in to comment.