Skip to content

Commit

Permalink
feat(configs): improve default opts.bar.enable() function
Browse files Browse the repository at this point in the history
  • Loading branch information
Bekaboo committed Dec 26, 2024
1 parent cb3aad3 commit 05715d8
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 31 deletions.
59 changes: 40 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,27 @@ vim.ui.select = require('dropbar.utils.menu').select
bar = {
---@type boolean|fun(buf: integer, win: integer, info: table?): boolean
enable = function(buf, win, _)
return vim.api.nvim_buf_is_valid(buf)
and vim.api.nvim_win_is_valid(win)
and vim.wo[win].winbar == ''
and vim.fn.win_gettype(win) == ''
and vim.bo[buf].ft ~= 'help'
and (
(pcall(vim.treesitter.get_parser, buf, vim.bo[buf].ft)) and true
or false
)
if
not vim.api.nvim_buf_is_valid(buf)
or not vim.api.nvim_win_is_valid(win)
or vim.fn.win_gettype(win) ~= ''
or vim.wo[win].winbar ~= ''
or vim.bo[buf].ft == 'help'
then
return false
end

local stat = vim.uv.fs_stat(vim.api.nvim_buf_get_name(buf))
if stat and stat.size > 1024 * 1024 then
return false
end

return vim.bo[buf].bt == 'markdown'
or pcall(vim.treesitter.get_parser, buf)
or not vim.tbl_isempty(vim.lsp.get_clients({
bufnr = buf,
method = 'textDocument/documentSymbol',
}))
end,
attach_events = {
'OptionSet',
Expand Down Expand Up @@ -1080,18 +1092,27 @@ winbar:
- Default:
```lua
function(buf, win, _)
if not buf or buf == 0 then
buf = vim.api.nvim_get_current_buf()
if
not vim.api.nvim_buf_is_valid(buf)
or not vim.api.nvim_win_is_valid(win)
or vim.fn.win_gettype(win) ~= ''
or vim.wo[win].winbar ~= ''
or vim.bo[buf].ft == 'help'
then
return false
end
if not win or win == 0 then
win = vim.api.nvim_get_current_win()

local stat = vim.uv.fs_stat(vim.api.nvim_buf_get_name(buf))
if stat and stat.size > 1024 * 1024 then
return false
end
return vim.api.nvim_buf_is_valid(buf)
and vim.api.nvim_win_is_valid(win)
and vim.wo[win].winbar == ''
and vim.fn.win_gettype(win) == ''
and vim.bo[buf].ft ~= 'help'
and ((pcall(vim.treesitter.get_parser, buf)) and true or false)

return vim.bo[buf].bt == 'markdown'
or pcall(vim.treesitter.get_parser, buf)
or not vim.tbl_isempty(vim.lsp.get_clients({
bufnr = buf,
method = 'textDocument/documentSymbol',
}))
end,
```
- `opts.bar.attach_events`: `string[]`
Expand Down
27 changes: 21 additions & 6 deletions doc/dropbar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,27 @@ the winbar:
- Default: >lua

function(buf, win, _)
return vim.api.nvim_buf_is_valid(buf)
and vim.api.nvim_win_is_valid(win)
and vim.wo[win].winbar == ''
and vim.fn.win_gettype(win) == ''
and vim.bo[buf].ft ~= 'help'
and ((pcall(vim.treesitter.get_parser, buf)) and true or false)
if
not vim.api.nvim_buf_is_valid(buf)
or not vim.api.nvim_win_is_valid(win)
or vim.fn.win_gettype(win) ~= ''
or vim.wo[win].winbar ~= ''
or vim.bo[buf].ft == 'help'
then
return false
end

local stat = vim.uv.fs_stat(vim.api.nvim_buf_get_name(buf))
if stat and stat.size > 1024 * 1024 then
return false
end

return vim.bo[buf].bt == 'markdown'
or pcall(vim.treesitter.get_parser, buf)
or not vim.tbl_isempty(vim.lsp.get_clients({
bufnr = buf,
method = 'textDocument/documentSymbol',
}))
end,
<
- `opts.bar.attach_events`: `string[]`
Expand Down
27 changes: 21 additions & 6 deletions lua/dropbar/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,27 @@ M.opts = {
bar = {
---@type boolean|fun(buf: integer, win: integer, info: table?): boolean
enable = function(buf, win, _)
return vim.api.nvim_buf_is_valid(buf)
and vim.api.nvim_win_is_valid(win)
and vim.wo[win].winbar == ''
and vim.fn.win_gettype(win) == ''
and vim.bo[buf].ft ~= 'help'
and ((pcall(vim.treesitter.get_parser, buf)) and true or false)
if
not vim.api.nvim_buf_is_valid(buf)
or not vim.api.nvim_win_is_valid(win)
or vim.fn.win_gettype(win) ~= ''
or vim.wo[win].winbar ~= ''
or vim.bo[buf].ft == 'help'
then
return false
end

local stat = vim.uv.fs_stat(vim.api.nvim_buf_get_name(buf))
if stat and stat.size > 1024 * 1024 then
return false
end

return vim.bo[buf].bt == 'markdown'
or pcall(vim.treesitter.get_parser, buf)
or not vim.tbl_isempty(vim.lsp.get_clients({
bufnr = buf,
method = 'textDocument/documentSymbol',
}))
end,
attach_events = {
'BufWinEnter',
Expand Down

0 comments on commit 05715d8

Please sign in to comment.