home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / os2 / e17info.zip / EMACS / 19.17 / INFO / EMACS-5 (.txt) < prev    next >
GNU Info File  |  1993-07-18  |  49KB  |  848 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.54 from the
  2. input file emacs.texi.
  3. File: emacs,  Node: Horizontal Scrolling,  Next: Selective Display,  Prev: Scrolling,  Up: Display
  4. Horizontal Scrolling
  5. ====================
  6. `C-x <'
  7.      Scroll text in current window to the left (`scroll-left').
  8. `C-x >'
  9.      Scroll to the right (`scroll-right').
  10.    The text in a window can also be scrolled horizontally.  This means
  11. that each line of text is shifted sideways in the window, and one or
  12. more characters at the beginning of each line are not displayed at all.
  13. When a window has been scrolled horizontally in this way, text lines
  14. are truncated rather than continued (*note Continuation Lines::.), with
  15. a `$' appearing in the first column when there is text truncated to the
  16. left, and in the last column when there is text truncated to the right.
  17.    The command `C-x <' (`scroll-left') scrolls the selected window to
  18. the left by N columns with argument N.  This moves part of the
  19. beginning of each line off the left edge of the window.  With no
  20. argument, it scrolls by almost the full width of the window (two
  21. columns less, to be precise).
  22.    `C-x >' (`scroll-right') scrolls similarly to the right.  The window
  23. cannot be scrolled any farther to the right once it is displaying
  24. normally (with each line starting at the window's left margin);
  25. attempting to do so has no effect.  This means that you don't have to
  26. calculate the argument precisely for `C-x >'; any sufficiently large
  27. argument will restore normally display.
  28. File: emacs,  Node: Selective Display,  Next: Optional Display,  Prev: Horizontal Scrolling,  Up: Display
  29. Selective Display
  30. =================
  31.    Emacs has the ability to hide lines indented more than a certain
  32. number of columns (you specify how many columns).  You can use this to
  33. get an overview of a part of a program.
  34.    To hide lines, type `C-x $' (`set-selective-display') with a numeric
  35. argument N.  Then lines with at least N columns of indentation
  36. disappear from the screen.  The only indication of their presence is
  37. that three dots (`...') appear at the end of each visible line that is
  38. followed by one or more invisible ones.
  39.    The commands `C-n' and `C-p' move across the invisible lines as if
  40. they were not there.
  41.    The invisible lines are still present in the buffer, and most editing
  42. commands see them as usual, so you may find point in the middle of
  43. invisible text.  When this happens, the cursor appears at the end of the
  44. previous line, after the three dots.  If point is at the end of the
  45. visible line, before the newline that ends it, the cursor appears before
  46. the three dots.
  47.    To make everything visible again, type `C-x $' with no argument.
  48. File: emacs,  Node: European Display,  Next: Display Vars,  Prev: Optional Display,  Up: Display
  49. European Character Set Display
  50. ==============================
  51.    Emacs can display accented characters, assuming the font in use
  52. supports them.  The `M-x standard-display-european' command toggles
  53. European character display.  When enabled, Emacs displays characters
  54. according to the ISO 8859 Latin-1 encoding for European languages; when
  55. disabled, Emacs uses octal notation for all characters not specified by
  56. the ordinary ASCII standard.  Load the library `iso-syntax' to specify
  57. the correct syntactic properties for the character codes 128 and above.
  58.    With a prefix argument, `M-x standard-display-european' enables
  59. European character display if and only if the argument is positive.
  60.    If your terminal can send character codes 128 and up to represent
  61. ISO Latin-1 characters, execute the following expression to enable
  62. Emacs to understand them:
  63.      (set-input-mode (car (current-input-mode))
  64.                      (nth 1 (current-input-mode))
  65.                      0)
  66. Otherwise, you can load the library `iso-insert' to turn the key `C-x
  67. 8' into a "compose character" prefix for insertion of the extra ISO
  68. Latin-1 printing characters.
  69. File: emacs,  Node: Optional Display,  Next: European Display,  Prev: Selective Display,  Up: Display
  70. Optional Display Features
  71. =========================
  72.    To add the current line number of point to the mode line, enable Line
  73. Number mode with the command `M-x line-number-mode'.  The line number
  74. appears before POS, with the letter `L' to indicate what it is.  *Note
  75. Minor Modes::, for more information about minor modes and about how to
  76. use this command.
  77.    If the buffer is very large (larger than the value of
  78. `line-number-display-limit'), then the line number doesn't appear.
  79. Emacs doesn't compute the line number when the buffer is large, because
  80. that would be too slow.
  81.    Emacs can optionally display the time and system load in all mode
  82. lines.  To enable this feature, type `M-x display-time'.  The
  83. information added to the mode line usually appears after the buffer
  84. name, before the mode names and their parentheses.  It looks like this:
  85.      HH:MMpm L.LL [D]
  86. Here HH and MM are the hour and minute, followed always by `am' or
  87. `pm'.  L.LL is the average number of running processes in the whole
  88. system recently.  D is an approximate index of the ratio of disk
  89. activity to cpu activity for all users.  (Some fields may be missing if
  90. your operating system cannot support them.)
  91.    The word `Mail' appears after the load level if there is mail for
  92. you that you have not read yet.
  93.    Customization note: the variable `mode-line-inverse-video' controls
  94. whether the mode line is displayed in inverse video (assuming the
  95. terminal supports it); `nil' means no inverse video.  The default is
  96. `t'.  *Note Display Vars::.
  97. File: emacs,  Node: Display Vars,  Prev: European Display,  Up: Display
  98. Variables Controlling Display
  99. =============================
  100.    This section contains information for customization only.  Beginning
  101. users should skip it.
  102.    The variable `mode-line-inverse-video' controls whether the mode
  103. line is displayed in inverse video (assuming the terminal supports it);
  104. `nil' means don't do so.  *Note Mode Line::.
  105.    If the variable `inverse-video' is non-`nil', Emacs attempts to
  106. invert all the lines of the display from what they normally are.
  107.    If the variable `visible-bell' is non-`nil', Emacs attempts to make
  108. the whole screen blink when it would normally make an audible bell
  109. sound.  This variable has no effect if your terminal does not have a way
  110. to make the screen blink.
  111.    When you reenter Emacs after suspending, Emacs normally clears the
  112. screen and redraws the entire display.  On some terminals with more than
  113. one page of memory, it is possible to arrange the termcap entry so that
  114. the `ti' and `te' strings (output to the terminal when Emacs is entered
  115. and exited, respectively) switch between pages of memory so as to use
  116. one page for Emacs and another page for other output.  Then you might
  117. want to set the variable `no-redraw-on-reenter' non-`nil'; this tells
  118. Emacs to assume, when resumed, that the screen page it is using still
  119. contains what Emacs last wrote there.
  120.    The variable `echo-keystrokes' controls the echoing of
  121. multi-character keys; its value is the number of seconds of pause
  122. required to cause echoing to start, or zero meaning don't echo at all.
  123. *Note Echo Area::.
  124.    If the variable `ctl-arrow' is `nil', control characters in the
  125. buffer are displayed with octal escape sequences, all except newline
  126. and tab.  Altering the value of `ctl-arrow' makes it local to the
  127. current buffer; until that time, the default value is in effect.  The
  128. default is initially `t'.  *Note Display Tables: (elisp)Display Tables.
  129.    Normally, a tab character in the buffer is displayed as whitespace
  130. which extends to the next display tab stop position, and display tab
  131. stops come at intervals equal to eight spaces.  The number of spaces
  132. per tab is controlled by the variable `tab-width', which is made local
  133. by changing it, just like `ctl-arrow'.  Note that how the tab character
  134. in the buffer is displayed has nothing to do with the definition of TAB
  135. as a command.  The variable `tab-width' must have an integer value
  136. between 1 and 1000, inclusive.
  137.    If you set the variable `selective-display-ellipses' to `nil', the
  138. three dots do not appear at the end of a line that precedes invisible
  139. lines.  Then there is no visible indication of the invisible lines.
  140. This variable too becomes local automatically when set.
  141.    If the variable `truncate-lines' is non-`nil', then each line of
  142. text gets just one screen line for display; if the text line is too
  143. long, display shows only the part that fits.  If `truncate-lines' is
  144. `nil', then long text lines display as more than one screen line,
  145. enough to show the whole text of the line.  *Note Continuation Lines::.
  146. Altering the value of `truncate-lines' makes it local to the current
  147. buffer; until that time, the default value is in effect.  The default
  148. is initially `nil'.
  149.    If the variable `truncate-partial-width-windows' is non-`nil', it
  150. forces truncation rather than continuation in any window less than the
  151. full width of the screen or frame, regardless of the value of
  152. `truncate-lines'.  For information about side-by-side windows, see
  153. *Note Split Window::.  See also *Note Display: (elisp)Display.
  154.    The variable `baud-rate' holds the the output speed of the terminal,
  155. as far as Emacs knows.  Setting this variable does not change the speed
  156. of actual data transmission, but the value is used for calculations
  157. such as padding.  It also affects decisions about whether to scroll
  158. part of the screen or redraw it instead--even when using a window
  159. system, (We designed it this way, despite the fact that a window system
  160. has no true "output speed", to give you a way to tune these decisions.)
  161. File: emacs,  Node: Search,  Next: Fixit,  Prev: Display,  Up: Top
  162. Searching and Replacement
  163. *************************
  164.    Like other editors, Emacs has commands for searching for occurrences
  165. of a string.  The principal search command is unusual in that it is
  166. "incremental"; it begins to search before you have finished typing the
  167. search string.  There are also nonincremental search commands more like
  168. those of other editors.
  169.    Besides the usual `replace-string' command that finds all
  170. occurrences of one string and replaces them with another, Emacs has a
  171. fancy replacement command called `query-replace' which asks
  172. interactively which occurrences to replace.
  173. * Menu:
  174. * Incremental Search::      Search happens as you type the string.
  175. * Nonincremental Search::   Specify entire string and then search.
  176. * Word Search::             Search for sequence of words.
  177. * Regexp Search::           Search for match for a regexp.
  178. * Regexps::                 Syntax of regular expressions.
  179. * Search Case::             To ignore case while searching, or not.
  180. * Replace::                 Search, and replace some or all matches.
  181. * Other Repeating Search::  Operating on all matches for some regexp.
  182. File: emacs,  Node: Incremental Search,  Next: Nonincremental Search,  Prev: Search,  Up: Search
  183. Incremental Search
  184. ==================
  185.    An incremental search begins searching as soon as you type the first
  186. character of the search string.  As you type in the search string, Emacs
  187. shows you where the string (as you have typed it so far) would be
  188. found.  When you have typed enough characters to identify the place you
  189. want, you can stop.  Depending on what you plan to do next, you may or
  190. may not need to terminate the search explicitly with RET.
  191. `C-s'
  192.      Incremental search forward (`isearch-forward').
  193. `C-r'
  194.      Incremental search backward (`isearch-backward').
  195.    `C-s' starts an incremental search.  `C-s' reads characters from the
  196. keyboard and positions the cursor at the first occurrence of the
  197. characters that you have typed.  If you type `C-s' and then `F', the
  198. cursor moves right after the first `F'.  Type an `O', and see the
  199. cursor move to after the first `FO'.  After another `O', the cursor is
  200. after the first `FOO' after the place where you started the search.
  201. Meanwhile, the search string `FOO' has been echoed in the echo area.
  202.    If you make a mistake in typing the search string, you can cancel
  203. characters with DEL.  Each DEL cancels the last character of search
  204. string.  This does not happen until Emacs is ready to read another
  205. input character; first it must either find, or fail to find, the
  206. character you want to erase.  If you do not want to wait for this to
  207. happen, use `C-g' as described below.
  208.    When you are satisfied with the place you have reached, you can type
  209. RET, which stops searching, leaving the cursor where the search brought
  210. it.  Also, any command not specially meaningful in searches stops the
  211. searching and is then executed.  Thus, typing `C-a' would exit the
  212. search and then move to the beginning of the line.  RET is necessary
  213. only if the next command you want to type is a printing character, DEL,
  214. RET, or another control character that is special within searches
  215. (`C-q', `C-w', `C-r', `C-s', `C-y', `M-r', or `M-s').
  216.    Sometimes you search for `FOO' and find it, but not the one you
  217. expected to find.  There was a second `FOO' that you forgot about,
  218. before the one you were looking for.  In this event, type another `C-s'
  219. to move to the next occurrence of the search string.  This can be done
  220. any number of times.  If you overshoot, you can cancel some `C-s'
  221. characters with DEL.
  222.    After you exit a search, you can search for the same string again by
  223. typing just `C-s C-s': the first `C-s' is the key that invokes
  224. incremental search, and the second `C-s' means "search again".
  225.    To reuse earlier search strings, use the "search ring".  The
  226. commands `M-p' and `M-n' move through the ring to pick a search string
  227. to reuse.  These commands leave the selected search ring element in the
  228. minibuffer, where you can edit it.  Type `C-s' or `C-r' to terminate
  229. editing the string and search for it.
  230.    If your string is not found at all, the echo area says `Failing
  231. I-Search'.  The cursor is after the place where Emacs found as much of
  232. your string as it could.  Thus, if you search for `FOOT', and there is
  233. no `FOOT', you might see the cursor after the `FOO' in `FOOL'.  At this
  234. point there are several things you can do.  If your string was
  235. mistyped, you can rub some of it out and correct it.  If you like the
  236. place you have found, you can type RET or some other Emacs command to
  237. "accept what the search offered".  Or you can type `C-g', which removes
  238. from the search string the characters that could not be found (the `T'
  239. in `FOOT'), leaving those that were found (the `FOO' in `FOOT').  A
  240. second `C-g' at that point cancels the search entirely, returning point
  241. to where it was when the search started.
  242.    An upper-case letter in the search string makes the search
  243. case-sensitive.  If you delete the upper-case character from the search
  244. string, it ceases to have this effect.  *Note Search Case::.
  245.    If a search is failing and you ask to repeat it by typing another
  246. `C-s', it starts again from the beginning of the buffer.  Repeating a
  247. failing reverse search with `C-r' starts again from the end.  This is
  248. called "wrapping around".  `Wrapped' appears in the search prompt once
  249. this has happened.
  250.    The `C-g' "quit" character does special things during searches; just
  251. what it does depends on the status of the search.  If the search has
  252. found what you specified and is waiting for input, `C-g' cancels the
  253. entire search.  The cursor moves back to where you started the search.
  254. If `C-g' is typed when there are characters in the search string that
  255. have not been found--because Emacs is still searching for them, or
  256. because it has failed to find them--then the search string characters
  257. which have not been found are discarded from the search string.  With
  258. them gone, the search is now successful and waiting for more input, so
  259. a second `C-g' will cancel the entire search.
  260.    To search for a newline, type LFD (also known as `C-j').  To search
  261. for another control character such as control-S or carriage return, you
  262. must quote it by typing `C-q' first.  This function of `C-q' is
  263. analogous to its meaning as an Emacs command: it causes the following
  264. character to be treated the way a graphic character would normally be
  265. treated in the same context.  You can also specify a character by its
  266. octal code: enter `C-q' followed by three octal digits.
  267.    You can change to searching backwards with `C-r'.  If a search fails
  268. because the place you started was too late in the file, you should do
  269. this.  Repeated `C-r' keeps looking for more occurrences backwards.  A
  270. `C-s' starts going forwards again.  `C-r' in a search can be cancelled
  271. with DEL.
  272.    If you know initially that you want to search backwards, you can use
  273. `C-r' instead of `C-s' to start the search, because `C-r' is also a key
  274. running a command (`isearch-backward') to search backward.
  275.    The characters `C-y' and `C-w' can be used in incremental search to
  276. grab text from the buffer into the search string.  This makes it
  277. convenient to search for another occurrence of text at point.  `C-w'
  278. copies the word after point as part of the search string, advancing
  279. point over that word.  Another `C-s' to repeat the search will then
  280. search for a string including that word.  `C-y' is similar to `C-w' but
  281. copies all the rest of the current line into the search string.
  282.    To customize the special characters that incremental search
  283. understands, alter their bindings in the keymap `isearch-mode-map'.
  284. Slow Terminal Incremental Search
  285. --------------------------------
  286.    Incremental search on a slow terminal uses a modified style of
  287. display that is designed to take less time.  Instead of redisplaying
  288. the buffer at each place the search gets to, it creates a new
  289. single-line window and uses that to display the line that the search
  290. has found.  The single-line window comes into play as soon as point
  291. gets outside of the text that is already on the screen.
  292.    When you terminate the search, the single-line window is removed.
  293. Then Emacs redisplays the window in which the search was done, to show
  294. its new position of point.
  295.    The slow terminal style of display is used when the terminal baud
  296. rate is less than or equal to the value of the variable
  297. `search-slow-speed', initially 1200.
  298.    The number of lines to use in slow terminal search display is
  299. controlled by the variable `search-slow-window-lines'.  1 is its normal
  300. value.
  301. File: emacs,  Node: Nonincremental Search,  Next: Word Search,  Prev: Incremental Search,  Up: Search
  302. Nonincremental Search
  303. =====================
  304.    Emacs also has conventional nonincremental search commands, which
  305. require you to type the entire search string before searching begins.
  306. `C-s RET STRING RET'
  307.      Search for STRING.
  308. `C-r RET STRING RET'
  309.      Search backward for STRING.
  310.    To do a nonincremental search, first type `C-s RET'.  This enters
  311. the minibuffer to read the search string; terminate the string with
  312. RET, and then the search takes place.  If the string is not found, the
  313. search command gets an error.
  314.    The way `C-s RET' works is that the `C-s' invokes incremental
  315. search, which is specially programmed to invoke nonincremental search
  316. if the argument you give it is empty.  (Such an empty argument would
  317. otherwise be useless.)  `C-r RET' also works this way.
  318.    However, nonincremental searches performed using `C-s RET' do not
  319. call `search-forward' right away.  The first thing done is to see if
  320. the next character is `C-w', which requests a word search.  *Note Word
  321. Search::.
  322.    Forward and backward nonincremental searches are implemented by the
  323. commands `search-forward' and `search-backward'.  These commands may be
  324. bound to keys in the usual manner.  The feature that you can get to
  325. them via the incremental search commands exists for historical reasons,
  326. and to avoid the need to find suitable key sequences for them.
  327. File: emacs,  Node: Word Search,  Next: Regexp Search,  Prev: Nonincremental Search,  Up: Search
  328. Word Search
  329. ===========
  330.    Word search searches for a sequence of words without regard to how
  331. the words are separated.  More precisely, you type a string of many
  332. words, using single spaces to separate them, and the string can be
  333. found even if there are multiple spaces, newlines or other punctuation
  334. between the words.
  335.    Word search is useful for editing a printed document made with a text
  336. formatter.  If you edit while looking at the printed, formatted version,
  337. you can't tell where the line breaks are in the source file.  With word
  338. search, you can search without having to know them.
  339. `C-s RET C-w WORDS RET'
  340.      Search for WORDS, ignoring details of punctuation.
  341. `C-r RET C-w WORDS RET'
  342.      Search backward for WORDS, ignoring details of punctuation.
  343.    Word search is a special case of nonincremental search and is invoked
  344. with `C-s RET C-w'.  This is followed by the search string, which must
  345. always be terminated with RET.  Being nonincremental, this search does
  346. not start until the argument is terminated.  It works by constructing a
  347. regular expression and searching for that; see *Note Regexp Search::.
  348.    Use `C-r RET C-w' to do backward word search.
  349.    Forward and backward word searches are implemented by the commands
  350. `word-search-forward' and `word-search-backward'.  These commands may
  351. be bound to keys in the usual manner.  The feature that you can get to
  352. them via the incremental search commands exists for historical reasons,
  353. and to avoid the need to find suitable key sequences for them.
  354. File: emacs,  Node: Regexp Search,  Next: Regexps,  Prev: Word Search,  Up: Search
  355. Regular Expression Search
  356. =========================
  357.    A "regular expression" ("regexp", for short) is a pattern that
  358. denotes a class of alternative strings to match, possibly infinitely
  359. many.  In GNU Emacs, you can search for the next match for a regexp
  360. either incrementally or not.
  361.    Incremental search for a regexp is done by typing `C-M-s'
  362. (`isearch-forward-regexp').  This command reads a search string
  363. incrementally just like `C-s', but it treats the search string as a
  364. regexp rather than looking for an exact match against the text in the
  365. buffer.  Each time you add text to the search string, you make the
  366. regexp longer, and the new regexp is searched for.  To search backward
  367. in the buffer, use `C-M-r' (`isearch-backward-regexp').
  368.    All of the control characters that do special things within an
  369. ordinary incremental search have the same function in incremental regexp
  370. search.  Typing `C-s' or `C-r' immediately after starting the search
  371. retrieves the last incremental search regexp used; that is to say,
  372. incremental regexp and non-regexp searches have independent defaults.
  373. They also have separate search rings that you can access with `M-p' and
  374. `M-n'.
  375.    If you type SPC in incremental regexp search, it matches any
  376. sequence of whitespace characters, including newlines.  If you want to
  377. match just a space, type `C-q SPC'.
  378.    Note that adding characters to the regexp in an incremental regexp
  379. search can make the cursor move back and start again.  For example, if
  380. you have searched for `foo' and you add `\|bar', the cursor backs up in
  381. case the first `bar' precedes the first `foo'.
  382.    Nonincremental search for a regexp is done by the functions
  383. `re-search-forward' and `re-search-backward'.  You can invoke these
  384. with `M-x', or bind them to keys, or invoke them by way of incremental
  385. regexp search with `C-M-s RET' and `C-M-r RET'.
  386. File: emacs,  Node: Regexps,  Next: Search Case,  Prev: Regexp Search,  Up: Search
  387. Syntax of Regular Expressions
  388. =============================
  389.    Regular expressions have a syntax in which a few characters are
  390. special constructs and the rest are "ordinary".  An ordinary character
  391. is a simple regular expression which matches that same character and
  392. nothing else.  The special characters are `$', `^', `.', `*', `+', `?',
  393. `[', `]' and `\'.  Any other character appearing in a regular
  394. expression is ordinary, unless a `\' precedes it.
  395.    For example, `f' is not a special character, so it is ordinary, and
  396. therefore `f' is a regular expression that matches the string `f' and
  397. no other string.  (It does *not* match the string `ff'.)  Likewise, `o'
  398. is a regular expression that matches only `o'.  (When case distinctions
  399. are being ignored, these regexps also match `F' and `O', but we
  400. consider this a generalization of "the same string", rather than an
  401. exception.)
  402.    Any two regular expressions A and B can be concatenated.  The result
  403. is a regular expression which matches a string if A matches some amount
  404. of the beginning of that string and B matches the rest of the string.
  405.    As a simple example, we can concatenate the regular expressions `f'
  406. and `o' to get the regular expression `fo', which matches only the
  407. string `fo'.  Still trivial.  To do something nontrivial, you need to
  408. use one of the special characters.  Here is a list of them.
  409. `. (Period)'
  410.      is a special character that matches any single character except a
  411.      newline.  Using concatenation, we can make regular expressions
  412.      like `a.b' which matches any three-character string which begins
  413.      with `a' and ends with `b'.
  414.      is not a construct by itself; it is a postfix operator, which
  415.      means to match the preceding regular expression repetitively as
  416.      many times as possible.  Thus, `o*' matches any number of `o's
  417.      (including no `o's).
  418.      `*' always applies to the *smallest* possible preceding
  419.      expression.  Thus, `fo*' has a repeating `o', not a repeating
  420.      `fo'.  It matches `f', `fo', `foo', and so on.
  421.      The matcher processes a `*' construct by matching, immediately, as
  422.      many repetitions as can be found.  Then it continues with the rest
  423.      of the pattern.  If that fails, backtracking occurs, discarding
  424.      some of the matches of the `*'-modified construct in case that
  425.      makes it possible to match the rest of the pattern.  For example,
  426.      matching `ca*ar' against the string `caaar', the `a*' first tries
  427.      to match all three `a's; but the rest of the pattern is `ar' and
  428.      there is only `r' left to match, so this try fails.  The next
  429.      alternative is for `a*' to match only two `a's.  With this choice,
  430.      the rest of the regexp matches successfully.
  431.      is a postfix character, similar to `*' except that it must match
  432.      the preceding expression at least once.  So, for example, `ca+r'
  433.      matches the strings `car' and `caaaar' but not the string `cr',
  434.      whereas `ca*r' matches all three strings.
  435.      is a postfix character, similar to `*' except that it can match the
  436.      preceding expression either once or not at all.  For example,
  437.      `ca?r' matches `car' or `cr'; nothing else.
  438. `[ ... ]'
  439.      is a "character set", which begins with `[' and is terminated by a
  440.      `]'.  In the simplest case, the characters between the two
  441.      brackets are what this set can match.
  442.      Thus, `[ad]' matches either one `a' or one `d', and `[ad]*'
  443.      matches any string composed of just `a's and `d's (including the
  444.      empty string), from which it follows that `c[ad]*r' matches `cr',
  445.      `car', `cdr', `caddaar', etc.
  446.      You can also include character ranges a character set, by writing
  447.      two characters with a `-' between them.  Thus, `[a-z]' matches any
  448.      lower-case letter.  Ranges may be intermixed freely with individual
  449.      characters, as in `[a-z$%.]', which matches any lower case letter
  450.      or `$', `%' or period.
  451.      Note that the usual special characters are not special any more
  452.      inside a character set.  A completely different set of special
  453.      characters exists inside character sets: `]', `-' and `^'.
  454.      To include a `]' in a character set, you must make it the first
  455.      character.  For example, `[]a]' matches `]' or `a'.  To include a
  456.      `-', write `-' at the beginning or end of a range.  To include
  457.      `^', make it other than the first character in the set.
  458. `[^ ... ]'
  459.      `[^' begins a "complemented character set", which matches any
  460.      character except the ones specified.  Thus, `[^a-z0-9A-Z]' matches
  461.      all characters *except* letters and digits.
  462.      `^' is not special in a character set unless it is the first
  463.      character.  The character following the `^' is treated as if it
  464.      were first (`-' and `]' are not special there).
  465.      A complemented character set can match a newline, unless newline is
  466.      mentioned as one of the characters not to match.  This is in
  467.      contrast to the handling of regexps in programs such as `grep'.
  468.      is a special character that matches the empty string, but only at
  469.      the beginning of a line in the text being matched.  Otherwise it
  470.      fails to match anything.  Thus, `^foo' matches a `foo' which
  471.      occurs at the beginning of a line.
  472.      is similar to `^' but matches only at the end of a line.  Thus,
  473.      `xx*$' matches a string of one `x' or more at the end of a line.
  474.      has two functions: it quotes the special characters (including
  475.      `\'), and it introduces additional special constructs.
  476.      Because `\' quotes special characters, `\$' is a regular
  477.      expression which matches only `$', and `\[' is a regular
  478.      expression which matches only `[', etc.
  479.    Note: for historical compatibility, special characters are treated as
  480. ordinary ones if they are in contexts where their special meanings make
  481. no sense.  For example, `*foo' treats `*' as ordinary since there is no
  482. preceding expression on which the `*' can act.  It is poor practice to
  483. depend on this behavior; better to quote the special character anyway,
  484. regardless of where is appears.
  485.    For the most part, `\' followed by any character matches only that
  486. character.  However, there are several exceptions: two-character
  487. sequences starting with `\' which have special meanings.  The second
  488. character in the sequence is always an ordinary character on their own.
  489. Here is a table of `\' constructs.
  490.      specifies an alternative.  Two regular expressions A and B with
  491.      `\|' in between form an expression that matches anything that
  492.      either A or B matches.
  493.      Thus, `foo\|bar' matches either `foo' or `bar' but no other string.
  494.      `\|' applies to the largest possible surrounding expressions.
  495.      Only a surrounding `\( ... \)' grouping can limit the scope of
  496.      `\|'.
  497.      Full backtracking capability exists to handle multiple uses of
  498.      `\|'.
  499. `\( ... \)'
  500.      is a grouping construct that serves three purposes:
  501.        1. To enclose a set of `\|' alternatives for other operations.
  502.           Thus, `\(foo\|bar\)x' matches either `foox' or `barx'.
  503.        2. To enclose a complicated expression for the postfix operators
  504.           `*', `+' and `?' to operate on.  Thus, `ba\(na\)*' matches
  505.           `bananana', etc., with any (zero or more) number of `na'
  506.           strings.
  507.        3. To mark a matched substring for future reference.
  508.      This last application is not a consequence of the idea of a
  509.      parenthetical grouping; it is a separate feature which is assigned
  510.      as a second meaning to the same `\( ... \)' construct.  In practice
  511.      there is no conflict between the two meanings.  Here is an
  512.      explanation of this feature:
  513.      after the end of a `\( ... \)' construct, the matcher remembers
  514.      the beginning and end of the text matched by that construct.  Then,
  515.      later on in the regular expression, you can use `\' followed by the
  516.      digit D to mean "match the same text matched the Dth time by the
  517.      `\( ... \)' construct."
  518.      The strings matching the first nine `\( ... \)' constructs
  519.      appearing in a regular expression are assigned numbers 1 through 9
  520.      in order that the open-parentheses appear in the regular
  521.      expression.  `\1' through `\9' refer to the text previously
  522.      matched by the corresponding `\( ... \)' construct.
  523.      For example, `\(.*\)\1' matches any newline-free string that is
  524.      composed of two identical halves.  The `\(.*\)' matches the first
  525.      half, which may be anything, but the `\1' that follows must match
  526.      the same exact text.
  527.      matches the empty string, provided it is at the beginning of the
  528.      buffer.
  529.      matches the empty string, provided it is at the end of the buffer.
  530.      matches the empty string, provided it is at the beginning or end
  531.      of a word.  Thus, `\bfoo\b' matches any occurrence of `foo' as a
  532.      separate word.  `\bballs?\b' matches `ball' or `balls' as a
  533.      separate word.
  534.      matches the empty string, provided it is *not* at the beginning or
  535.      end of a word.
  536.      matches the empty string, provided it is at the beginning of a
  537.      word.
  538.      matches the empty string, provided it is at the end of a word.
  539.      matches any word-constituent character.  The syntax table
  540.      determines which characters these are.
  541.      matches any character that is not a word-constituent.
  542. `\sC'
  543.      matches any character whose syntax is C.  Here C is a character
  544.      which represents a syntax code: thus, `w' for word constituent,
  545.      `(' for open-parenthesis, etc.  Represent a character of
  546.      whitespace (which can be a newline) by either `-' or a space
  547.      character.
  548. `\SC'
  549.      matches any character whose syntax is not C.
  550.    The constructs that pertain to words and syntax are controlled by the
  551. setting of the syntax table (*note Syntax::.).
  552.    Here is a complicated regexp, used by Emacs to recognize the end of a
  553. sentence together with any whitespace that follows.  It is given in Lisp
  554. syntax to enable you to distinguish the spaces from the tab characters.
  555. In Lisp syntax, the string constant begins and ends with a
  556. double-quote.  `\"' stands for a double-quote as part of the regexp,
  557. `\\' for a backslash as part of the regexp, `\t' for a tab and `\n' for
  558. a newline.
  559.      "[.?!][]\"')]*\\($\\|\t\\|  \\)[ \t\n]*"
  560. This contains four parts in succession: a character set matching period,
  561. `?', or `!'; a character set matching close-brackets, quotes, or
  562. parentheses, repeated any number of times; an alternative in
  563. backslash-parentheses that matches end-of-line, a tab, or two spaces;
  564. and a character set matching whitespace characters, repeated any number
  565. of times.
  566.    To enter the same regexp interactively, you would type TAB to enter
  567. a tab, and `C-q C-j' to enter a newline.  You would also type single
  568. slashes as themselves, instead of doubling them for Lisp syntax.
  569. File: emacs,  Node: Search Case,  Next: Replace,  Prev: Regexps,  Up: Search
  570. Searching and Case
  571. ==================
  572.    All sorts of searches in Emacs normally ignore the case of the text
  573. they are searching through, if you specify the text in lower case.
  574. Thus, if you specify searching for `foo', then `Foo' and `foo' are also
  575. considered a match.  Regexps, and in particular character sets, are
  576. included: `[ab]' would match `a' or `A' or `b' or `B'.
  577.    An upper-case letter in the search string makes the search
  578. case-sensitive.  Thus, searching for `Foo' does not find `foo' or
  579. `FOO'.  This applies to regular expression search also.  If you delete
  580. the upper-case character from the search string, it ceases to have this
  581. effect.
  582.    If you set the variable `case-fold-search' to `nil', then all
  583. letters must match exactly, including case.  This is a per-buffer
  584. variable; altering the variable affects only the current buffer, but
  585. there is a default value which you can change as well.  *Note Locals::.
  586. File: emacs,  Node: Replace,  Next: Other Repeating Search,  Prev: Search Case,  Up: Search
  587. Replacement Commands
  588. ====================
  589.    Global search-and-replace operations are not needed as often in Emacs
  590. as they are in other editors(1), but they are available.  In addition
  591. to the simple `M-x replace-string' command which is like that found in
  592. most editors, there is a `M-x query-replace' command which asks you, for
  593. each occurrence of the pattern, whether to replace it.
  594.    The replace commands all replace one string (or regexp) with one
  595. replacement string.  It is possible to perform several replacements in
  596. parallel using the command `expand-region-abbrevs'.  *Note Expanding
  597. Abbrevs::.
  598. * Menu:
  599. * Unconditional Replace::  Replacing all matches for a string.
  600. * Regexp Replace::         Replacing all matches for a regexp.
  601. * Replacement and Case::   How replacements preserve case of letters.
  602. * Query Replace::          How to use querying.
  603.    ---------- Footnotes ----------
  604.    (1)  In some editors, search-and-replace operations are the only
  605. convenient way to make a single change in the text.
  606. File: emacs,  Node: Unconditional Replace,  Next: Regexp Replace,  Prev: Replace,  Up: Replace
  607. Unconditional Replacement
  608. -------------------------
  609. `M-x replace-string RET STRING RET NEWSTRING RET'
  610.      Replace every occurrence of STRING with NEWSTRING.
  611. `M-x replace-regexp RET REGEXP RET NEWSTRING RET'
  612.      Replace every match for REGEXP with NEWSTRING.
  613.    To replace every instance of `foo' after point with `bar', use the
  614. command `M-x replace-string' with the two arguments `foo' and `bar'.
  615. Replacement happens only in the text after point, so if you want to
  616. cover the whole buffer you must go to the beginning first.  All
  617. occurrences up to the end of the buffer are replaced; to limit
  618. replacement to part of the buffer, narrow to that part of the buffer
  619. before doing the replacement (*note Narrowing::.).
  620.    When `replace-string' exits, point is left at the last occurrence
  621. replaced.  The position of point where the `replace-string' command was
  622. issued is remembered on the mark ring; use `C-u C-SPC' to move back
  623. there.
  624.    A numeric argument restricts replacement to matches that are
  625. surrounded by word boundaries.
  626. File: emacs,  Node: Regexp Replace,  Next: Replacement and Case,  Prev: Unconditional Replace,  Up: Replace
  627. Regexp Replacement
  628. ------------------
  629.    The `M-x replace-string' command replaces exact matches for a single
  630. string.  The similar command `M-x replace-regexp' replaces any match
  631. for a specified pattern.
  632.    In `replace-regexp', the NEWSTRING need not be constant: it can
  633. refer to all or part of what is matched by the REGEXP.  `\&' in
  634. NEWSTRING stands for the entire text being replaced.  `\D' in
  635. NEWSTRING, where D is a digit, stands for whatever matched the Dth
  636. parenthesized grouping in REGEXP.  To include a `\' in the text to
  637. replace with, you must give `\\'.  For example,
  638.      M-x replace-regexp RET c[ad]+r RET \&-safe RET
  639. replaces (for example) `cadr' with `cadr-safe' and `cddr' with
  640. `cddr-safe'.
  641.      M-x replace-regexp RET \(c[ad]+r\)-safe RET \1 RET
  642. performs the inverse transformation.
  643. File: emacs,  Node: Replacement and Case,  Next: Query Replace,  Prev: Regexp Replace,  Up: Replace
  644. Replace Commands and Case
  645. -------------------------
  646.    If the arguments to a replace command are in lower case, it preserves
  647. case when it makes a replacement.  Thus, the command
  648.      M-x replace-string RET foo RET bar RET
  649. replaces a lower case `foo' with a lower case `bar', `FOO' with `BAR',
  650. and `Foo' with `Bar'.  If upper case letters are used in the second
  651. argument, they remain upper case every time that argument is inserted.
  652. If upper case letters are used in the first argument, the second
  653. argument is always substituted exactly as given, with no case
  654. conversion.  Likewise, if the variable `case-replace' is set to `nil',
  655. replacement is done without case conversion.  If `case-fold-search' is
  656. set to `nil', case is significant in matching occurrences of `foo' to
  657. replace; this also inhibits case conversion of the replacement string.
  658. File: emacs,  Node: Query Replace,  Prev: Replacement and Case,  Up: Replace
  659. Query Replace
  660. -------------
  661. `M-% STRING RET NEWSTRING RET'
  662. `M-x query-replace RET STRING RET NEWSTRING RET'
  663.      Replace some occurrences of STRING with NEWSTRING.
  664. `M-x query-replace-regexp RET REGEXP RET NEWSTRING RET'
  665.      Replace some matches for REGEXP with NEWSTRING.
  666.    If you want to change only some of the occurrences of `foo' to
  667. `bar', not all of them, then you cannot use an ordinary
  668. `replace-string'.  Instead, use `M-%' (`query-replace').  This command
  669. finds occurrences of `foo' one by one, displays each occurrence and
  670. asks you whether to replace it.  A numeric argument to `query-replace'
  671. tells it to consider only occurrences that are bounded by
  672. word-delimiter characters.  This preserves case, just like
  673. `replace-string', provided `case-replace' is non-`nil', as it normally
  674.    Aside from querying, `query-replace' works just like
  675. `replace-string', and `query-replace-regexp' works just like
  676. `replace-regexp'.  The shortest way to type this command name is `M-x
  677. qu SPC SPC SPC RET'.
  678.    The things you can type when you are shown an occurrence of STRING
  679. or a match for REGEXP are:
  680. `SPC'
  681.      to replace the occurrence with NEWSTRING.
  682. `DEL'
  683.      to skip to the next occurrence without replacing this one.
  684. `, (Comma)'
  685.      to replace this occurrence and display the result.  You are then
  686.      asked for another input character, except that since the
  687.      replacement has already been made, DEL and SPC are equivalent.
  688.      You could type `C-r' at this point (see below) to alter the
  689.      replaced text.  You could also type `C-x u' to undo the
  690.      replacement; this exits the `query-replace', so if you want to do
  691.      further replacement you must use `C-x ESC RET' to restart (*note
  692.      Repetition::.).
  693. `RET'
  694. `ESC'
  695.      to exit without doing any more replacements.
  696. `. (Period)'
  697.      to replace this occurrence and then exit without searching for more
  698.      occurrences.
  699.      to replace all remaining occurrences without asking again.
  700.      to go back to the position of the previous occurrence (or what
  701.      used to be an occurrence), in case you changed it by mistake.
  702.      This works by popping the mark ring.  Only one `^' in a row is
  703.      allowed, because only one previous replacement position is kept
  704.      during `query-replace'.
  705. `C-r'
  706.      to enter a recursive editing level, in case the occurrence needs
  707.      to be edited rather than just replaced with NEWSTRING.  When you
  708.      are done, exit the recursive editing level with `C-M-c' to proceed
  709.      to the next occurrence.  *Note Recursive Edit::.
  710. `C-w'
  711.      to delete the occurrence, and then enter a recursive editing level
  712.      as in `C-r'.  Use the recursive edit to insert text to replace the
  713.      deleted occurrence of STRING.  When done, exit the recursive
  714.      editing level with `C-M-c' to proceed to the next occurrence.
  715. `C-l'
  716.      to redisplay the screen.  Then you must type another character to
  717.      specify what to do with this occurrence.
  718. `C-h'
  719.      to display a message summarizing these options.  Then you must type
  720.      another character to specify what to do with this occurrence.
  721.    Some other characters are aliases for the ones listed above: `y',
  722. `n' and `q' are equivalent to SPC, DEL and ESC.
  723.    Aside from this, any other character exits the `query-replace', and
  724. is then reread as part of a key sequence.  Thus, if you type `C-k', it
  725. exits the `query-replace' and then kills to end of line.
  726.    To restart a `query-replace' once it is exited, use `C-x ESC', which
  727. repeats the `query-replace' because it used the minibuffer to read its
  728. arguments.  *Note C-x ESC: Repetition.
  729.    See also *Note Transforming File Names::, for Dired commands to
  730. rename, copy, or link files by replacing regexp matches in file names.
  731. File: emacs,  Node: Other Repeating Search,  Prev: Replace,  Up: Search
  732. Other Search-and-Loop Commands
  733. ==============================
  734.    Here are some other commands that find matches for a regular
  735. expression.  They all operate from point to the end of the buffer.
  736. `M-x occur RET REGEXP RET'
  737.      Print each line that follows point and contains a match for
  738.      REGEXP.  A numeric argument specifies the number of context lines
  739.      to print before and after each matching line; the default is none.
  740.      The buffer `*Occur*' containing the output serves as a menu for
  741.      finding the occurrences in their original context.  Find an
  742.      occurrence as listed in `*Occur*', position point there and type
  743.      `C-c C-c'; this switches to the buffer that was searched and moves
  744.      point to the original of the same occurrence.
  745. `M-x list-matching-lines'
  746.      Synonym for `M-x occur'.
  747. `M-x count-matches RET REGEXP RET'
  748.      Print the number of matches for REGEXP after point.
  749. `M-x flush-lines RET REGEXP RET'
  750.      Delete each line that follows point and does not contain a match
  751.      for REGEXP.
  752. `M-x keep-lines RET REGEXP RET'
  753.      Delete each line that follows point and contains a match for
  754.      REGEXP.
  755. File: emacs,  Node: Fixit,  Next: Files,  Prev: Search,  Up: Top
  756. Commands for Fixing Typos
  757. *************************
  758.    In this chapter we describe the commands that are especially useful
  759. for the times when you catch a mistake in your text just after you have
  760. made it, or change your mind while composing text on line.
  761. * Menu:
  762. * Kill Errors:: Commands to kill a batch of recently entered text.
  763. * Transpose::   Exchanging two characters, words, lines, lists...
  764. * Fixing Case:: Correcting case of last word entered.
  765. * Spelling::    Apply spelling checker to a word, or a whole file.
  766. File: emacs,  Node: Kill Errors,  Next: Transpose,  Up: Fixit
  767. Killing Your Mistakes
  768. =====================
  769. `DEL'
  770.      Delete last character (`delete-backward-char').
  771. `M-DEL'
  772.      Kill last word (`backward-kill-word').
  773. `C-x DEL'
  774.      Kill to beginning of sentence (`backward-kill-sentence').
  775.    The DEL character (`delete-backward-char') is the most important
  776. correction command.  When used among graphic (self-inserting)
  777. characters, it can be thought of as canceling the last character typed.
  778.    When your mistake is longer than a couple of characters, it might be
  779. more convenient to use `M-DEL' or `C-x DEL'.  `M-DEL' kills back to the
  780. start of the last word, and `C-x DEL' kills back to the start of the
  781. last sentence.  `C-x DEL' is particularly useful when you change your
  782. mind about the phrasing of the text you are writing.  `M-DEL' and `C-x
  783. DEL' save the killed text for `C-y' and `M-y' to retrieve.  *Note
  784. Yanking::.
  785.    `M-DEL' is often useful even when you have typed only a few
  786. characters wrong, if you know you are confused in your typing and aren't
  787. sure exactly what you typed.  At such a time, you cannot correct with
  788. DEL except by looking at the screen to see what you did.  It requires
  789. less thought to kill the whole word and start over again.
  790. File: emacs,  Node: Transpose,  Next: Fixing Case,  Prev: Kill Errors,  Up: Fixit
  791. Transposing Text
  792. ================
  793. `C-t'
  794.      Transpose two characters (`transpose-chars').
  795. `M-t'
  796.      Transpose two words (`transpose-words').
  797. `C-M-t'
  798.      Transpose two balanced expressions (`transpose-sexps').
  799. `C-x C-t'
  800.      Transpose two lines (`transpose-lines').
  801.    The common error of transposing two characters can be fixed, when
  802. they are adjacent, with the `C-t' command (`transpose-chars').
  803. Normally, `C-t' transposes the two characters on either side of point.
  804. When given at the end of a line, rather than transposing the last
  805. character of the line with the newline, which would be useless, `C-t'
  806. transposes the last two characters on the line.  So, if you catch your
  807. transposition error right away, you can fix it with just a `C-t'.  If
  808. you don't catch it so fast, you must move the cursor back to between
  809. the two transposed characters.  If you transposed a space with the last
  810. character of the word before it, the word motion commands are a good
  811. way of getting there.  Otherwise, a reverse search (`C-r') is often the
  812. best way.  *Note Search::.
  813.    `M-t' (`transpose-words') transposes the word before point with the
  814. word after point.  It moves point forward over a word, dragging the
  815. word preceding or containing point forward as well.  The punctuation
  816. characters between the words do not move.  For example, `FOO, BAR'
  817. transposes into `BAR, FOO' rather than `BAR FOO,'.
  818.    `C-M-t' (`transpose-sexps') is a similar command for transposing two
  819. expressions (*note Lists::.), and `C-x C-t' (`transpose-lines')
  820. exchanges lines.  They work like `M-t' except in determining the
  821. division of the text into syntactic units.
  822.    A numeric argument to a transpose command serves as a repeat count:
  823. it tells the transpose command to move the character (word, sexp, line)
  824. before or containing point across several other characters (words,
  825. sexps, lines).  For example, `C-u 3 C-t' moves the character before
  826. point forward across three other characters.  It would change
  827. `f-!-oobar' into `oobf-!-ar'.  This is equivalent to repeating `C-t'
  828. three times.  `C-u - 4 M-t' moves the word before point backward across
  829. four words.  `C-u - C-M-t' would cancel the effect of plain `C-M-t'.
  830.    A numeric argument of zero is assigned a special meaning (because
  831. otherwise a command with a repeat count of zero would do nothing): to
  832. transpose the character (word, sexp, line) ending after point with the
  833. one ending after the mark.
  834. File: emacs,  Node: Fixing Case,  Next: Spelling,  Prev: Transpose,  Up: Fixit
  835. Case Conversion
  836. ===============
  837. `M-- M-l'
  838.      Convert last word to lower case.  Note `Meta--' is Meta-minus.
  839. `M-- M-u'
  840.      Convert last word to all upper case.
  841. `M-- M-c'
  842.      Convert last word to lower case with capital initial.
  843.    A very common error is to type words in the wrong case.  Because of
  844. this, the word case-conversion commands `M-l', `M-u' and `M-c' have a
  845. special feature when used with a negative argument: they do not move the
  846. cursor.  As soon as you see you have mistyped the last word, you can
  847. simply case-convert it and go on typing.  *Note Case::.
  848.