From 0436ae9135324d68f0e8bbd61df3f3682acc0662 Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 17 Oct 2024 07:23:57 -0600 Subject: [PATCH] Check if Untitled buffer exists before trying to delete it --- lua/cd-project/api.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/cd-project/api.lua b/lua/cd-project/api.lua index 4fd5878..c593306 100644 --- a/lua/cd-project/api.lua +++ b/lua/cd-project/api.lua @@ -91,7 +91,9 @@ local function cd_project_in_tab(dir) vim.fn.execute("tabe | tcd " .. vim.fn.fnameescape(dir)) - vim.api.nvim_command("bdelete! Untitled") + if vim.fn.bufnr("Untitled") == -1 then + vim.api.nvim_command("bdelete! Untitled") + end vim.api.nvim_command("%bdelete") require("persistence").load() local hooks = cd_hooks.get_hooks(vim.g.cd_project_config.hooks, dir, "AFTER_CD") @@ -110,7 +112,9 @@ local function cd_project(dir) vim.fn.execute("cd " .. vim.fn.fnameescape(dir)) - vim.api.nvim_command("bdelete! Untitled") + if vim.fn.bufnr("Untitled") == -1 then + vim.api.nvim_command("bdelete! Untitled") + end vim.api.nvim_command("%bdelete") require("persistence").load()