@@ -711,6 +711,11 @@ if !exists("no_buffers_menu")
711711" startup faster.
712712let s: bmenu_wait = 1
713713
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+
714719if ! exists (" bmenu_priority" )
715720 let bmenu_priority = 60
716721endif
@@ -733,14 +738,13 @@ func! s:BMRemove()
733738 if isdirectory (name)
734739 return
735740 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]
742747 endif
743- let s: bmenu_count = s: bmenu_count - 1
744748 endif
745749endfunc
746750
@@ -749,6 +753,7 @@ func! s:BMShow(...)
749753 let s: bmenu_wait = 1
750754 let s: bmenu_short = 1
751755 let s: bmenu_count = 0
756+ let s: bmenu_items = {}
752757 "
753758 " get new priority, if exists
754759 if a: 0 == 1
@@ -844,9 +849,12 @@ func! s:BMFilename(name, num)
844849 let munge = <SID> BMMunge (a: name , a: num )
845850 let hash = <SID> BMHash (munge)
846851 if s: bmenu_short == 0
852+ let s: bmenu_items [a: num ] = munge
847853 let name = ' an ' . g: bmenu_priority . ' .' . hash . ' &Buffers.' . munge
848854 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
850858 endif
851859 " set 'cpo' to include the <CR>
852860 let cpo_save = &cpo
0 commit comments