comparison man/search.texi @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 375f2633d815
children 4c90ffeb71c5
comparison
equal deleted inserted replaced
89908:ee1402f7b568 89909:68c22ea6027c
17 occurrences of one string and replaces them with another, Emacs has a 17 occurrences of one string and replaces them with another, Emacs has a
18 more flexible replacement command called @code{query-replace}, which 18 more flexible replacement command called @code{query-replace}, which
19 asks interactively which occurrences to replace. 19 asks interactively which occurrences to replace.
20 20
21 @menu 21 @menu
22 * Incremental Search:: Search happens as you type the string. 22 * Incremental Search:: Search happens as you type the string.
23 * Nonincremental Search:: Specify entire string and then search. 23 * Nonincremental Search:: Specify entire string and then search.
24 * Word Search:: Search for sequence of words. 24 * Word Search:: Search for sequence of words.
25 * Regexp Search:: Search for match for a regexp. 25 * Regexp Search:: Search for match for a regexp.
26 * Regexps:: Syntax of regular expressions. 26 * Regexps:: Syntax of regular expressions.
27 * Search Case:: To ignore case while searching, or not. 27 * Search Case:: To ignore case while searching, or not.
28 * Replace:: Search, and replace some or all matches. 28 * Configuring Scrolling:: Scrolling within incremental search.
29 * Other Repeating Search:: Operating on all matches for some regexp. 29 * Replace:: Search, and replace some or all matches.
30 * Other Repeating Search:: Operating on all matches for some regexp.
30 @end menu 31 @end menu
31 32
32 @node Incremental Search, Nonincremental Search, Search, Search 33 @node Incremental Search, Nonincremental Search, Search, Search
33 @section Incremental Search 34 @section Incremental Search
34 35
120 to its use for insertion (@pxref{Inserting Text}): it causes the 121 to its use for insertion (@pxref{Inserting Text}): it causes the
121 following character to be treated the way any ``ordinary'' character is 122 following character to be treated the way any ``ordinary'' character is
122 treated in the same context. You can also specify a character by its 123 treated in the same context. You can also specify a character by its
123 octal code: enter @kbd{C-q} followed by a sequence of octal digits. 124 octal code: enter @kbd{C-q} followed by a sequence of octal digits.
124 125
125 @cindex searching for non-ASCII characters 126 @cindex searching for non-@acronym{ASCII} characters
126 @cindex input method, during incremental search 127 @cindex input method, during incremental search
127 To search for non-ASCII characters, you must use an input method 128 To search for non-@acronym{ASCII} characters, you must use an input method
128 (@pxref{Input Methods}). If an input method is enabled in the 129 (@pxref{Input Methods}). If an input method is enabled in the
129 current buffer when you start the search, you can use it while you 130 current buffer when you start the search, you can use it while you
130 type the search string also. Emacs indicates that by including the 131 type the search string also. Emacs indicates that by including the
131 input method mnemonic in its prompt, like this: 132 input method mnemonic in its prompt, like this:
132 133
223 @vindex isearch-mode-map 224 @vindex isearch-mode-map
224 To customize the special characters that incremental search understands, 225 To customize the special characters that incremental search understands,
225 alter their bindings in the keymap @code{isearch-mode-map}. For a list 226 alter their bindings in the keymap @code{isearch-mode-map}. For a list
226 of bindings, look at the documentation of @code{isearch-mode} with 227 of bindings, look at the documentation of @code{isearch-mode} with
227 @kbd{C-h f isearch-mode @key{RET}}. 228 @kbd{C-h f isearch-mode @key{RET}}.
229
230 @subsection Scrolling During Incremental Search
231
232 Vertical scrolling during incremental search can be enabled by
233 setting the customizable variable @code{isearch-allow-scroll} to a
234 non-nil value.
235
236 You can then use the vertical scroll-bar or certain keyboard
237 commands such as @kbd{@key{PRIOR}} (@code{scroll-down}),
238 @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
240 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
242 terminate a search.
243
244 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
246 intentional.
247
248 Several other commands, such as @kbd{C-x 2}
249 (@code{split-window-vertically}) and @kbd{C-x ^}
250 (@code{enlarge-window}) which don't scroll the window, are
251 nevertheless made available under this rubric, since they are likewise
252 handy during a search.
253
254 For a list of commands which are configured as scrolling commands by
255 default and instructions on how thus to configure other commands, see
256 @ref{Configuring Scrolling}.
228 257
229 @subsection Slow Terminal Incremental Search 258 @subsection Slow Terminal Incremental Search
230 259
231 Incremental search on a slow terminal uses a modified style of display 260 Incremental search on a slow terminal uses a modified style of display
232 that is designed to take less time. Instead of redisplaying the buffer at 261 that is designed to take less time. Instead of redisplaying the buffer at
503 (including the empty string), from which it follows that @samp{c[ad]*r} 532 (including the empty string), from which it follows that @samp{c[ad]*r}
504 matches @samp{cr}, @samp{car}, @samp{cdr}, @samp{caddaar}, etc. 533 matches @samp{cr}, @samp{car}, @samp{cdr}, @samp{caddaar}, etc.
505 534
506 You can also include character ranges in a character set, by writing the 535 You can also include character ranges in a character set, by writing the
507 starting and ending characters with a @samp{-} between them. Thus, 536 starting and ending characters with a @samp{-} between them. Thus,
508 @samp{[a-z]} matches any lower-case ASCII letter. Ranges may be 537 @samp{[a-z]} matches any lower-case @acronym{ASCII} letter. Ranges may be
509 intermixed freely with individual characters, as in @samp{[a-z$%.]}, 538 intermixed freely with individual characters, as in @samp{[a-z$%.]},
510 which matches any lower-case ASCII letter or @samp{$}, @samp{%} or 539 which matches any lower-case @acronym{ASCII} letter or @samp{$}, @samp{%} or
511 period. 540 period.
512 541
513 Note that the usual regexp special characters are not special inside a 542 Note that the usual regexp special characters are not special inside a
514 character set. A completely different set of special characters exists 543 character set. A completely different set of special characters exists
515 inside character sets: @samp{]}, @samp{-} and @samp{^}. 544 inside character sets: @samp{]}, @samp{-} and @samp{^}.
529 is somewhat ill-defined, and it may change in future Emacs versions. 558 is somewhat ill-defined, and it may change in future Emacs versions.
530 559
531 @item @kbd{[^ @dots{} ]} 560 @item @kbd{[^ @dots{} ]}
532 @samp{[^} begins a @dfn{complemented character set}, which matches any 561 @samp{[^} begins a @dfn{complemented character set}, which matches any
533 character except the ones specified. Thus, @samp{[^a-z0-9A-Z]} matches 562 character except the ones specified. Thus, @samp{[^a-z0-9A-Z]} matches
534 all characters @emph{except} ASCII letters and digits. 563 all characters @emph{except} @acronym{ASCII} letters and digits.
535 564
536 @samp{^} is not special in a character set unless it is the first 565 @samp{^} is not special in a character set unless it is the first
537 character. The character following the @samp{^} is treated as if it 566 character. The character following the @samp{^} is treated as if it
538 were first (in other words, @samp{-} and @samp{]} are not special there). 567 were first (in other words, @samp{-} and @samp{]} are not special there).
539 568
545 is a special character that matches the empty string, but only at the 574 is a special character that matches the empty string, but only at the
546 beginning of a line in the text being matched. Otherwise it fails to 575 beginning of a line in the text being matched. Otherwise it fails to
547 match anything. Thus, @samp{^foo} matches a @samp{foo} that occurs at 576 match anything. Thus, @samp{^foo} matches a @samp{foo} that occurs at
548 the beginning of a line. 577 the beginning of a line.
549 578
579 For historical compatibility reasons, @samp{^} can be used with this
580 meaning only at the beginning of the regular expression, or after
581 @samp{\(} or @samp{\|}.
582
550 @item @kbd{$} 583 @item @kbd{$}
551 is similar to @samp{^} but matches only at the end of a line. Thus, 584 is similar to @samp{^} but matches only at the end of a line. Thus,
552 @samp{x+$} matches a string of one @samp{x} or more at the end of a line. 585 @samp{x+$} matches a string of one @samp{x} or more at the end of a line.
586
587 For historical compatibility reasons, @samp{$} can be used with this
588 meaning only at the end of the regular expression, or before @samp{\)}
589 or @samp{\|}.
553 590
554 @item @kbd{\} 591 @item @kbd{\}
555 has two functions: it quotes the special characters (including 592 has two functions: it quotes the special characters (including
556 @samp{\}), and it introduces additional special constructs. 593 @samp{\}), and it introduces additional special constructs.
557 594
760 verify even very complex regexps. (On displays that don't support 797 verify even very complex regexps. (On displays that don't support
761 colors, Emacs blinks the cursor around the matched text, as it does 798 colors, Emacs blinks the cursor around the matched text, as it does
762 for matching parens.) 799 for matching parens.)
763 @end ignore 800 @end ignore
764 801
765 @node Search Case, Replace, Regexps, Search 802 @node Search Case, Configuring Scrolling, Regexps, Search
766 @section Searching and Case 803 @section Searching and Case
767 804
768 Incremental searches in Emacs normally ignore the case of the text 805 Incremental searches in Emacs normally ignore the case of the text
769 they are searching through, if you specify the text in lower case. 806 they are searching through, if you specify the text in lower case.
770 Thus, if you specify searching for @samp{foo}, then @samp{Foo} and 807 Thus, if you specify searching for @samp{foo}, then @samp{Foo} and
790 there is a default value which you can change as well. @xref{Locals}. 827 there is a default value which you can change as well. @xref{Locals}.
791 This variable applies to nonincremental searches also, including those 828 This variable applies to nonincremental searches also, including those
792 performed by the replace commands (@pxref{Replace}) and the minibuffer 829 performed by the replace commands (@pxref{Replace}) and the minibuffer
793 history matching commands (@pxref{Minibuffer History}). 830 history matching commands (@pxref{Minibuffer History}).
794 831
795 @node Replace, Other Repeating Search, Search Case, Search 832 @node Configuring Scrolling, Replace, Search Case, Search
833 @section Configuring Scrolling
834 @cindex scrolling in incremental search
835 @vindex isearch-allow-scroll
836
837 Scrolling, etc., during incremental search is enabled by setting the
838 customizable variable @code{isearch-allow-scroll} to a non-nil value.
839
840 @c See Subject: Info file: How do I get an itemized list without blank lines?
841 @c Date: Sat, 12 Apr 2003 09:45:31 +0000 in gnu.emacs.help
842 @subsection Standard scrolling commands
843 Here is the list of commands which are configured by default to be
844 ``scrolling'' commands in an incremental search, together with their
845 usual bindings:
846 @subsubsection Commands which scroll the window:
847 @table @asis
848 @item @code{scroll-bar-toolkit-scroll} (@kbd{@key{vertical-scroll-bar}@key{mouse-1}} in X-Windows)
849 @itemx @code{mac-handle-scroll-bar-event} (@kbd{@key{vertical-scroll-bar}@key{mouse-1}} on a Mac)
850 @itemx @code{w32-handle-scroll-bar-event} (@kbd{@key{vertical-scroll-bar}@key{mouse-1}} in MS-Windows)
851 @item @code{recenter} (@kbd{C-l}) @xref{Scrolling}.
852 @itemx @code{reposition-window} (@kbd{C-M-l}) @xref{Scrolling}.
853 @itemx @code{scroll-up} (@kbd{@key{NEXT}}) @xref{Scrolling}.
854 @itemx @code{scroll-down} (@kbd{@key{PRIOR}}) @xref{Scrolling}.
855 @end table
856
857 @subsubsection Commands which act on the other window:
858 @table @asis
859 @item @code{list-buffers} (@kbd{C-x C-b}) @xref{List Buffers}.
860 @itemx @code{scroll-other-window} (@kbd{C-M-v}) @xref{Other Window}.
861 @itemx @code{scroll-other-window-down} (@kbd{C-M-S-v}) @xref{Other Window}.
862 @itemx @code{beginning-of-buffer-other-window} (@kbd{M-@key{home}})
863 @itemx @code{end-of-buffer-other-window} (@kbd{M-@key{end}})
864 @end table
865
866 @subsubsection Commands which change the window layout:
867 @table @asis
868 @item @code{delete-other-windows} (@kbd{C-x 1}) @xref{Change Window}.
869 @itemx @code{balance-windows} (@kbd{C-x +}) @xref{Change Window}.
870 @itemx @code{split-window-vertically} (@kbd{C-x 2}) @xref{Split Window}.
871 @itemx @code{enlarge-window} (@kbd{C-x ^}) @xref{Change Window}.
872 @end table
873
874 @subsection Configuring other commands as scrolling commands
875 To do this, set a command's isearch-scroll property to the value t.
876 For example:
877
878 @example
879 @code{(put 'my-command 'isearch-scroll t)}
880 @end example
881
882 You should only thus configure commands which are ``safe'': i.e., they
883 won't leave emacs in an inconsistent state when executed within a
884 search - that is to say, the following things may be changed by a
885 command only temporarily, and must be restored before the command
886 finishes:
887
888 @enumerate
889 @item
890 Point.
891 @item
892 The buffer contents.
893 @item
894 The selected window and selected frame.
895 @item
896 The current match-data @xref{Match Data,,,elisp}.
897 @end enumerate
898
899 Additionally, the command must not delete the current window and must
900 not itself attempt an incremental search. It may, however, change the
901 window's size, or create or delete other windows and frames.
902
903 Note that an attempt by a command to scroll the text
904 @emph{horizontally} won't work, although it will do no harm - any such
905 scrolling will be overriden and nullified by the display code.
906
907 @node Replace, Other Repeating Search, Configuring Scrolling, Search
796 @section Replacement Commands 908 @section Replacement Commands
797 @cindex replacement 909 @cindex replacement
798 @cindex search-and-replace commands 910 @cindex search-and-replace commands
799 @cindex string substitution 911 @cindex string substitution
800 @cindex global substitution 912 @cindex global substitution
812 replacement string. It is possible to perform several replacements in 924 replacement string. It is possible to perform several replacements in
813 parallel using the command @code{expand-region-abbrevs} 925 parallel using the command @code{expand-region-abbrevs}
814 (@pxref{Expanding Abbrevs}). 926 (@pxref{Expanding Abbrevs}).
815 927
816 @menu 928 @menu
817 * Unconditional Replace:: Replacing all matches for a string. 929 * Unconditional Replace:: Replacing all matches for a string.
818 * Regexp Replace:: Replacing all matches for a regexp. 930 * Regexp Replace:: Replacing all matches for a regexp.
819 * Replacement and Case:: How replacements preserve case of letters. 931 * Replacement and Case:: How replacements preserve case of letters.
820 * Query Replace:: How to use querying. 932 * Query Replace:: How to use querying.
821 @end menu 933 @end menu
822 934
823 @node Unconditional Replace, Regexp Replace, Replace, Replace 935 @node Unconditional Replace, Regexp Replace, Replace, Replace
824 @subsection Unconditional Replacement 936 @subsection Unconditional Replacement
825 @findex replace-string 937 @findex replace-string
1119 1231
1120 You can also search multiple files under control of a tags table 1232 You can also search multiple files under control of a tags table
1121 (@pxref{Tags Search}) or through Dired @kbd{A} command 1233 (@pxref{Tags Search}) or through Dired @kbd{A} command
1122 (@pxref{Operating on Files}), or ask the @code{grep} program to do it 1234 (@pxref{Operating on Files}), or ask the @code{grep} program to do it
1123 (@pxref{Grep Searching}). 1235 (@pxref{Grep Searching}).
1236
1237 @ignore
1238 arch-tag: fd9d8e77-66af-491c-b212-d80999613e3e
1239 @end ignore