From 34fea4fc64f719fd5384f6cc393d464cebed38bd Mon Sep 17 00:00:00 2001 From: Yinzuo Jiang Date: Sat, 14 Mar 2026 12:48:23 +0800 Subject: [PATCH] vim-patch:fce324f557: runtime(termdebug): close all buffers in the same way For ASM and Variables buffer, check were done to make sure they existed before attempting to close them, but not for debugged program or gdb communication. The debugged program window is a user-facing one and user might close it manually, so it's better to check if it exists. https://github.com/vim/vim/commit/fce324f55718192ae7de389bb88d423eed7977a2 Co-authored-by: Damien Riegel AI-assisted: Codex --- .../pack/dist/opt/termdebug/plugin/termdebug.vim | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim index a57f58164b..0ebdb78f6a 100644 --- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim +++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @@ -227,12 +227,16 @@ endfunc " Use when debugger didn't start or ended. func s:CloseBuffers() - exe $'bwipe! {s:ptybufnr}' - if s:asmbufnr > 0 && bufexists(s:asmbufnr) - exe $'bwipe! {s:asmbufnr}' - endif - if s:varbufnr > 0 && bufexists(s:varbufnr) - exe $'bwipe! {s:varbufnr}' + for bufnr in [get(s:, 'ptybufnr', 0), get(s:, 'asmbufnr', 0), get(s:, 'varbufnr', 0)] + if bufnr > 0 && bufexists(bufnr) + execute $'bwipe! {bufnr}' + endif + endfor + if exists('s:comm_job_id') + let commbufnr = get(nvim_get_chan_info(s:comm_job_id), 'buffer', 0) + if commbufnr > 0 && bufexists(commbufnr) + execute $'bwipe! {commbufnr}' + endif endif let s:running = v:false unlet! s:gdbwin