]> git.eshelyaron.com Git - emacs.git/commitdiff
Use 'revert-buffer' in Xref buffers instead of bespoke command
authorEshel Yaron <me@eshelyaron.com>
Tue, 4 Jun 2024 09:05:11 +0000 (11:05 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 4 Jun 2024 09:05:11 +0000 (11:05 +0200)
lisp/progmodes/xref.el

index bab5384574ee57bba9d0f94024ea871c6f1b5141..77790b4a919322018465ada04c7854559934c51b 100644 (file)
@@ -1034,7 +1034,6 @@ point."
     ;; 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))
 
@@ -1117,6 +1116,7 @@ Xref buffers."
                 (outline-search-text-property
                  'xref-group nil bound move backward looking-at)))
   (setq-local outline-level (lambda () 1))
+  (setq-local revert-buffer-function #'xref-revert-buffer)
   (setq-local bookmark-make-record-function #'xref-bookmark-make-record))
 
 (defvar xref--transient-buffer-mode-map
@@ -1398,23 +1398,29 @@ this variable to an alist with the following key-value pairs:
           xref--kind (assoc-default 'kind alist))
     (setq xref--fetcher fetcher)))
 
-(defun xref-revert-buffer ()
+(defun xref-revert-buffer (&rest _)
   "Refresh the search results in the current buffer."
-  (interactive)
+  (interactive nil xref--xref-buffer-mode)
   (let ((inhibit-read-only t)
-        (buffer-undo-list t))
-    (save-excursion
-      (condition-case err
-          (let ((alist (xref--analyze (funcall xref--fetcher)))
-                (inhibit-modification-hooks t))
-            (erase-buffer)
-            (xref--insert-xrefs alist))
-        (user-error
-         (erase-buffer)
-         (insert
-          (propertize
-           (error-message-string err)
-           'face 'error)))))))
+        (buffer-undo-list t)
+        (bookmark (bookmark-make-record-default t)))
+    (condition-case err
+        (let ((alist (xref--analyze (funcall xref--fetcher)))
+              (inhibit-modification-hooks t))
+          (erase-buffer)
+          (xref--insert-xrefs alist)
+          (let ((forward-str (bookmark-get-front-context-string bookmark))
+                (behind-str (bookmark-get-rear-context-string bookmark)))
+            (when (and forward-str (search-forward forward-str (point-max) t))
+              (goto-char (match-beginning 0)))
+            (when (and behind-str (search-backward behind-str (point-min) t))
+              (goto-char (match-end 0)))))
+      (user-error
+       (erase-buffer)
+       (insert
+        (propertize
+         (error-message-string err)
+         'face 'error))))))
 
 (defun xref--auto-jump-first (buf value)
   (when value