Subject: bug#71466: 30.0.50; Buffer-menu-group-by non-nil resets point when Buffer List is reverted

From: Juri Linkov <[email-masked]>
Date: Tue, 11 Jun 2024 20:05:51 +0300

> I noticed a certain issue with the new Buffer-menu-group-by option: when
> grouping is enabled, reverting the Buffer List buffer may move point
> back to the beginning on the buffer.  This is especially problematic
> when auto-revert-mode is involved.  Consider:
>
> 1. emacs -Q
> 2. (setq global-auto-revert-non-file-buffers t)
> 3. M-x global-auto-revert-mode RET
> 4. (setq Buffer-menu-group-by '(Buffer-menu-group-by-mode))
> 5. M-x list-buffers
> 6. Navigate to some heading in the Buffer List buffer, any heading
>    besides the first.
> 7. Wait (or think) for 5 seconds.
> 8. Auto-revert kicks in and point moves back to the beginning
>    of the buffer.

Thanks for the request, this definitely should be improved.

> Without grouping, reverting the Buffer List (manually or via
> global-auto-revert-mode) keeps point in place.

When point is on an entry, then 'tabulated-list-print'
moves point to the entry with the same ID.

However, what ID to prefer for outline heading lines
is not quite clear.  Possible variants:

1. The simplest way would be to remember the position of point
   or the line number.  But this is not quite reliable
   when new entries are inserted before.

2. Remembering the outline heading line as a string and searching for it
   afterwards would be ambiguous when there are more headings with the
   same string.  For example, when at the top level there are project names,
   and at the second level mode names repeated for every project.

3. To remember a complete path like outline-hidden-headings-paths does,
   e.g. '("Project1 name" "Mode2 name").  But this will not handle modes
   that don't use tabulated-list.  For example, reverting an xref buffer
   with outlines now restores visibility of outlines, but doesn't restore point.
   OTOH, maybe it's not responsibility of outline-minor-mode to restore point
   when it's not on a heading line.

4. To remember some context before and after point, then after reverting
   search context with 'rear-context-string' and 'front-context-string'.