# replace-all-pairs(3)

[Home] [Commands] [Variables] [Macro-Dev] [Glossary]

## NAME

replace-all-pairs - Replace string pairs in a list of files

## SYNOPSIS

n replace-all-pairs "files"

## DESCRIPTION

replace-all-pairs uses the current buffer to extract "from" and "to" pairs and then replaces all occurrences of "from" to "to" in the given list of files without prompting the user. An optional third argument "grep" can be given which will be used as the grep string, if not given the "from" string is used. The format of the current buffer must be:

    /from1/to1/
    Xfrom2Xto2X
    ?from3?to3?
    /from4/to4/grep4/
      .
      .
    /fromN/toN/

For each pair the command finds all occurrences of "from" (or "grep" if specified) by calling the command grep(3) to search for string "from" in files "files". Thus all relevant edited files must be saved or grep may return the wrong line numbers. This is achieved by a call to save-some-buffers(2) between each replace pair, it is called with an argument of 0 to ensure that any changed buffers are automatically saved.

Each occurrence of "from" is jumped to using get-next-line(2) and the string is replaced by the call:

    -1 replace-string "from" "to"

This replaces all occurrences of "from" to "to" on the current line only, hence the line numbers must be correct. This also means that the "from" search string must be correctly formatted for both grep and replace-string.

The given argument n is a bit based flag which changes the default behavior described above. The bits have the following effect:-

0x01

Prompt before saving any changed buffers FIRST time ONLY, enabled by default. If set then the user is also prompted to continue before any changes are made. If this bit is not set then the command executes without any user input.

## NOTES

replace-all-pairs is a macro defined in `search.emf`.

The grep command must be working before this command can function properly.

It is not recommended to use a "from" or "to" string which uses more that one line as the results may be unpredictable.

As the change is likely to be several pair strings with each changed buffer being saved between pairs undo(2) cannot be used to undo the changes. Neither can the backups be relied on as a buffer may be saved more than once in this process, therefore it is strongly recommend that a backup of the files is made before commencing with this command.

## SEE ALSO

replace-all-string(3), replace-string(2), save-some-buffers(2), grep(3), get-next-line(2), undo(2), query-replace-all-string(3), search-forward(2).
Regular Expressions

(c) Copyright JASSPA 2009
Last Modified: 2009/08/29
Generated On: 2009/10/12

</HMTL>