mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-07-01 04:12:17 +02:00
Update: alpha opens in every new tab
This commit is contained in:
@@ -2,6 +2,33 @@
|
|||||||
|
|
||||||
_G.alpha_tab_ascii = {}
|
_G.alpha_tab_ascii = {}
|
||||||
|
|
||||||
|
-- Temporarily unlist other buffers so alpha.start(true) isn't skipped
|
||||||
|
-- when other tabs have real files open, then restore them after
|
||||||
|
local function force_alpha_start()
|
||||||
|
local alpha_loaded, alpha = pcall(require, 'alpha')
|
||||||
|
if not alpha_loaded then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local curbuf = vim.api.nvim_get_current_buf()
|
||||||
|
local restore = {}
|
||||||
|
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||||
|
if buf ~= curbuf and vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_option(buf, 'buflisted') then
|
||||||
|
table.insert(restore, buf)
|
||||||
|
vim.api.nvim_buf_set_option(buf, 'buflisted', false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
alpha.start(true)
|
||||||
|
|
||||||
|
for _, buf in ipairs(restore) do
|
||||||
|
if vim.api.nvim_buf_is_valid(buf) then
|
||||||
|
vim.api.nvim_buf_set_option(buf, 'buflisted', true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
_G.force_alpha_start = force_alpha_start
|
||||||
|
|
||||||
local last_tab_count = #vim.api.nvim_list_tabpages()
|
local last_tab_count = #vim.api.nvim_list_tabpages()
|
||||||
|
|
||||||
-- Save ASCII art
|
-- Save ASCII art
|
||||||
@@ -46,7 +73,7 @@ vim.api.nvim_create_autocmd('TabEnter', {
|
|||||||
local dashboard_loaded, dashboard = pcall(require, 'alpha.themes.dashboard')
|
local dashboard_loaded, dashboard = pcall(require, 'alpha.themes.dashboard')
|
||||||
if not dashboard_loaded then
|
if not dashboard_loaded then
|
||||||
vim.cmd 'enew'
|
vim.cmd 'enew'
|
||||||
alpha.start(true)
|
force_alpha_start()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -57,19 +84,27 @@ vim.api.nvim_create_autocmd('TabEnter', {
|
|||||||
end
|
end
|
||||||
|
|
||||||
vim.cmd 'enew'
|
vim.cmd 'enew'
|
||||||
alpha.start(true)
|
force_alpha_start()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Clean
|
-- Clean
|
||||||
|
-- <afile> here is the tab's position number, not its handle, so we
|
||||||
|
-- can't use it to key into alpha_tab_ascii directly. Prune any cached
|
||||||
|
-- handle that's no longer a live tabpage instead.
|
||||||
vim.api.nvim_create_autocmd('TabClosed', {
|
vim.api.nvim_create_autocmd('TabClosed', {
|
||||||
pattern = '*',
|
pattern = '*',
|
||||||
callback = function()
|
callback = function()
|
||||||
local closed_tab = tonumber(vim.fn.expand '<afile>')
|
local live_tabs = {}
|
||||||
if closed_tab then
|
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
||||||
_G.alpha_tab_ascii[closed_tab] = nil
|
live_tabs[tab] = true
|
||||||
|
end
|
||||||
|
for cached_tab, _ in pairs(_G.alpha_tab_ascii) do
|
||||||
|
if not live_tabs[cached_tab] then
|
||||||
|
_G.alpha_tab_ascii[cached_tab] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ vim.keymap.set('n', '<leader>th', '<Cmd>vsplit | wincmd l | terminal<CR>i', { no
|
|||||||
vim.keymap.set('n', '<Leader>e', function()
|
vim.keymap.set('n', '<Leader>e', function()
|
||||||
vim.cmd 'tabnew' -- create a new tab
|
vim.cmd 'tabnew' -- create a new tab
|
||||||
vim.cmd 'enew' -- create a new empty buffer in it
|
vim.cmd 'enew' -- create a new empty buffer in it
|
||||||
require('alpha').start(true) -- open Alpha dashboard in this new tab
|
_G.force_alpha_start() -- opens Alpha
|
||||||
end, { noremap = true, silent = true, desc = 'Create a new tab' })
|
end, { noremap = true, silent = true, desc = 'Create a new tab' })
|
||||||
|
|
||||||
-- [[ Horizontal split with new empty buffer below ]]
|
-- [[ Horizontal split with new empty buffer below ]]
|
||||||
|
|||||||
Reference in New Issue
Block a user