Subject: [PATCH] Update 'xref-num-matches-found' when reverting *xref* buffer

From: Eshel Yaron <[email-masked]>
Date: Mon, 11 Nov 2024 20:16:22 +0100

Tags: patch

Hi,

The *xref* buffer displays the number of found matches in the mode line.
With this patch, it also updates that number, stored in variable
xref-num-matches-found, when you revert the buffer.  That way the mode
line shows the updated number of matches when you add or delete some
references and revert the *xref* buffer.

>From 47fb809c858ee4fb18283350a4af6d9c7c33a8fb Mon Sep 17 00:00:00 2001
From: Eshel Yaron <[email-masked]>
Date: Mon, 11 Nov 2024 19:45:10 +0100
Subject: [PATCH] Update 'xref-num-matches-found' when reverting *xref* buffer

* lisp/progmodes/xref.el (xref--insert-xrefs): Update
'xref-num-matches-found' here...
(xref--show-xref-buffer): ...instead of here.
---
 lisp/progmodes/xref.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index cc06e06ef78..cf061a18ee0 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -1139,6 +1139,7 @@ xref--insert-xrefs
 GROUP is a string for decoration purposes and XREF is an
 `xref-item' object."
   (require 'compile) ; For the compilation faces.
+  (setq xref-num-matches-found 0)
   (cl-loop for (group . xrefs) in xref-alist
            for max-line = (cl-loop for xref in xrefs
                                    maximize (xref-location-line
@@ -1158,6 +1159,7 @@ xref--insert-xrefs
            (xref--insert-propertized '(face xref-file-header xref-group t)
                                      group "\n")
            (dolist (xref xrefs)
+             (cl-incf xref-num-matches-found)
              (pcase-let (((cl-struct xref-item summary location) xref))
                (let* ((line (xref-location-line location))
                       (prefix
@@ -1247,7 +1249,6 @@ xref--show-xref-buffer
       (xref--ensure-default-directory dd (current-buffer))
       (xref--xref-buffer-mode)
       (xref--show-common-initialize xref-alist fetcher alist)
-      (setq xref-num-matches-found (length xrefs))
       (setq mode-line-process (list xref-mode-line-matches))
       (pop-to-buffer (current-buffer))
       (setq buf (current-buffer)))
-- 
2.46.2