Skip to content

Commit

Permalink
feat(winbar): add User HeirlineInitWinbar autocmd
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelot committed Jun 6, 2022
1 parent 14d1971 commit c5505f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -1310,12 +1310,31 @@ to the new Neovim `winbar`!
**NOTE**: `winbar` is set _locally_ using a `BufWinEnter` autocommand,
this way, it is possible to disable showing the `winbar` on a per-window basis.
This can be accomplished directly by Heirline during component evaluation (see example below)
or by defining your own autocommands somewhere else, e.g.:
and/or by defining your own autocommands somewhere else, e.g.:

```vim
autocmd FileType foo setlocal winbar=
```

or

```lua
autocmd("User", {
pattern = 'HeirlineInitWinbar',
callback = function(args)
local buf = args.buf
local buftype = vim.tbl_contains(
{ "terminal", "prompt", "nofile", "help", "quickfix" },
vim.bo[buf].buftype
)
local filetype = vim.tbl_contains({ "gitcommit", "fugitive" }, vim.bo[buf].filetype)
if buftype or filetype then
vim.opt_local.winbar = nil
end
end,
})
```

```lua
local WinBars = {
init = utils.pick_child_on_condition,
Expand Down
1 change: 1 addition & 0 deletions lua/heirline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local function setup_local_winbar_with_autocmd()
vim.api.nvim_create_autocmd("BufWinEnter", {
callback = function()
vim.opt_local.winbar = "%{%v:lua.require'heirline'.eval_winbar()%}"
vim.api.nvim_exec_autocmds('User', {pattern = 'HeirlineInitWinbar', modeline = false})
end,
group = augrp_id,
desc = "Heirline: set window-local winbar",
Expand Down

0 comments on commit c5505f6

Please sign in to comment.