Subject: bug#40225: 27.0.90; abort with apparent stack explosion in lsp-mode

From: Juri Linkov <[email-masked]>
Date: Fri, 11 Feb 2022 10:34:10 +0200

>> > So with regard to the subject of this issue I think it's fine to close
>> > this. Not having tab-line-mode call tab-line-tabs-buffer-list-function
>> > on pretty much every possible event might be a worthwhile improvement
>> > at some point though (I haven't checked whether things improved in
>> > Emacs 28).
>>
>> Pretty much every event can kill buffers, and the list of buffers
>> displayed on the tab line should reflect the change of the buffer list.
>> The existing optimization takes care only to not redraw the tab line
>> on every event when the buffer list is unchanged.
>
> Sounds like the elegant solution here could be a hook that runs when
> buffers are created/killed/renamed.

I wouldn't call it quite elegant but indeed this is a possible optimization
by tracking changes in the buffer list via buffer-list-update-hook.
Patches welcome from anyone who has problems with the current implementation.