xref-find-references-and-replace: New command

* lisp/progmodes/xref.el (xref-find-references-and-replace):
New command.
This commit is contained in:
Dmitry Gutov 2022-01-14 04:38:39 +02:00
parent b2cc03d572
commit c7bf60465a
2 changed files with 18 additions and 0 deletions

View file

@ -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
+++

View file

@ -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.