From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#44905: 27.1; Packages that customize xref-show-xrefs-function can break Dired's dired-do-find-regexp-and-replace Date: Sat, 28 Nov 2020 21:04:53 +0200 Message-ID: <7ab2afb1-33ec-bca0-4014-131130e71a04@yandex.ru> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22893"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 To: Daniel =?UTF-8?Q?Mart=C3=ADn?= , 44905@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 28 20:06:16 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kj5Y0-0005pO-Cs for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 28 Nov 2020 20:06:16 +0100 Original-Received: from localhost ([::1]:43946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kj5Xz-00025W-9V for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 28 Nov 2020 14:06:15 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kj5Xo-000257-ML for bug-gnu-emacs@gnu.org; Sat, 28 Nov 2020 14:06:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37520) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kj5Xn-0004Pw-0D for bug-gnu-emacs@gnu.org; Sat, 28 Nov 2020 14:06:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kj5Xm-0007GB-Ru for bug-gnu-emacs@gnu.org; Sat, 28 Nov 2020 14:06:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 28 Nov 2020 19:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44905 X-GNU-PR-Package: emacs Original-Received: via spool by 44905-submit@debbugs.gnu.org id=B44905.160659030427786 (code B ref 44905); Sat, 28 Nov 2020 19:06:02 +0000 Original-Received: (at 44905) by debbugs.gnu.org; 28 Nov 2020 19:05:04 +0000 Original-Received: from localhost ([127.0.0.1]:49058 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kj5Wq-0007E6-9h for submit@debbugs.gnu.org; Sat, 28 Nov 2020 14:05:04 -0500 Original-Received: from mail-wm1-f45.google.com ([209.85.128.45]:40142) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kj5Wo-0007DT-Dn for 44905@debbugs.gnu.org; Sat, 28 Nov 2020 14:05:02 -0500 Original-Received: by mail-wm1-f45.google.com with SMTP id a3so10355776wmb.5 for <44905@debbugs.gnu.org>; Sat, 28 Nov 2020 11:05:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=VSMGvbNb0y2EXkCCqHif9mnHfK7Dw53ljJOda62nOIY=; b=AdGTfu1kXUtxSoFj1N7n2KhFY3n2PF8prxdZcmSz22JeGxPAvuP5p02xxUeSZlu/A+ vB9IO97Lg272qKa4GS83f6KcJ/xQ3kzEG+TA4nbfcu5mMy3LjVeS8PQ+7PJURyHRy1nR NeuPw7mo8Y6QabSch9mePS9JRNWwe4X0zKkoJ+xBFNWaVm21UZMbHRyIOQum3Gb0o3yG wf5xQ0e6lpcr5cGFcT4zxFPh3HqggsD5knnUZJyB41MIdtYaZH4uzkXwR4M3+4r502KB rqvS8H8rgGPjTMIQL9zP2nIRzl/aJvAzMcubGK2LrC//cBN6cFWbsXNf8QnZf+od2My9 uNuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=VSMGvbNb0y2EXkCCqHif9mnHfK7Dw53ljJOda62nOIY=; b=nL4j2LyZkUPwwfuB39SrUTGGpZea2fQvmn9IKakQ99ynUFptTHOyKaRnlOFIdLdIcP 5DALV9VYFhHWZaEIjOEarCk4gCm/UmxY+vfeMKBJEbF4x3nNCxQSmCiN/e8MOW3LkPbs BFESUa1az8bJn60cJP7+dEnQIlA3SO7goYztpDuLAhoQ89ITi5M8Dwz7pjZ2K85wB1l0 gADDHj4tyr2yHjnWLFOcPG9aQPLW+RQdEHD5R5BeNdJEhcS0g/wIEhOukEdbzcsUyKHq FWGCzrH0irlu/9zO/ts3DnjvqTiD+GPFaHAWcldmOOBlLKcaUu/t7I2fsQSA8dw5xZ8a ciYw== X-Gm-Message-State: AOAM531D0lN3kj2vezgnS/6VNtfDBmXxM8PIt4rHTJp7Sj73GwoeOoKT Crytu63rEA65fX81LXOt8MZafO45rlj7tA== X-Google-Smtp-Source: ABdhPJw2NkoSZcVWt2wVrtc/YWU86OrRjYkXStcHDAI6BWhPoR1cC/dpm0RnfKayAAzZXROIINxFfQ== X-Received: by 2002:a1c:4e10:: with SMTP id g16mr15745472wmh.48.1606590296304; Sat, 28 Nov 2020 11:04:56 -0800 (PST) Original-Received: from [192.168.0.4] ([66.205.71.3]) by smtp.googlemail.com with ESMTPSA id 2sm24673662wrq.87.2020.11.28.11.04.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 28 Nov 2020 11:04:55 -0800 (PST) In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:194498 Archived-At: On 27.11.2020 22:14, Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors wrote: > > Scenario: A package customizes xref-show-refs-function to use a > different UI to show xref results. If that function does not return a > valid xref buffer, then Dired's dired-do-find-regexp-and-replace (bound > to Q by default) won't work anymore because it calls > xref-query-replace-in-results on the buffer returned by > xref--show-xrefs. Oh, indeed. Thanks for the report. > A workaround is that the package explicitly calls > xref--show-xref-buffer, which is done for example at > https://github.com/alexmurray/ivy-xref/commit/aa97103ea8ce6ab8891e34deff7d43aa83fe36dd, > but it doesn't feel like an ideal solution because of the duplicated > work. It's too bad this wasn't reported a year ago. > Is there a way dired-do-find-regexp-and-replace could not depend on an > actual xref buffer to perform the replacement? Well, there are options like: - Mandate that any xref-show-refs-function alternative has a corresponding feature that performs replacements in the matches. - Reimplement dired-do-find-regexp-and-replace entirely in terms of a different UI (e.g. create a faster dired-do-query-replace-regexp). But in this particular scenario we can just override xref-show-xrefs-function to use the default behavior, see below. While this change in the Right Thing(tm), I have to question the wisdom of setting xref-show-xrefs-function to an Ivy or Helm-based function, though. Those UIs serve to help you choose one item, whereas commands like dired-do-find-regexp and project-find-regexp show the user a list of matches, to interact with (usually) several of them. diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 94a2bbf1f3..4caafc8df6 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -3140,7 +3140,10 @@ dired-do-find-regexp-and-replace (query-replace-read-args "Query replace regexp in marked files" t t))) (list (nth 0 common) (nth 1 common)))) - (with-current-buffer (dired-do-find-regexp from) + (defvar xref-show-xrefs-function) + (with-current-buffer + (let ((xref-show-xrefs-function 'xref--show-xref-buffer)) + (dired-do-find-regexp from)) (xref-query-replace-in-results from to))) (defun dired-nondirectory-p (file)