Add: Open alpha window on every new tab.

This commit is contained in:
psychhim
2025-10-15 20:33:56 +05:30
parent e548ded27e
commit 45ffc1a03c
3 changed files with 49 additions and 18 deletions

View File

@@ -113,11 +113,12 @@ vim.keymap.set('n', '<leader>tv', '<Cmd>split | wincmd j | terminal<CR>i', { nor
-- In a horizontal split (right side) -- In a horizontal split (right side)
vim.keymap.set('n', '<leader>th', '<Cmd>vsplit | wincmd l | terminal<CR>i', { noremap = true, silent = true, desc = 'Open terminal in vertical split' }) vim.keymap.set('n', '<leader>th', '<Cmd>vsplit | wincmd l | terminal<CR>i', { noremap = true, silent = true, desc = 'Open terminal in vertical split' })
-- [[ Create an empty buffer in a new tab ]] -- [[ Create an empty buffer in a new tab and open Alpha ]]
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
end, { noremap = true, silent = true, desc = 'Create an empty buffer' }) require('alpha').start(true) -- open Alpha dashboard in this 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 ]]
vim.keymap.set('n', '<leader>sv', function() vim.keymap.set('n', '<leader>sv', function()

View File

@@ -134,14 +134,32 @@ return {
local bufname = vim.api.nvim_buf_get_name(buf) local bufname = vim.api.nvim_buf_get_name(buf)
local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') local buftype = vim.api.nvim_buf_get_option(buf, 'buftype')
local modified = vim.api.nvim_buf_get_option(buf, 'modified') local modified = vim.api.nvim_buf_get_option(buf, 'modified')
-- PATCH: Treat Alpha dashboard as empty -- PATCH: Treat Alpha dashboard as empty buffer and restore normal options
if is_alpha_buffer(buf) or (bufname == '' and buftype == '' and not modified) then if is_alpha_buffer(buf) or (bufname == '' and buftype == '' and not modified) then
empty_buf = buf
vim.api.nvim_set_current_win(win) vim.api.nvim_set_current_win(win)
-- Clear Alpha buffer if it's Alpha
if is_alpha_buffer(buf) then if is_alpha_buffer(buf) then
vim.api.nvim_buf_delete(buf, { force = true }) vim.api.nvim_buf_set_option(buf, 'modifiable', true)
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {}) -- clear contents
vim.api.nvim_buf_set_option(buf, 'buftype', '')
vim.api.nvim_buf_set_option(buf, 'modified', false)
end
-- Open the file in this window
vim.cmd('edit! ' .. vim.fn.fnameescape(path)) -- force edit
-- Restore normal buffer/window options
local normal_win_opts = {
number = true, -- enable line numbers
relativenumber = true, -- enable relative line numbers
signcolumn = 'yes', -- show sign column
cursorline = false, -- no cursorline by default
foldenable = true, -- enable folds
wrap = false, -- no line wrap
spell = false, -- disable spell
}
local win = vim.api.nvim_get_current_win()
for opt, val in pairs(normal_win_opts) do
vim.api.nvim_win_set_option(win, opt, val)
end end
vim.cmd('edit ' .. vim.fn.fnameescape(path))
return return
end end
end end

View File

@@ -56,12 +56,6 @@ return {
local actions = require 'telescope.actions' local actions = require 'telescope.actions'
local action_state = require 'telescope.actions.state' local action_state = require 'telescope.actions.state'
-- Helper function to detect Alpha dashboard buffer
local function is_alpha_buffer(buf)
local ft = vim.api.nvim_buf_get_option(buf, 'filetype')
return ft == 'alpha'
end
local function smart_open(prompt_bufnr) local function smart_open(prompt_bufnr)
local entry = action_state.get_selected_entry() local entry = action_state.get_selected_entry()
if not entry then if not entry then
@@ -93,16 +87,34 @@ return {
local name = vim.api.nvim_buf_get_name(buf) local name = vim.api.nvim_buf_get_name(buf)
local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') local buftype = vim.api.nvim_buf_get_option(buf, 'buftype')
local modified = vim.api.nvim_buf_get_option(buf, 'modified') local modified = vim.api.nvim_buf_get_option(buf, 'modified')
local ft = vim.api.nvim_buf_get_option(buf, 'filetype')
-- PATCH: also treat Alpha dashboard buffer as empty -- PATCH: also treat Alpha dashboard buffer as empty
if (name == '' and buftype == '' and not modified) or is_alpha_buffer(buf) then if (name == '' and buftype == '' and not modified) or ft == 'alpha' then
vim.api.nvim_set_current_win(win) vim.api.nvim_set_current_win(win)
-- DELETE Alpha buffer if it's in this window -- DELETE Alpha buffer contents if it's Alpha
if is_alpha_buffer(buf) then if ft == 'alpha' then
vim.api.nvim_buf_delete(buf, { force = true }) vim.api.nvim_buf_set_option(buf, 'modifiable', true)
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {}) -- clear contents
vim.api.nvim_buf_set_option(buf, 'buftype', '')
vim.api.nvim_buf_set_option(buf, 'modified', false)
end end
-- Now open the file in this window -- Now open the file in this window
vim.cmd('edit ' .. vim.fn.fnameescape(path)) vim.cmd('edit! ' .. vim.fn.fnameescape(path)) -- note the !
-- Stop further processing
-- Restore normal buffer/window options after opening a file
local normal_win_opts = {
number = true, -- enable line numbers
relativenumber = true, -- enable relative line numbers
signcolumn = 'yes', -- show sign column
cursorline = false, -- no cursorline by default
foldenable = true, -- enable folds
wrap = false, -- no line wrap
spell = false, -- disable spell
}
local win = vim.api.nvim_get_current_win()
for opt, val in pairs(normal_win_opts) do
vim.api.nvim_win_set_option(win, opt, val)
end
return return
end end
end end