@@ -711,6 +711,11 @@ if !exists("no_buffers_menu")
711
711
" startup faster.
712
712
let s: bmenu_wait = 1
713
713
714
+ " dictionary of buffer ID to name. This helps prevent bugs where a buffer is
715
+ " somehow being renamed and we can't remove it from the menu because we are
716
+ " using the wrong menu name.
717
+ let s: bmenu_items = {}
718
+
714
719
if ! exists (" bmenu_priority" )
715
720
let bmenu_priority = 60
716
721
endif
@@ -733,14 +738,13 @@ func! s:BMRemove()
733
738
if isdirectory (name)
734
739
return
735
740
endif
736
- let munge = <SID> BMMunge (name, expand (" <abuf>" ) )
737
-
738
- if s: bmenu_short == 0
739
- exe ' silent! aun &Buffers.' . munge
740
- else
741
- exe ' silent! aun &Buffers. ' . <SID> BMHash2 (munge) . munge
741
+ let bufnum = expand (" <abuf>" )
742
+ if s: bmenu_items - > has_key (bufnum)
743
+ let menu_name = s: bmenu_items [bufnum]
744
+ exe ' silent! aun &Buffers.' . menu_name
745
+ let s: bmenu_count = s: bmenu_count - 1
746
+ unlet s: bmenu_items [bufnum]
742
747
endif
743
- let s: bmenu_count = s: bmenu_count - 1
744
748
endif
745
749
endfunc
746
750
@@ -749,6 +753,7 @@ func! s:BMShow(...)
749
753
let s: bmenu_wait = 1
750
754
let s: bmenu_short = 1
751
755
let s: bmenu_count = 0
756
+ let s: bmenu_items = {}
752
757
"
753
758
" get new priority, if exists
754
759
if a: 0 == 1
@@ -844,9 +849,12 @@ func! s:BMFilename(name, num)
844
849
let munge = <SID> BMMunge (a: name , a: num )
845
850
let hash = <SID> BMHash (munge)
846
851
if s: bmenu_short == 0
852
+ let s: bmenu_items [a: num ] = munge
847
853
let name = ' an ' . g: bmenu_priority . ' .' . hash . ' &Buffers.' . munge
848
854
else
849
- let name = ' an ' . g: bmenu_priority . ' .' . hash . ' .' . hash . ' &Buffers.' . <SID> BMHash2 (munge) . munge
855
+ let menu_name = <SID> BMHash2 (munge) . munge
856
+ let s: bmenu_items [a: num ] = l: menu_name
857
+ let name = ' an ' . g: bmenu_priority . ' .' . hash . ' .' . hash . ' &Buffers.' . menu_name
850
858
endif
851
859
" set 'cpo' to include the <CR>
852
860
let cpo_save = &cpo
0 commit comments