From 45ffc1a03cc9806d5aaa854ff2594a851072834a Mon Sep 17 00:00:00 2001 From: psychhim Date: Wed, 15 Oct 2025 20:33:56 +0530 Subject: [PATCH] Add: Open alpha window on every new tab. --- lua/keymaps.lua | 5 +++-- lua/plugins/custom/filetree.lua | 26 +++++++++++++++++++---- lua/plugins/custom/telescope.lua | 36 +++++++++++++++++++++----------- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/lua/keymaps.lua b/lua/keymaps.lua index 1f4d5da..1726c46 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -113,11 +113,12 @@ vim.keymap.set('n', 'tv', 'split | wincmd j | terminali', { nor -- In a horizontal split (right side) vim.keymap.set('n', 'th', 'vsplit | wincmd l | terminali', { 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', 'e', function() vim.cmd 'tabnew' -- create a new tab 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 ]] vim.keymap.set('n', 'sv', function() diff --git a/lua/plugins/custom/filetree.lua b/lua/plugins/custom/filetree.lua index d640709..3a5f3dd 100644 --- a/lua/plugins/custom/filetree.lua +++ b/lua/plugins/custom/filetree.lua @@ -134,14 +134,32 @@ return { local bufname = vim.api.nvim_buf_get_name(buf) local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') 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 - empty_buf = buf vim.api.nvim_set_current_win(win) + -- Clear Alpha buffer if it's Alpha 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 - vim.cmd('edit ' .. vim.fn.fnameescape(path)) return end end diff --git a/lua/plugins/custom/telescope.lua b/lua/plugins/custom/telescope.lua index ee5c296..ecd7776 100644 --- a/lua/plugins/custom/telescope.lua +++ b/lua/plugins/custom/telescope.lua @@ -56,12 +56,6 @@ return { local actions = require 'telescope.actions' 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 entry = action_state.get_selected_entry() if not entry then @@ -93,16 +87,34 @@ return { local name = vim.api.nvim_buf_get_name(buf) local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') 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 - 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) - -- DELETE Alpha buffer if it's in this window - if is_alpha_buffer(buf) then - vim.api.nvim_buf_delete(buf, { force = true }) + -- DELETE Alpha buffer contents if it's Alpha + if ft == 'alpha' then + 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 -- Now open the file in this window - vim.cmd('edit ' .. vim.fn.fnameescape(path)) - -- Stop further processing + vim.cmd('edit! ' .. vim.fn.fnameescape(path)) -- note the ! + + -- 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 end end