nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
5.71k stars 455 forks source link

feat: add recording events to refresh events #1227

Open mikesmithgh opened 2 months ago

mikesmithgh commented 2 months ago

I'd like to add the events RecordingEnter and RecordingLeave 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 events RecordingEnter and RecordingLeave immediately triggers an update for a better experience.

For example, noice.nvim does this with the following snippet from its README.

{
  require('noice').api.status.mode.get,
  cond = require('noice').api.status.mode.has,
  color = { fg = '#ff9e64' },
}

This could also be accomplished manually via:

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
  end,
})

and with the lualine section:

{
  function()
    return rec_msg
  end,
  color = { fg = '#ff9e64' },
}