bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#59862: quit-restore per window buffer


From: martin rudalics
Subject: bug#59862: quit-restore per window buffer
Date: Mon, 8 Jul 2024 18:49:52 +0200
User-agent: Mozilla Thunderbird

It took me some time to rewrite the code for this since I found a couple
of leaks in the window handling code which I tried to plug now.  In a
nutshell, the new patch is supposed to fix the following issues.

- I introduced a new variable called 'kill-buffer-quit-windows'.  If
  non-nil, it makes killing a buffer call 'quit-restore-window' for each
  window showing the buffer thus implementing the behavior you want.  If
  nil, killing a buffer works as before apart from the fixes I added
  below.

- The new window parameter type 'quit-restore-prev' that was already in
  the previous patch handles most scenarios of traversing an entire
  chain of buffer display operations back to the one that initially
  created a window or a frame.  The only thing it does not handle is to
  restore the previously selected window for all but the first and last
  such operation.

- As in the previous patch I remove a buffer from all live windows'
  previous/next buffers and quit-restore(-prev) parameters when killing
  it.  In the present patch I remove it also from dead windows (windows
  presumably stored in window configurations if they survived at least
  one collection cycle after their deletion).  This should eliminate the
  necessity to scan these lists separately in the mark phase of the
  collector.

- The old code erroneously has an internal window share the lists of
  previous/next buffers of a live window whenever that internal window
  is created by splitting the live window.  If the live window is
  subsequently deleted but the internal window persists, these lists
  will continue to exist until the internal window is deleted.  Since
  you cannot switch buffers in internal windows, these lists are
  completely useless while increasing memory overhead.  The patch fixes
  this leak.

Dead windows are kept in a weak hash table, adding a window when it is
deleted and removing it when restoring it from a saved window
configuration.  The collector is supposed to remove all dead windows
whose configurations have died in its finalization phase.  For testing
purposes, this hash table is accessible from Lisp via the variable
'window-dead-windows-table'.

In earlier versions of Emacs, window configurations were mostly used to
handle window excursions and were consequently rather short-lived.  Your
tab bar code has changed that.  Hence we should try to avoid any leaks
introduced by long-lived configurations.

The hash table based code should also work for the incremental (MPS
based) collector once it is capable of handling weak hash tables
correctly.  The present approach to emulate the above mentioned separate
mark steps in Elisp is completely inadequate in this regard since it
cannot identify dead windows.

Please test the patch intensively and report any problems you see.  I
used the forms below to test the various features of the patch.

martin

(display-buffer (get-buffer-create "*foo*"))
(display-buffer (get-buffer-create "*bar*"))

(setq kill-buffer-quit-windows t)

(kill-buffer "*bar*")
(kill-buffer "*foo*")

(setq foo (current-window-configuration))
(set-window-configuration foo)
(setq foo nil) ; To reclaim all dead windows of foo

(garbage-collect)

(hash-table-count window-dead-windows-table)

Attachment: windows-and-buffers.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]