summaryrefslogtreecommitdiff
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorDmitry Gutov <dgutov@yandex.ru>2022-01-14 04:38:39 +0200
committerDmitry Gutov <dgutov@yandex.ru>2022-01-14 04:38:39 +0200
commitc7bf60465a5c647e3149af705bc727b74d12335f (patch)
treea1524849aab9f0fc3a18bb3c5e590610b9517cde /lisp/progmodes
parentb2cc03d572aa4ef591b38e461b0ecb68837cbfc5 (diff)
downloademacs-c7bf60465a5c647e3149af705bc727b74d12335f.tar.gz
emacs-c7bf60465a5c647e3149af705bc727b74d12335f.tar.bz2
emacs-c7bf60465a5c647e3149af705bc727b74d12335f.zip
xref-find-references-and-replace: New command
* lisp/progmodes/xref.el (xref-find-references-and-replace): New command.
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/xref.el16
1 files changed, 16 insertions, 0 deletions
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.