From: Dmitry Gutov Date: Fri, 14 Jan 2022 02:38:39 +0000 (+0200) Subject: xref-find-references-and-replace: New command X-Git-Tag: emacs-29.0.90~3083 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c7bf60465a5c647e3149af705bc727b74d12335f;p=emacs.git xref-find-references-and-replace: New command * lisp/progmodes/xref.el (xref-find-references-and-replace): New command. --- diff --git a/etc/NEWS b/etc/NEWS index 8fd717cfc87..83217a6a947 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -598,6 +598,8 @@ It is bound to 'C-M-,' and jumps to the location where 'xref-go-back' without prefix argument, to make the most common case faster: replacing all matches entirely. +*** New command 'xref-find-references-and-replace'. + ** File notifications +++ diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 06faf16a31a..a1e976cb1cc 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -1478,6 +1478,22 @@ is nil, prompt only if there's no usable symbol at point." (interactive (list (xref--read-identifier "Find references of: "))) (xref--find-xrefs identifier 'references identifier nil)) +(defun xref-find-references-and-replace (from to) + "Replace all references to identifier FROM with TO." + (interactive + (let ((common + (query-replace-read-args "Query replace identifier" nil))) + (list (nth 0 common) (nth 1 common)))) + (require 'xref) + (with-current-buffer + (let ((xref-show-xrefs-function + ;; Some future-proofing (bug#44905). + (custom--standard-value 'xref-show-xrefs-function)) + ;; Disable auto-jumping, it will mess up replacement logic. + xref-auto-jump-to-first-xref) + (xref-find-references from)) + (xref-query-replace-in-results ".*" to))) + ;;;###autoload (defun xref-find-definitions-at-mouse (event) "Find the definition of identifier at or around mouse click.