-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix buffer management when tab creation with
:tab sbuffer
command
- Loading branch information
1 parent
b05f332
commit 467e254
Showing
3 changed files
with
41 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,47 @@ | ||
local M = {} | ||
|
||
-- Creates auto command | ||
M.set_autocmd = function(event, callback) | ||
if not M._group then | ||
M._group = vim.api.nvim_create_augroup("TabScopeNvim", {}) | ||
M._get_augroup = function() | ||
if not M._augroup then | ||
M._augroup = vim.api.nvim_create_augroup("TabScopeNvim", {}) | ||
end | ||
return M._augroup | ||
end | ||
|
||
-- Creates auto command | ||
M.set_autocmd = function(event, callback) | ||
vim.api.nvim_create_autocmd(event, { | ||
group = M._group, | ||
group = M._get_augroup(), | ||
callback = callback, | ||
}) | ||
end | ||
|
||
-- Creates auto command that triggered like bufEnter, but it triggers | ||
-- if buffer changes to the same buffer (like :sbuffer / :tab sbuffer) | ||
M.set_improved_bufenter_autocmd = function(callback) | ||
local triggered = false | ||
|
||
vim.api.nvim_create_autocmd("BufEnter", { | ||
group = M._get_augroup(), | ||
callback = function() | ||
triggered = true | ||
callback() | ||
end, | ||
}) | ||
|
||
vim.api.nvim_create_autocmd("WinEnter", { | ||
group = M._get_augroup(), | ||
callback = function() | ||
triggered = false | ||
vim.schedule(function() | ||
if triggered then | ||
return | ||
end | ||
triggered = true | ||
callback() | ||
end) | ||
end, | ||
}) | ||
|
||
end | ||
|
||
return M |