From 3654b082bc5d16f9b2102f3ce2a1ac382211dc26 Mon Sep 17 00:00:00 2001 From: Matthew Leong Date: Fri, 13 Jan 2023 07:17:37 -0800 Subject: [PATCH] feat(lualine): add quicker refreshing for macro updates --- lua/cosmic/plugins/lualine/init.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lua/cosmic/plugins/lualine/init.lua b/lua/cosmic/plugins/lualine/init.lua index 1f7fe7b..37cc9a0 100644 --- a/lua/cosmic/plugins/lualine/init.lua +++ b/lua/cosmic/plugins/lualine/init.lua @@ -102,6 +102,35 @@ return { }, extensions = { 'quickfix', 'fugitive', 'nvim-tree' }, }, user_config.plugins.lualine or {})) + + vim.api.nvim_create_autocmd('RecordingEnter', { + callback = function() + require('lualine').refresh({ + place = { 'statusline' }, + }) + end, + }) + + vim.api.nvim_create_autocmd('RecordingLeave', { + callback = function() + -- This is going to seem really weird! + -- Instead of just calling refresh we need to wait a moment because of the nature of + -- `vim.fn.reg_recording`. If we tell lualine to refresh right now it actually will + -- still show a recording occuring because `vim.fn.reg_recording` hasn't emptied yet. + -- So what we need to do is wait a tiny amount of time (in this instance 50 ms) to + -- ensure `vim.fn.reg_recording` is purged before asking lualine to refresh. + local timer = vim.loop.new_timer() + timer:start( + 50, + 0, + vim.schedule_wrap(function() + require('lualine').refresh({ + place = { 'statusline' }, + }) + end) + ) + end, + }) end, dependencies = { 'nvim-tree/nvim-web-devicons' }, enabled = not vim.tbl_contains(user_config.disable_builtin_plugins, 'lualine'),