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

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

bug#71466: 30.0.50; Buffer-menu-group-by non-nil resets point when Buffe


From: Eshel Yaron
Subject: bug#71466: 30.0.50; Buffer-menu-group-by non-nil resets point when Buffer List is reverted
Date: Mon, 17 Jun 2024 17:43:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Dmitry Gutov <dmitry@gutov.dev> writes:

> On 17/06/2024 10:40, Eshel Yaron wrote:
>>>> 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.
>>> For xref I propose a separate patch that keeps point on the same line
>>> after reverting the xref buffer:
>> LGTM, but FWIW the situation with xref-revert-buffer is not ideal IMO:
>> it might be cleaner to leave 'g' bound to the usual revert-buffer and
>> set revert-buffer-function to (a slightly modified) xref-revert-buffer.
>> That way xref-revert-buffer wouldn't need to duplicate generic parts of
>> revert-buffer, such as running revert-buffer-restore-functions.  WDYT?
>
> I'm okay with that.

Here's a concrete proposal:

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index fb6c9dad73b..9878806c0de 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -993,7 +993,6 @@ xref--xref-buffer-mode-map
     ;; suggested by Johan Claesson "to further reduce finger movement":
     (define-key map (kbd ".") #'xref-next-line)
     (define-key map (kbd ",") #'xref-prev-line)
-    (define-key map (kbd "g") #'xref-revert-buffer)
     (define-key map (kbd "M-,") #'xref-quit-and-pop-marker-stack)
     map))
 
@@ -1011,6 +1010,7 @@ xref--xref-buffer-mode
         #'xref--imenu-extract-index-name)
   (setq-local add-log-current-defun-function
               #'xref--add-log-current-defun)
+  (setq-local revert-buffer-function #'xref-revert-buffer)
   (setq-local outline-minor-mode-cycle t)
   (setq-local outline-minor-mode-use-buttons 'insert)
   (setq-local outline-search-function
@@ -1273,22 +1273,17 @@ xref--show-common-initialize
           xref--original-window-intent (assoc-default 'display-action alist))
     (setq xref--fetcher fetcher)))
 
-(defun xref-revert-buffer ()
+(defun xref-revert-buffer (&rest _)     ; Ignore `revert-buffer' args.
   "Refresh the search results in the current buffer."
   (interactive)
   (let ((inhibit-read-only t)
-        (buffer-undo-list t)
-        restore-functions)
-    (when (boundp 'revert-buffer-restore-functions)
-      (run-hook-wrapped 'revert-buffer-restore-functions
-                        (lambda (f) (push (funcall f) restore-functions) nil)))
+        (buffer-undo-list t))
     (save-excursion
       (condition-case err
           (let ((alist (xref--analyze (funcall xref--fetcher)))
                 (inhibit-modification-hooks t))
             (erase-buffer)
-            (prog1 (xref--insert-xrefs alist)
-              (mapc #'funcall (delq nil restore-functions))))
+            (xref--insert-xrefs alist))
         (user-error
          (erase-buffer)
          (insert






reply via email to

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