comparison man/search.texi @ 64148:a77d510ff94d

(Isearch Scroll): Add example of using the `isearch-scroll' property. (Slow Isearch): Reference anchor for `baud-rate' instead of entire `Display Custom' node. (Regexp Replace): Put text that requires Emacs Lisp knowledge last and de-emphasize it. (Other Repeating Search): `occur' currently can not correctly handle multiline matches. Correct, clarify and update description of `flush-lines' and `keep-lines'.
author Luc Teirlinck <teirllm@auburn.edu>
date Thu, 07 Jul 2005 23:09:00 +0000
parents ce18be094148
children 3723093a21fd fbb2bea03df9
comparison
equal deleted inserted replaced
64147:ccaefd0abbe5 64148:a77d510ff94d
292 You can then use the vertical scroll-bar or certain keyboard 292 You can then use the vertical scroll-bar or certain keyboard
293 commands such as @kbd{@key{PRIOR}} (@code{scroll-down}), 293 commands such as @kbd{@key{PRIOR}} (@code{scroll-down}),
294 @kbd{@key{NEXT}} (@code{scroll-up}) and @kbd{C-l} (@code{recenter}) 294 @kbd{@key{NEXT}} (@code{scroll-up}) and @kbd{C-l} (@code{recenter})
295 within the search, thus letting you see more of the text near the 295 within the search, thus letting you see more of the text near the
296 current match. You must run these commands via their key sequences to 296 current match. You must run these commands via their key sequences to
297 stay in the search---typing M-x @var{comand-name} will always 297 stay in the search---typing M-x @var{command-name} will always
298 terminate a search. 298 terminate a search.
299 299
300 You can give prefix arguments to these commands in the usual way. 300 You can give prefix arguments to these commands in the usual way.
301 The current match cannot be scrolled out of the window---this is 301 The current match cannot be scrolled out of the window---this is
302 intentional. 302 intentional.
307 nevertheless made available under this rubric, since they are likewise 307 nevertheless made available under this rubric, since they are likewise
308 handy during a search. 308 handy during a search.
309 309
310 You can make other commands usable within an incremental search by 310 You can make other commands usable within an incremental search by
311 giving the command a non-@code{nil} @code{isearch-scroll} property. 311 giving the command a non-@code{nil} @code{isearch-scroll} property.
312 For example, to make @kbd{C-h l} usable within an incremental search
313 in all future Emacs sessions, use @kbd{C-h c} to find what command it
314 runs. (You type @kbd{C-h c C-h l}; it says @code{view-lossage}.) Then
315 you can put the following line in your @file{.emacs} file (@pxref{Init File}):
316
317 @example
318 (put 'view-lossage 'isearch-scroll t)
319 @end example
320
321 @noindent
312 This works for commands that don't permanently change point, the 322 This works for commands that don't permanently change point, the
313 buffer contents, the match data, the current buffer, or the selected 323 buffer contents, the match data, the current buffer, or the selected
314 window and frame. The command must not delete the current window and 324 window and frame. The command must not delete the current window and
315 must not itself attempt an incremental search. 325 must not itself attempt an incremental search.
316 326
329 its new position of point. 339 its new position of point.
330 340
331 @vindex search-slow-speed 341 @vindex search-slow-speed
332 The slow terminal style of display is used when the terminal baud rate is 342 The slow terminal style of display is used when the terminal baud rate is
333 less than or equal to the value of the variable @code{search-slow-speed}, 343 less than or equal to the value of the variable @code{search-slow-speed},
334 initially 1200. See @code{baud-rate} in @ref{Display Custom}. 344 initially 1200. See also the discussion of the variable @code{baud-rate}
345 (@pxref{baud-rate,, Customization of Display}).
335 346
336 @vindex search-slow-window-lines 347 @vindex search-slow-window-lines
337 The number of lines to use in slow terminal search display is controlled 348 The number of lines to use in slow terminal search display is controlled
338 by the variable @code{search-slow-window-lines}. Its normal value is 1. 349 by the variable @code{search-slow-window-lines}. Its normal value is 1.
339 350
1010 1021
1011 @noindent 1022 @noindent
1012 performs the inverse transformation. To include a @samp{\} in the 1023 performs the inverse transformation. To include a @samp{\} in the
1013 text to replace with, you must enter @samp{\\}. 1024 text to replace with, you must enter @samp{\\}.
1014 1025
1015 You can also use Lisp expressions to calculate parts of the 1026 If you want to enter part of the replacement string by hand each
1027 time, use @samp{\?} in the replacement string. Each replacement will
1028 ask you to edit the replacement string in the minibuffer, putting
1029 point where the @samp{\?} was.
1030
1031 The remainder of this subsection is intended for specialized tasks
1032 and requires knowledge of Lisp. Most readers can skip it.
1033
1034 You can use Lisp expressions to calculate parts of the
1016 replacement string. To do this, write @samp{\,} followed by the 1035 replacement string. To do this, write @samp{\,} followed by the
1017 expression in the replacement string. Each replacement calculates the 1036 expression in the replacement string. Each replacement calculates the
1018 value of the expression and converts it to text without quoting (if 1037 value of the expression and converts it to text without quoting (if
1019 it's a string, this means using the string's contents), and uses it in 1038 it's a string, this means using the string's contents), and uses it in
1020 the replacement string in place of the expression itself. If the 1039 the replacement string in place of the expression itself. If the
1047 1066
1048 @example 1067 @example
1049 M-x replace-regexp @key{RET} ^.\@{0,72\@}$ @key{RET} 1068 M-x replace-regexp @key{RET} ^.\@{0,72\@}$ @key{RET}
1050 \,(format "%-72sABC%05d" \& \#) @key{RET} 1069 \,(format "%-72sABC%05d" \& \#) @key{RET}
1051 @end example 1070 @end example
1052
1053 If you want to enter part of the replacement string by hand each
1054 time, use @samp{\?} in the replacement string. Each replacement will
1055 ask you to edit the replacement string in the minibuffer, putting
1056 point where the @samp{\?} was. For example,
1057
1058 @example
1059 M-x replace-regexp @key{RET} \\footnote@{ @key{RET}
1060 \&\\label@{fn:\#\?@} @key{RET}
1061 @end example
1062
1063 @noindent
1064 will add labels starting with @samp{\label@{fn:0@}} to occurrences of
1065 @samp{\footnote@{}, but letting you edit each replacement before
1066 performing it. To number the labels starting at 1, use @samp{\,(1+
1067 \#)} instead of @samp{\#}.
1068 1071
1069 @node Replacement and Case, Query Replace, Regexp Replace, Replace 1072 @node Replacement and Case, Query Replace, Regexp Replace, Replace
1070 @subsection Replace Commands and Case 1073 @subsection Replace Commands and Case
1071 1074
1072 If the first argument of a replace command is all lower case, the 1075 If the first argument of a replace command is all lower case, the
1255 @item M-x occur @key{RET} @var{regexp} @key{RET} 1258 @item M-x occur @key{RET} @var{regexp} @key{RET}
1256 Display a list showing each line in the buffer that contains a match 1259 Display a list showing each line in the buffer that contains a match
1257 for @var{regexp}. To limit the search to part of the buffer, narrow 1260 for @var{regexp}. To limit the search to part of the buffer, narrow
1258 to that part (@pxref{Narrowing}). A numeric argument @var{n} 1261 to that part (@pxref{Narrowing}). A numeric argument @var{n}
1259 specifies that @var{n} lines of context are to be displayed before and 1262 specifies that @var{n} lines of context are to be displayed before and
1260 after each matching line. 1263 after each matching line. Currently, @code{occur} can not correctly
1264 handle multiline matches.
1261 1265
1262 @kindex RET @r{(Occur mode)} 1266 @kindex RET @r{(Occur mode)}
1263 @kindex o @r{(Occur mode)} 1267 @kindex o @r{(Occur mode)}
1264 @kindex C-o @r{(Occur mode)} 1268 @kindex C-o @r{(Occur mode)}
1265 The buffer @samp{*Occur*} containing the output serves as a menu for 1269 The buffer @samp{*Occur*} containing the output serves as a menu for
1269 searched and moves point to the original of the chosen occurrence. 1273 searched and moves point to the original of the chosen occurrence.
1270 @kbd{o} and @kbd{C-o} display the match in another window; @kbd{C-o} 1274 @kbd{o} and @kbd{C-o} display the match in another window; @kbd{C-o}
1271 does not select it. 1275 does not select it.
1272 1276
1273 Occur mode supports the @code{next-error} functionality described in 1277 Occur mode supports the @code{next-error} functionality described in
1274 in @ref{Compilation Mode}. 1278 @ref{Compilation Mode}.
1275 1279
1276 @item M-x list-matching-lines 1280 @item M-x list-matching-lines
1277 Synonym for @kbd{M-x occur}. 1281 Synonym for @kbd{M-x occur}.
1278 1282
1279 @item M-x multi-occur @key{RET} @var{buffers} @key{RET} @var{regexp} @key{RET} 1283 @item M-x multi-occur @key{RET} @var{buffers} @key{RET} @var{regexp} @key{RET}
1288 Print the number of matches for @var{regexp} that exist in the buffer 1292 Print the number of matches for @var{regexp} that exist in the buffer
1289 after point. In Transient Mark mode, if the region is active, the 1293 after point. In Transient Mark mode, if the region is active, the
1290 command operates on the region instead. 1294 command operates on the region instead.
1291 1295
1292 @item M-x flush-lines @key{RET} @var{regexp} @key{RET} 1296 @item M-x flush-lines @key{RET} @var{regexp} @key{RET}
1293 Delete each line that contains a match for @var{regexp}, operating on 1297 This command deletes each line that contains a match for @var{regexp},
1294 the text after point. In Transient Mark mode, if the region is 1298 operating on the text after point; it deletes the current line
1295 active, the command operates on the region instead. 1299 if it contains a match starting after point. In Transient Mark mode,
1300 if the region is active, the command operates on the region instead;
1301 it deletes a line partially contained in the region if it contains a
1302 match entirely contained in the region.
1303
1304 If a match is split across lines, @code{flush-lines} deletes all those
1305 lines. It deletes the lines before starting to look for the next
1306 match; hence, it ignores a match starting on the same line at which
1307 another match ended.
1296 1308
1297 @item M-x keep-lines @key{RET} @var{regexp} @key{RET} 1309 @item M-x keep-lines @key{RET} @var{regexp} @key{RET}
1298 Delete each line that @emph{does not} contain a match for 1310 This command deletes each line that @emph{does not} contain a match for
1299 @var{regexp}, operating on the text after point. In Transient Mark 1311 @var{regexp}, operating on the text after point; if point is not at the
1300 mode, if the region is active, the command operates on the region 1312 beginning of a line, it always keeps the current line. In Transient
1301 instead. 1313 Mark mode, if the region is active, the command operates on the region
1314 instead; it never deletes lines that are only partially contained in
1315 the region (a newline that ends a line counts as part of that line).
1316
1317 If a match is split across lines, this command keeps all those lines.
1302 @end table 1318 @end table
1303 1319
1304 You can also search multiple files under control of a tags table 1320 You can also search multiple files under control of a tags table
1305 (@pxref{Tags Search}) or through Dired @kbd{A} command 1321 (@pxref{Tags Search}) or through the Dired @kbd{A} command
1306 (@pxref{Operating on Files}), or ask the @code{grep} program to do it 1322 (@pxref{Operating on Files}), or ask the @code{grep} program to do it
1307 (@pxref{Grep Searching}). 1323 (@pxref{Grep Searching}).
1308 1324
1309 @ignore 1325 @ignore
1310 arch-tag: fd9d8e77-66af-491c-b212-d80999613e3e 1326 arch-tag: fd9d8e77-66af-491c-b212-d80999613e3e