From 5044bfa809aa9e1516683665bf979189cfb39b89 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sat, 18 May 2024 03:24:56 +0300 Subject: [PATCH] Fix project-find-regexp in remote projects * lisp/progmodes/xref.el (xref--hits-file-prefix): New variable. Something to prepend to each file name (bug#69233). (xref--convert-hits): Use it to also store the "default directory" part of the filename conditionally on whether it's remote. (xref--collect-matches): Use the new variable here. (cherry picked from commit db039399cccd38b767bf6a30ba6c5da593eb69cf) --- lisp/progmodes/xref.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index f6f3729b47c..ced860a2038 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -2223,15 +2223,17 @@ Such as the current syntax table and the applied syntax properties." (defvar xref--last-file-buffer nil) (defvar xref--temp-buffer-file-name nil) (defvar xref--hits-remote-id nil) +(defvar xref--hits-file-prefix nil) (defun xref--convert-hits (hits regexp) - (let (xref--last-file-buffer - (tmp-buffer (generate-new-buffer " *xref-temp*")) - (xref--hits-remote-id (if (file-name-absolute-p (cadar hits)) - ;; TODO: Add some test for this. - (file-remote-p default-directory) - default-directory)) - (syntax-needed (xref--regexp-syntax-dependent-p regexp))) + (let* (xref--last-file-buffer + (tmp-buffer (generate-new-buffer " *xref-temp*")) + (xref--hits-remote-id (file-remote-p default-directory)) + (xref--hits-file-prefix (if (and hits (file-name-absolute-p (cadar hits))) + ;; TODO: Add some test for this. + xref--hits-remote-id + (expand-file-name default-directory))) + (syntax-needed (xref--regexp-syntax-dependent-p regexp))) (unwind-protect (mapcan (lambda (hit) (xref--collect-matches hit regexp tmp-buffer syntax-needed)) @@ -2240,7 +2242,7 @@ Such as the current syntax table and the applied syntax properties." (defun xref--collect-matches (hit regexp tmp-buffer syntax-needed) (pcase-let* ((`(,line ,file ,text) hit) - (file (and file (concat xref--hits-remote-id file))) + (file (and file (concat xref--hits-file-prefix file))) (buf (xref--find-file-buffer file))) (if buf (with-current-buffer buf -- 2.39.5