Open alpha when all buffers closed? #85
-
Hello! Using Currently, If i close all those buffers, I get an empty How? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 12 replies
-
Also tried to do this, however it seems that trying almost any possible autocmd with alpha.start() failed with a lot of errors. |
Beta Was this translation helpful? Give feedback.
-
I've tried |
Beta Was this translation helpful? Give feedback.
-
famiu kindly added ---@author kikito
---@see https://codereview.stackexchange.com/questions/268130/get-list-of-buffers-from-current-neovim-instance
local function get_listed_buffers()
local buffers = {}
local len = 0
for buffer = 1, vim.fn.bufnr('$') do
if vim.fn.buflisted(buffer) == 1 then
len = len + 1
buffers[len] = buffer
end
end
return buffers
end
vim.api.nvim_create_augroup('alpha_on_empty', { clear = true })
vim.api.nvim_create_autocmd('User', {
pattern = 'BDeletePre',
group = 'alpha_on_empty',
callback = function(event)
local found_non_empty_buffer = false
local buffers = get_listed_buffers()
for _, bufnr in ipairs(buffers) do
if not found_non_empty_buffer then
local name = vim.api.nvim_buf_get_name(bufnr)
local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype')
if bufnr ~= event.buf and name ~= '' and ft ~= 'Alpha' then
found_non_empty_buffer = true
end
end
end
if not found_non_empty_buffer then
require 'neo-tree'.close_all()
vim.cmd [[:Alpha]]
end
end,
})
|
Beta Was this translation helpful? Give feedback.
-
You can leverage the vim.api.nvim_create_autocmd("User", {
pattern = "BDeletePost",
callback = function(event)
local fallback_name = vim.api.nvim_buf_get_name(event.buf)
local fallback_ft = vim.api.nvim_buf_get_option(event.buf, "filetype")
local fallback_on_empty = fallback_name == "" and fallback_ft == ""
if fallback_on_empty then
-- do you magic there
end
end,
}) |
Beta Was this translation helpful? Give feedback.
-
With this breaking change commit (famiu/bufdelete.nvim@bdaae05), pattern need to be |
Beta Was this translation helpful? Give feedback.
-
Does this work for you correctly? vim.api.nvim_create_augroup("alpha_on_empty", { clear = true })
vim.api.nvim_create_autocmd("User", {
pattern = "BDeletePost*",
group = "alpha_on_empty",
callback = function(event)
local fallback_name = vim.api.nvim_buf_get_name(event.buf)
local fallback_ft = vim.api.nvim_buf_get_option(event.buf, "filetype")
local fallback_on_empty = fallback_name == "" and fallback_ft == ""
if fallback_on_empty then
vim.cmd("Alpha")
end
end,
}) Somehow a "[No Name]" buffer is created which messes up the handling of opening/deleting multiple buffers in sequence |
Beta Was this translation helpful? Give feedback.
-
Thanks for your effort! The only difference was that you were opening files via neo-tree and I via Telescope. But with your updated autocmd both work flawless for me as well! |
Beta Was this translation helpful? Give feedback.
I worked this out in a roundabout way by binding a specific callback to delete buffers (and as the callback to delete buffers in bufferline.nvm)Perhaps bufdelete.nvim will add a User event or callback option, in which case this would be a drop easier to configure. See famiu/bufdelete.nvim#18famiu kindly added
BDeletePre
to bufdelete.nvim, so this is good: