Subject: [PATCH] Correctly check buffer mtime when displaying xref matches
From: Spencer Baugh <[email-masked]>
To: [email-masked]
Cc: Dmitry Gutov <[email-masked]>
Date: Tue, 26 Mar 2024 08:45:36 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

This fixes what appears to just be an oversight, although maybe I am
missing some subtle reason it's correct to check current-buffer here.

In GNU Emacs 29.2.50 (build 4, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.15.12, Xaw scroll bars) of 2024-02-28 built on
 igm-qws-u22796a
Repository revision: 46e23709d37943a20faa735c97af520196a443e9
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Rocky Linux 8.9 (Green Obsidian)

Configured using:
 'configure 'CFLAGS=-O0 -g3' --with-gif=ifavailable
 --with-x-toolkit=lucid'

From 718f2dc2c23660bc002b852bb36f2ece292ed524 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
Date: Tue, 26 Mar 2024 08:44:25 -0400
Subject: [PATCH] Correctly check buffer mtime when displaying xref matches

This was just a typo: we were checking the modification time of
current-buffer instead of checking the modification time of the
passed-in buffer.

This caused matches to not be shown if they weren't present in
the current in-Emacs state of the buffer.

This was easily reproduced by writing a string to a file outside
Emacs, then searching for that string with
e.g. project-find-regexp.  The string would seemingly not be
found, although in reality it was found, just not displayed.

* lisp/progmodes/xref.el (xref--find-file-buffer): Check buf,
not current-buffer.
---
 lisp/progmodes/xref.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 717b837a2e5..755c3db04fd 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -2176,7 +2176,7 @@ xref--find-file-buffer
                  (or
                   (buffer-modified-p buf)
                   (unless xref--hits-remote-id
-                    (not (verify-visited-file-modtime (current-buffer))))))
+                    (not (verify-visited-file-modtime buf)))))
         ;; We can't use buffers whose contents diverge from disk (bug#54025).
         (setq buf nil))
       (setq xref--last-file-buffer (cons file buf))))
-- 
2.39.3