From 6aefafe78fa6946d3596ba4226218b03da8dba33 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 31 May 2024 22:15:03 +0200 Subject: make logic in close_current_buffer clearer --- lua/functions.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/functions.lua b/lua/functions.lua index 6ec4658..7d95ac3 100644 --- a/lua/functions.lua +++ b/lua/functions.lua @@ -110,7 +110,7 @@ function _G.close_current_buffer() local all_buffers = vim.fn.getbufinfo() - local buffers = table.filter( + local file_buffers = table.filter( all_buffers, function(buf_info) return buf_info.loaded == 1 @@ -121,10 +121,10 @@ function _G.close_current_buffer() end ) - if #buffers ~= 0 then - vim.cmd("buffer " .. buffers[1].bufnr) - else + if #file_buffers == 0 then vim.cmd("new") + else + vim.cmd("buffer " .. file_buffers[1].bufnr) end vim.api.nvim_buf_delete(current_buf_nr, { force = true }) -- cgit v1.2.3-18-g5258