which event to use for an autocmd to run a callback? #326
-
Hi @MunifTanjim ref: andreacfromtheapp/chuck-nvim#10 The following code runs fine if I invoke the function with a user command after vim is opened a chuck file but if I set autorun to true to invoke it at start of nvim (when opening a chuck file), the layout is created but none of the functions within the panes run. -- this one creates the NUI layout and spawns the above
function M.chuck_ui(cmd, logfile)
layout.chuck_layout:mount()
layout.chuck_pane:on(events.BufEnter, function()
start_chuck(cmd, logfile)
end, { once = true })
layout.shred_pane:on(events.BufEnter, function()
shred_lines(logfile)
end, { once = true })
vim.cmd("wincmd w")
layout.chuck_layout:update(layout.update_layout)
end I have tried BufNew, BufAdd, VimEnter and more, to no avail. I'm out of ideas. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 24 replies
-
ps: if there is a way to run all code on layout:mount even better. the above doesn't seem right. it works but. |
Beta Was this translation helpful? Give feedback.
Just as a closing note, I'm not entirely sure how
chuck
cli command works... but you should try to separate it from the UI concerns. UI (splits) can be closed and opened again and again. But I'd assume you don't want to runchunk
cli command multiple times. Also inshred_lines
, I assume you're trying to listen to changes in the log file... you shouldn't do that every time UI is opened, you only need to do that once.Once you separate out those two concerns, a lot of the problems you're facing will disappear.
And about
:terminal <cmd>
it creates a new terminal buffer, you can store that terminal buffer number somewhere and then just change the buffer of the split to that terminal buffer wh…