home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-User.iso / usr / lib / emacs / info / emacs-4 (.txt) < prev    next >
GNU Info File  |  1992-10-30  |  48KB  |  841 lines

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