-
Notifications
You must be signed in to change notification settings - Fork 466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add recording events to refresh events #1227
base: master
Are you sure you want to change the base?
feat: add recording events to refresh events #1227
Conversation
@mikesmithgh I came across a post somewhere, stating that the register holding the macro data isn't cleared immediately after Here's the related code snippet: vim.api.nvim_create_autocmd('RecordingEnter', {
callback = function()
require('lualine').refresh({ place = { 'statusline' } })
end,
})
-- The register does not clean up immediately after
-- recording stops, so we wait a bit (50ms) before refreshing.
vim.api.nvim_create_autocmd('RecordingLeave', {
callback = function()
local timer = vim.loop.new_timer()
timer:start(
50,
0,
vim.schedule_wrap(function()
require('lualine').refresh({ place = { 'statusline' } })
end)
)
end,
}) |
Same here. Leaving recording mode doesn't immediately register the nvim state. |
@smartinellimarco @darrenchang Thanks for the info, I wasn't aware of this. I suppose it depends on the implementation. @darrenchang for example yours https://github.com/darrenchang/nvim-config/blob/71d4d88ac50a8977297e7ccefccfe223a32d7833/lua/plugins/lualine.lua#L2 -- Format function for displaying macro recording status
local function show_macro_recording()
local recording_register = vim.fn.reg_recording()
if recording_register == "" then
return ""
else
return "Recording @" .. recording_register
end
end is depending on the result of But in my example, function(e)
if e.event == 'RecordingLeave' then
rec_msg = ''
else
rec_msg = 'recording @' .. vim.fn.reg_recording()
end it doesn't rely on the result of But, I can see how this can be a problem and don't have any strong opinions, so I'm fine if we want to just close this as won't do. My workaround at the moment is to explicitly call local rec_msg = ''
vim.api.nvim_create_autocmd({ 'RecordingEnter', 'RecordingLeave' }, {
group = vim.api.nvim_create_augroup('LualineRecordingSection', { clear = true }),
callback = function(e)
if e.event == 'RecordingLeave' then
rec_msg = ''
else
rec_msg = 'recording @' .. vim.fn.reg_recording()
end
require('lualine').refresh()
end,
}) |
I'd like to add the events
RecordingEnter
andRecordingLeave
to the default refresh events.This is useful for cases where the recording register (e.g.,
vim.fn.reg_recording()
) is displayed in lualine. Currently, lualine has to wait until the next refresh which causes a delay. Adding the eventsRecordingEnter
andRecordingLeave
immediately triggers an update for a better experience.For example, noice.nvim does this with the following snippet from its README.
This could also be accomplished manually via:
and with the lualine section: