From: Dmitry Gutov Date: Fri, 14 Jan 2022 02:30:16 +0000 (+0200) Subject: Steamline xref-query-replace-in-results X-Git-Tag: emacs-29.0.90~3084 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b2cc03d572aa4ef591b38e461b0ecb68837cbfc5;p=emacs.git Steamline xref-query-replace-in-results * lisp/progmodes/xref.el (xref-query-replace-in-results): Steamline the most common scenario (https://lists.gnu.org/archive/html/emacs-devel/2022-01/msg00864.html). --- diff --git a/etc/NEWS b/etc/NEWS index 06a6886ebf6..8fd717cfc87 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -594,6 +594,10 @@ to enable the display of the buffer list. It is bound to 'C-M-,' and jumps to the location where 'xref-go-back' ('M-,', also known as 'xref-pop-marker-stack') was invoked previously. +*** 'xref-query-replace-in-results' only prompts for TO when called +without prefix argument, to make the most common case faster: +replacing all matches entirely. + ** File notifications +++ diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 9ce63a8f8a1..06faf16a31a 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -738,11 +738,20 @@ quit the *xref* buffer." "Perform interactive replacement of FROM with TO in all displayed xrefs. This command interactively replaces FROM with TO in the names of the -references displayed in the current *xref* buffer." +references displayed in the current *xref* buffer. + +When called interactively, it uses '.*' as FROM, which means +replace the whole name. Unless called with prefix argument, in +which case the user is prompted for both FROM and TO." (interactive - (let ((fr (read-regexp "Xref query-replace (regexp)" ".*"))) - (list fr - (read-regexp (format "Xref query-replace (regexp) %s with: " fr))))) + (let* ((fr + (if prefix-arg + (read-regexp "Query-replace (regexp)" ".*") + ".*")) + (prompt (if prefix-arg + (format "Query-replace (regexp) %s with: " fr) + "Query-replace all matches with: "))) + (list fr (read-regexp prompt)))) (let* (item xrefs iter) (save-excursion (while (setq item (xref--search-property 'xref-item))