231 |
|
|
232 |
Vertical scrolling during incremental search can be enabled by |
Vertical scrolling during incremental search can be enabled by |
233 |
setting the customizable variable @code{isearch-allow-scroll} to a |
setting the customizable variable @code{isearch-allow-scroll} to a |
234 |
non-nil value. |
non-@code{nil} value. |
235 |
|
|
236 |
You can then use the vertical scroll-bar or certain keyboard |
You can then use the vertical scroll-bar or certain keyboard |
237 |
commands such as @kbd{@key{PRIOR}} (@code{scroll-down}), |
commands such as @kbd{@key{PRIOR}} (@code{scroll-down}), |
238 |
@kbd{@key{NEXT}} (@code{scroll-up}) and @kbd{C-l} (@code{recenter}) |
@kbd{@key{NEXT}} (@code{scroll-up}) and @kbd{C-l} (@code{recenter}) |
239 |
within the search, thus letting you see more of the text near the |
within the search, thus letting you see more of the text near the |
240 |
current match. You must run these commands via their key sequences to |
current match. You must run these commands via their key sequences to |
241 |
stay in the search - typing M-x @var{comand-name} will always |
stay in the search---typing M-x @var{comand-name} will always |
242 |
terminate a search. |
terminate a search. |
243 |
|
|
244 |
You can give prefix arguments to these commands in the usual way. |
You can give prefix arguments to these commands in the usual way. |
245 |
The current match cannot be scrolled out of the window - this is |
The current match cannot be scrolled out of the window---this is |
246 |
intentional. |
intentional. |
247 |
|
|
248 |
Several other commands, such as @kbd{C-x 2} |
Several other commands, such as @kbd{C-x 2} |
847 |
@vindex isearch-allow-scroll |
@vindex isearch-allow-scroll |
848 |
|
|
849 |
Scrolling, etc., during incremental search is enabled by setting the |
Scrolling, etc., during incremental search is enabled by setting the |
850 |
customizable variable @code{isearch-allow-scroll} to a non-nil value. |
customizable variable @code{isearch-allow-scroll} to a non-@code{nil} value. |
851 |
|
|
852 |
@c See Subject: Info file: How do I get an itemized list without blank lines? |
@c See Subject: Info file: How do I get an itemized list without blank lines? |
853 |
@c Date: Sat, 12 Apr 2003 09:45:31 +0000 in gnu.emacs.help |
@c Date: Sat, 12 Apr 2003 09:45:31 +0000 in gnu.emacs.help |
893 |
|
|
894 |
You should only thus configure commands which are ``safe'': i.e., they |
You should only thus configure commands which are ``safe'': i.e., they |
895 |
won't leave emacs in an inconsistent state when executed within a |
won't leave emacs in an inconsistent state when executed within a |
896 |
search - that is to say, the following things may be changed by a |
search---that is to say, the following things may be changed by a |
897 |
command only temporarily, and must be restored before the command |
command only temporarily, and must be restored before the command |
898 |
finishes: |
finishes: |
899 |
|
|
913 |
window's size, or create or delete other windows and frames. |
window's size, or create or delete other windows and frames. |
914 |
|
|
915 |
Note that an attempt by a command to scroll the text |
Note that an attempt by a command to scroll the text |
916 |
@emph{horizontally} won't work, although it will do no harm - any such |
@emph{horizontally} won't work, although it will do no harm---any such |
917 |
scrolling will be overriden and nullified by the display code. |
scrolling will be overriden and nullified by the display code. |
918 |
|
|
919 |
@node Replace, Other Repeating Search, Configuring Scrolling, Search |
@node Replace, Other Repeating Search, Configuring Scrolling, Search |
977 |
What if you want to exchange @samp{x} and @samp{y}: replace every @samp{x} with a @samp{y} and vice versa? You can do it this way: |
What if you want to exchange @samp{x} and @samp{y}: replace every @samp{x} with a @samp{y} and vice versa? You can do it this way: |
978 |
|
|
979 |
@example |
@example |
980 |
M-x query-replace @key{RET} x @key{RET} @@TEMP@@ @key{RET} |
M-x replace-string @key{RET} x @key{RET} @@TEMP@@ @key{RET} |
981 |
M-x query-replace @key{RET} y @key{RET} x @key{RET} |
M-< M-x replace-string @key{RET} y @key{RET} x @key{RET} |
982 |
M-x query-replace @key{RET} @@TEMP@@ @key{RET} y @key{RET} |
M-< M-x replace-string @key{RET} @@TEMP@@ @key{RET} y @key{RET} |
983 |
@end example |
@end example |
984 |
|
|
985 |
@noindent |
@noindent |
993 |
single string. The similar command @kbd{M-x replace-regexp} replaces |
single string. The similar command @kbd{M-x replace-regexp} replaces |
994 |
any match for a specified pattern. |
any match for a specified pattern. |
995 |
|
|
996 |
In @code{replace-regexp}, the @var{newstring} need not be constant: it |
In @code{replace-regexp}, the @var{newstring} need not be constant: |
997 |
can refer to all or part of what is matched by the @var{regexp}. |
it can refer to all or part of what is matched by the @var{regexp}. |
998 |
@samp{\&} in @var{newstring} stands for the entire match being replaced. |
@samp{\&} in @var{newstring} stands for the entire match being |
999 |
@samp{\@var{d}} in @var{newstring}, where @var{d} is a digit, stands for |
replaced. @samp{\@var{d}} in @var{newstring}, where @var{d} is a |
1000 |
whatever matched the @var{d}th parenthesized grouping in @var{regexp}. |
digit, stands for whatever matched the @var{d}th parenthesized |
1001 |
To include a @samp{\} in the text to replace with, you must enter |
grouping in @var{regexp}. @samp{\#} refers to the count of |
1002 |
@samp{\\}. For example, |
replacements already made in this command, as a decimal number. In |
1003 |
|
the first replacement, @samp{\#} stands for @samp{0}; in the second, |
1004 |
|
for @samp{1}; and so on. For example, |
1005 |
|
|
1006 |
@example |
@example |
1007 |
M-x replace-regexp @key{RET} c[ad]+r @key{RET} \&-safe @key{RET} |
M-x replace-regexp @key{RET} c[ad]+r @key{RET} \&-safe @key{RET} |
1016 |
@end example |
@end example |
1017 |
|
|
1018 |
@noindent |
@noindent |
1019 |
performs the inverse transformation. |
performs the inverse transformation. To include a @samp{\} in the |
1020 |
|
text to replace with, you must enter @samp{\\}. |
1021 |
|
|
1022 |
|
You can also use Lisp expressions to calculate parts of the |
1023 |
|
replacement string. To do this, write @samp{\,} followed by the |
1024 |
|
expression in the replacement string. Each replacement calculates the |
1025 |
|
value of the expression, which ought to be a string, and uses it in |
1026 |
|
the replacement string in place of the expression itself. If the |
1027 |
|
expression is a symbol, one space in the replacement string after the |
1028 |
|
symbol name counts as part of the symbol name, so the value replaces |
1029 |
|
them both. |
1030 |
|
|
1031 |
|
Inside such an expression, @samp{\&} and @samp{\@var{n}} used as |
1032 |
|
subexpressions refer respectively to the entire match as a string, and |
1033 |
|
to a submatch as a string. @var{n} may exceed 9 here, and the value |
1034 |
|
of @samp{\@var{n}} is @code{nil} if subexpression @var{n} did not |
1035 |
|
match. You can also use @samp{\#&} and @samp{\#@var{n}} refer to |
1036 |
|
those matches converted to numbers (this is valid when the match or |
1037 |
|
submatch has the form of a number). @samp{\#} stands for the number |
1038 |
|
of already-completed replacements. |
1039 |
|
|
1040 |
|
Repeating our example to exchange @samp{x} and @samp{y}, we can thus |
1041 |
|
do it also this way: |
1042 |
|
|
1043 |
|
@example |
1044 |
|
M-x replace-regexp @key{RET} \(x\)\|y @key{RET} |
1045 |
|
\,(if \1 "y" "x") @key{RET} |
1046 |
|
@end example |
1047 |
|
|
1048 |
|
The @code{format} function (@pxref{Formatting Strings,,,elisp, GNU |
1049 |
|
Emacs Lisp Reference Manual}) comes in handy for computing replacement |
1050 |
|
strings for @samp{\,}. For example, to add consecutively numbered |
1051 |
|
strings like @samp{ABC00042} to columns 73 @w{to 80} (unless they are |
1052 |
|
already occupied), you can use |
1053 |
|
|
1054 |
|
@example |
1055 |
|
M-x replace-regexp @key{RET} ^.\@{0,72\@}$ @key{RET} |
1056 |
|
\,(format "%-72sABC%05d" \& \#) @key{RET} |
1057 |
|
@end example |
1058 |
|
|
1059 |
|
If you want to enter part of the replacement string by hand each |
1060 |
|
time, use @samp{\?} in the replacement string. Each replacement will |
1061 |
|
enter a recursive edit, with point at the position where the @samp{\?} |
1062 |
|
was. For example, |
1063 |
|
|
1064 |
|
@example |
1065 |
|
M-x replace-regexp @key{RET} \footnote@{ @key{RET} |
1066 |
|
\&\\label@{fn:\#\?@} @key{RET} |
1067 |
|
@end example |
1068 |
|
|
1069 |
|
@noindent |
1070 |
|
will add labels starting with @samp{\label@{fn:0@}} to occurences of |
1071 |
|
@samp{\footnote@{}, but letting you edit each replacement before |
1072 |
|
performing it. To number the labels starting at 1, use @samp{\,(1+ |
1073 |
|
\#)} instead of @samp{\#}. |
1074 |
|
|
1075 |
@node Replacement and Case, Query Replace, Regexp Replace, Replace |
@node Replacement and Case, Query Replace, Regexp Replace, Replace |
1076 |
@subsection Replace Commands and Case |
@subsection Replace Commands and Case |
1182 |
|
|
1183 |
@item ^ |
@item ^ |
1184 |
to go back to the position of the previous occurrence (or what used to |
to go back to the position of the previous occurrence (or what used to |
1185 |
be an occurrence), in case you changed it by mistake. This works by |
be an occurrence), in case you changed it by mistake or want to |
1186 |
popping the mark ring. Only one @kbd{^} in a row is meaningful, because |
reexamine it. |
|
only one previous replacement position is kept during @code{query-replace}. |
|
1187 |
|
|
1188 |
@item C-r |
@item C-r |
1189 |
to enter a recursive editing level, in case the occurrence needs to be |
to enter a recursive editing level, in case the occurrence needs to be |