Skip to content

Commit

Permalink
Re-add BufEnter autocmd and handle tmux bug
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
andweeb committed Jun 8, 2021
1 parent 81c3cc0 commit f4c1e22
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions autoload/presence.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function presence#SetAutoCmds()
autocmd VimLeavePre * lua package.loaded.presence:handle_vim_leave_pre()
autocmd WinEnter * lua package.loaded.presence:handle_win_enter()
autocmd WinLeave * lua package.loaded.presence:handle_win_leave()
autocmd BufEnter * lua package.loaded.presence:handle_buf_enter()
autocmd BufAdd * lua package.loaded.presence:handle_buf_add()
endif
augroup END
Expand Down
19 changes: 19 additions & 0 deletions lua/presence/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,13 @@ end
function Presence:handle_focus_gained()
self.log:debug("Handling FocusGained event...")

-- Skip a potentially extraneous update call on initial startup if tmux is being used
-- (See https://github.com/neovim/neovim/issues/14572)
if next(self.last_activity) == nil and os.getenv("TMUX") then
self.log:debug("Skipping presence update for FocusGained event triggered by tmux...")
return
end

if vim.bo.filetype == "qf" then
self.log:debug("Skipping presence update for quickfix window...")
return
Expand Down Expand Up @@ -921,6 +928,18 @@ function Presence:handle_win_leave()
end)
end

-- BufEnter events force-update the presence for the current buffer unless it's a quickfix window
function Presence:handle_buf_enter()
self.log:debug("Handling BufEnter event...")

if vim.bo.filetype == "qf" then
self.log:debug("Skipping presence update for quickfix window...")
return
end

self:update()
end

-- WinLeave events cancel the current buffer presence
function Presence:handle_buf_add()
self.log:debug("Handling BufAdd event...")
Expand Down

0 comments on commit f4c1e22

Please sign in to comment.