Subject: bug#45848: 27.1; Buffers menu opens wrong buffer

From: Lars Ingebrigtsen <[email-masked]>
Date: Mon, 09 May 2022 16:17:28 +0200

martin rudalics <[email-masked]> writes:

>> In recent versions of GTK Emacs with multiple frames open, selecting the
>> top buffer from the Buffers menu often opens the wrong buffer.  Upon
>> returning to the Buffers menu, the top item has changed to the one that
>> actually opened.  Selecting the desired file from the menu again opens the
>> correct file as expected.

I'm unable to reproduce this, but:

>> I belive the problem is that the Buffers menu opens before the frame focus
>> changes causing the wrong Buffers list to display for the frame.

When clicking on the Buffers menu without selecting the frame first, the
menu first displays the buffers in one order, and then
menu-bar-update-buffers is triggered, and then the order rearranges
itself, which is disturbing.

So menu-bar-update-hook is called too late -- after opening the menu
instead of before.  (Or perhaps called at the right time, but before the
frame is selected...)

> This means that
> conceptually the menu will show the same list regardless from where you
> invoke it unless that invoking step itself changes the global buffer
> list beforehand.  Now selecting a frame is one way to change it, popping
> up a menu from the menu bar should not change it.
>
> So the first issue we'd have to resolve is what the "correct Buffers
> menu" is.

I'm not sure, either.  It just lists things in `buffer-list' order, and
selecting a different frame will select a new window, and therefor a new
buffer, so switching frames will alter the order...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no