replace-all-pairs - Replace string pairs in a list of files
n replace-all-pairs "files"
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:-
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.
Copyright (c) 1998-2006 JASSPA
Last Modified: 2002/01/11
Generated On: 2006/10/07