mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-07-01 04:12:17 +02:00
Compare commits
2 Commits
5b7601463a
...
fbf75ac3ed
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbf75ac3ed | ||
|
|
e713e93426 |
@@ -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 ]]
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ return {
|
|||||||
end
|
end
|
||||||
-- Reuse empty buffer in current tab
|
-- Reuse empty buffer in current tab
|
||||||
local wins = vim.api.nvim_tabpage_list_wins(0)
|
local wins = vim.api.nvim_tabpage_list_wins(0)
|
||||||
local empty_buf = nil
|
|
||||||
for _, win in ipairs(wins) do
|
for _, win in ipairs(wins) do
|
||||||
if vim.api.nvim_win_is_valid(win) then
|
if vim.api.nvim_win_is_valid(win) then
|
||||||
local buf = vim.api.nvim_win_get_buf(win)
|
local buf = vim.api.nvim_win_get_buf(win)
|
||||||
@@ -165,11 +164,8 @@ return {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if empty_buf then
|
-- No reusable window found, open in a new tab
|
||||||
vim.cmd('edit ' .. vim.fn.fnameescape(path))
|
|
||||||
else
|
|
||||||
vim.cmd('tabnew ' .. vim.fn.fnameescape(path))
|
vim.cmd('tabnew ' .. vim.fn.fnameescape(path))
|
||||||
end
|
|
||||||
-- Always close Neo-tree window if open
|
-- Always close Neo-tree window if open
|
||||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||||
if vim.api.nvim_win_is_valid(win) then
|
if vim.api.nvim_win_is_valid(win) then
|
||||||
|
|||||||
@@ -311,19 +311,8 @@ return {
|
|||||||
require('telescope.builtin').git_files {
|
require('telescope.builtin').git_files {
|
||||||
attach_mappings = function(_, map)
|
attach_mappings = function(_, map)
|
||||||
map('n', 'q', actions.close)
|
map('n', 'q', actions.close)
|
||||||
local actions = require 'telescope.actions'
|
map('i', '<CR>', smart_open)
|
||||||
local action_state = require 'telescope.actions.state'
|
map('n', '<CR>', smart_open)
|
||||||
|
|
||||||
local function open_smart(prompt_bufnr)
|
|
||||||
local entry = action_state.get_selected_entry()
|
|
||||||
if not entry then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
pcall(actions.close, prompt_bufnr)
|
|
||||||
smart_open(prompt_bufnr)
|
|
||||||
end
|
|
||||||
map('i', '<CR>', open_smart)
|
|
||||||
map('n', '<CR>', open_smart)
|
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user