neogit icon indicating copy to clipboard operation
neogit copied to clipboard

Automatically refresh upon `BufEnter`?

Open stelcodes opened this issue 11 months ago • 2 comments

Wouldn't it make sense to add BufEnter to this autocmd? I'm finding myself having to manually refresh all the time. Since it's async I don't think this would freeze the UI at all. Maybe an option could be added?

EDIT: I misunderstood the point of this autocommand in particular. Please ignore.

https://github.com/NeogitOrg/neogit/blob/757c74cf4d5765d39370ebb48cbcf1ea44c2f84d/lua/neogit/autocmds.lua#L22-L38

stelcodes avatar Mar 13 '25 22:03 stelcodes

I'm going to add this to my config, even though it fires unnecessarily on initial NeogitStatus opening.


local neogit = require('neogit')
local a = require("plenary.async")
local status_buffer = require("neogit.buffers.status")
local group = require("neogit").autocmd_group
vim.api.nvim_create_autocmd({ "BufEnter" }, {
  pattern = "NeogitStatus",
  callback = a.void(function(o)
    status_buffer.instance():dispatch_refresh(nil, o.event)
  end),
  group = group,
})

Simpler version:

local neogit = require('neogit')
vim.api.nvim_create_autocmd({ "BufEnter" }, {
  pattern = "NeogitStatus",
  callback = function()
    neogit.dispatch_refresh()
  end,
  group = neogit.autocmd_group,
})

stelcodes avatar Mar 14 '25 00:03 stelcodes

I agree with @stelcodes, I would also add FocusGained

disrupted avatar Mar 27 '25 13:03 disrupted