The commands in this section perform various search and replace operations either on identifiers themselves or on files that reference them.
Find all the references for the identifier at point.
Interactively replace regexp with replacement in the names of all the identifiers shown in the *xref* buffer.
Search for regexp through the files in the selected tags table.
query-replace-regexp on each file in the selected tags table.
Restart one of the last 2 commands above, from the current location of point.
M-? finds all the references for the identifier at point,
prompting for the identifier as needed, with completion. Depending on
the current backend (see Xref), the command may prompt even if it
finds a valid identifier at point. When invoked with a prefix
argument, it always prompts for the identifier. (If you want it to
prompt always, customize the value of the variable
t; or set it to
to prompt only if there’s no usable identifier at point.) The command
then presents the *xref* buffer with all the references to the
identifier, showing the file name and the line where the identifier is
referenced. The XREF mode commands are available in this buffer, see
M-x xref-query-replace-in-results reads a regexp to match identifier names and a replacement string, just like ordinary M-x query-replace-regexp. It then performs the specified replacement in the names of the matching identifiers in all the places in all the files where these identifiers are referenced. This is useful when you rename your identifiers as part of refactoring. This command should be invoked in the *xref* buffer generated by M-?.
M-x tags-search reads a regexp using the minibuffer, then
searches for matches in all the files in the selected tags table, one
file at a time. It displays the name of the file being searched so
you can follow its progress. As soon as it finds an occurrence,
tags-search returns. This command requires tags tables to be
available (see Tags Tables).
Having found one match with
tags-search, you probably want to
find all the rest. M-x fileloop-continue resumes the
tags-search, finding one more match. This searches the rest of
the current buffer, followed by the remaining files of the tags table.
M-x tags-query-replace performs a single
query-replace-regexp through all the files in the tags table. It
reads a regexp to search for and a string to replace with, just like
ordinary M-x query-replace-regexp. It searches much like M-x
tags-search, but repeatedly, processing matches according to your
input. See Query Replace, for more information on query replace.
You can control the case-sensitivity of tags search commands by
customizing the value of the variable
default is to use the same setting as the value of
case-fold-search (see Lax Search).
It is possible to get through all the files in the tags table with a single invocation of M-x tags-query-replace. But often it is useful to exit temporarily, which you can do with any input event that has no special query replace meaning. You can resume the query replace subsequently by typing M-x fileloop-continue; this command resumes the last tags search or replace command that you did. For instance, to skip the rest of the current file, you can type M-> M-x fileloop-continue.
Note that the commands described above carry out much broader
searches than the
xref-find-definitions family. The
xref-find-definitions commands search only for definitions of
identifiers that match your string or regexp. The commands
tags-query-replace find every occurrence of the identifier or
regexp, as ordinary search commands and replace commands do in the
As an alternative to
tags-search, you can run
grep as a subprocess and
have Emacs show you the matching lines one by one. See Grep Searching.