[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master c7bf60465a 2/2: xref-find-references-and-replace: New command
From: |
Dmitry Gutov |
Subject: |
master c7bf60465a 2/2: xref-find-references-and-replace: New command |
Date: |
Thu, 13 Jan 2022 21:40:50 -0500 (EST) |
branch: master
commit c7bf60465a5c647e3149af705bc727b74d12335f
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>
xref-find-references-and-replace: New command
* lisp/progmodes/xref.el (xref-find-references-and-replace):
New command.
---
etc/NEWS | 2 ++
lisp/progmodes/xref.el | 16 ++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 8fd717cfc8..83217a6a94 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 06faf16a31..a1e976cb1c 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.