rebelot/heirline.nvim

update on User autocommand not working

Closed this issue · 5 comments

Hi there,

thank you for this nice plugin. I just added a CocDiagnostics component that I want to update on CocDiagnosticChange User autocommand. (see coc.nvim)

I can output the message CocDiagnosticChange event received with this vimscript snippet of code:

augroup coc_diagnostic_test
    au!
    autocmd User CocDiagnosticChange lua print("CocDiagnosticChange event received")
augroup END

when adding this autocommand to the update field of my heirline component like this

[...]
update = { "CocDiagnosticChange" },
[...]

I do get the following error, though:

E5108: Error executing lua ...k/bundle/start/heirline.nvim/lua/heirline/statusline.lua:234: unexpected event
stack traceback:
        [C]: in function 'nvim_create_autocmd'
        ...k/bundle/start/heirline.nvim/lua/heirline/statusline.lua:234: in function 'register_update_autocmd'
        ...k/bundle/start/heirline.nvim/lua/heirline/statusline.lua:274: in function '_eval'
        ...k/bundle/start/heirline.nvim/lua/heirline/statusline.lua:331: in function '_eval'
        ...k/bundle/start/heirline.nvim/lua/heirline/statusline.lua:331: in function '_eval'
        ...k/bundle/start/heirline.nvim/lua/heirline/statusline.lua:331: in function '_eval'
        ...k/bundle/start/heirline.nvim/lua/heirline/statusline.lua:331: in function '_eval'
        ...k/bundle/start/heirline.nvim/lua/heirline/statusline.lua:396: in function 'eval'
        ...te/pack/bundle/start/heirline.nvim/lua/heirline/init.lua:67: in function <...te/pack/bundle/start/heirline.nvim/lua/heirline/init.lua:62>

My best guess is, that the User keyword is a problem here... Is it possible to listen on the CocDiagnosticChange autocommand? There are a couple of other autocommands I would need to listen to as well.

Thx a lot :)

you should do that like you define any User autocmd:

...
update = {
    "User",
    pattern = "CocDiagnosticChange"
}
...
update = {
    "User",
    pattern = "CocDiagnosticChange"
}

sweet. Thx a bunch... still kind of new to (vims) lua. 🎉

@rebelot - Can we add this to the cookbook? Wasn't clear to me right away to structure it like this

@rebelot - Can we add this to the cookbook? Wasn't clear to me right away to structure it like this

Sure I can add an example, but that's a general user autocmd thing, where the autocmd name is actually a pattern matched agains user defined au

Sure I can add an example, but that's a general user autocmd thing, where the autocmd name is actually a pattern matched agains user defined au

Can't say I've been overly exposed to them so needed to do some digging to find out. With newer plugins having custom events (lazy.nvim for example) and statusline integrations, will hopefully save some folks some time.