home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-19.28-src.tgz / tar.out / fsf / emacs / info / emacs-10 (.txt) < prev    next >
GNU Info File  |  1996-09-28  |  48KB  |  851 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.54 from the
  2. input file emacs.texi.
  3. File: emacs,  Node: Defuns,  Next: Program Indent,  Prev: List Commands,  Up: Programs
  4. Defuns
  5. ======
  6.    In Emacs, a parenthetical grouping at the top level in the buffer is
  7. called a "defun".  The name derives from the fact that most top-level
  8. lists in a Lisp file are instances of the special form `defun', but any
  9. top-level parenthetical grouping counts as a defun in Emacs parlance
  10. regardless of what its contents are, and regardless of the programming
  11. language in use.  For example, in C, the body of a function definition
  12. is a defun.
  13. `C-M-a'
  14.      Move to beginning of current or preceding defun
  15.      (`beginning-of-defun').
  16. `C-M-e'
  17.      Move to end of current or following defun (`end-of-defun').
  18. `C-M-h'
  19.      Put region around whole current or following defun (`mark-defun').
  20.    The commands to move to the beginning and end of the current defun
  21. are `C-M-a' (`beginning-of-defun') and `C-M-e' (`end-of-defun').
  22.    If you wish to operate on the current defun, use `C-M-h'
  23. (`mark-defun') which puts point at the beginning and mark at the end of
  24. the current or next defun.  For example, this is the easiest way to get
  25. ready to move the defun to a different place in the text.  In C mode,
  26. `C-M-h' runs the function `mark-c-function', which is almost the same
  27. as `mark-defun'; the difference is that it backs up over the argument
  28. declarations, function name and returned data type so that the entire C
  29. function is inside the region.  *Note Marking Objects::.
  30.    Emacs assumes that any open-parenthesis found in the leftmost column
  31. is the start of a defun.  Therefore, *never put an open-parenthesis at
  32. the left margin in a Lisp file unless it is the start of a top level
  33. list.  Never put an open-brace or other opening delimiter at the
  34. beginning of a line of C code unless it starts the body of a function.*
  35. The most likely problem case is when you want an opening delimiter at
  36. the start of a line inside a string.  To avoid trouble, put an escape
  37. character (`\', in C and Emacs Lisp, `/' in some other Lisp dialects)
  38. before the opening delimiter.  It will not affect the contents of the
  39. string.
  40.    In the remotest past, the original Emacs found defuns by moving
  41. upward a level of parentheses until there were no more levels to go up.
  42. This always required scanning all the way back to the beginning of the
  43. buffer, even for a small function.  To speed up the operation, Emacs
  44. was changed to assume that any `(' (or other character assigned the
  45. syntactic class of opening-delimiter) at the left margin is the start
  46. of a defun.  This heuristic is nearly always right and avoids the
  47. costly scan; however, it mandates the convention described above.
  48. File: emacs,  Node: Program Indent,  Next: Matching,  Prev: Defuns,  Up: Programs
  49. Indentation for Programs
  50. ========================
  51.    The best way to keep a program properly indented is to use Emacs to
  52. re-indent it as you change it.  Emacs has commands to indent properly
  53. either a single line, a specified number of lines, or all of the lines
  54. inside a single parenthetical grouping.
  55. * Menu:
  56. * Basic Indent::    Indenting a single line.
  57. * Multi-line Indent::   Commands to reindent many lines at once.
  58. * Lisp Indent::        Specifying how each Lisp function should be indented.
  59. * C Indent::        Choosing an indentation style for C code.
  60.    Emacs also provides a Lisp pretty-printer in the library `pp'.  This
  61. program prints a Lisp object with indentation chosen to look nice.
  62. File: emacs,  Node: Basic Indent,  Next: Multi-line Indent,  Up: Program Indent
  63. Basic Program Indentation Commands
  64. ----------------------------------
  65. `TAB'
  66.      Adjust indentation of current line.
  67. `LFD'
  68.      Equivalent to RET followed by TAB (`newline-and-indent').
  69.    The basic indentation command is TAB, which gives the current line
  70. the correct indentation as determined from the previous lines.  The
  71. function that TAB runs depends on the major mode; it is
  72. `lisp-indent-line' in Lisp mode, `c-indent-line' in C mode, etc.  These
  73. functions understand different syntaxes for different languages, but
  74. they all do about the same thing.  TAB in any programming language
  75. major mode inserts or deletes whitespace at the beginning of the
  76. current line, independent of where point is in the line.  If point is
  77. inside the whitespace at the beginning of the line, TAB leaves it at
  78. the end of that whitespace; otherwise, TAB leaves point fixed with
  79. respect to the characters around it.
  80.    Use `C-q TAB' to insert a tab at point.
  81.    When entering lines of new code, use LFD (`newline-and-indent'),
  82. which is equivalent to a RET followed by a TAB.  LFD creates a blank
  83. line, and then gives it the appropriate indentation.
  84.    TAB indents the second and following lines of the body of a
  85. parenthetical grouping each under the preceding one; therefore, if you
  86. alter one line's indentation to be nonstandard, the lines below will
  87. tend to follow it.  This behavior is convenient in cases where you have
  88. overridden the standard result of TAB because you find it unaesthetic
  89. for a particular line.
  90.    Remember that an open-parenthesis, open-brace or other opening
  91. delimiter at the left margin is assumed by Emacs (including the
  92. indentation routines) to be the start of a function.  Therefore, you
  93. must never have an opening delimiter in column zero that is not the
  94. beginning of a function, not even inside a string.  This restriction is
  95. vital for making the indentation commands fast; you must simply accept
  96. it.  *Note Defuns::, for more information on this.
  97. File: emacs,  Node: Multi-line Indent,  Next: Lisp Indent,  Prev: Basic Indent,  Up: Program Indent
  98. Indenting Several Lines
  99. -----------------------
  100.    When you wish to re-indent several lines of code which have been
  101. altered or moved to a different level in the list structure, you have
  102. several commands available.
  103. `C-M-q'
  104.      Re-indent all the lines within one list (`indent-sexp').
  105. `C-u TAB'
  106.      Shift an entire list rigidly sideways so that its first line is
  107.      properly indented.
  108. `C-M-\'
  109.      Re-indent all lines in the region (`indent-region').
  110.    You can re-indent the contents of a single list by positioning point
  111. before the beginning of it and typing `C-M-q' (`indent-sexp' in Lisp
  112. mode, `indent-c-exp' in C mode; also bound to other suitable commands
  113. in other modes).  The indentation of the line the sexp starts on is not
  114. changed; therefore, only the relative indentation within the list, and
  115. not its position, is changed.  To correct the position as well, type a
  116. TAB before the `C-M-q'.
  117.    If the relative indentation within a list is correct but the
  118. indentation of its first line is not, go to that line and type `C-u
  119. TAB'.  TAB with a numeric argument reindents the current line as usual,
  120. then reindents by the same amount all the lines in the grouping
  121. starting on the current line.  In other words, it reindents the whole
  122. grouping rigidly as a unit.  It is clever, though, and does not alter
  123. lines that start inside strings, or C preprocessor lines when in C mode.
  124.    Another way to specify the range to be re-indented is with the
  125. region.  The command `C-M-\' (`indent-region') applies TAB to every
  126. line whose first character is between point and mark.
  127. File: emacs,  Node: Lisp Indent,  Next: C Indent,  Prev: Multi-line Indent,  Up: Program Indent
  128. Customizing Lisp Indentation
  129. ----------------------------
  130.    The indentation pattern for a Lisp expression can depend on the
  131. function called by the expression.  For each Lisp function, you can
  132. choose among several predefined patterns of indentation, or define an
  133. arbitrary one with a Lisp program.
  134.    The standard pattern of indentation is as follows: the second line
  135. of the expression is indented under the first argument, if that is on
  136. the same line as the beginning of the expression; otherwise, the second
  137. line is indented underneath the function name.  Each following line is
  138. indented under the previous line whose nesting depth is the same.
  139.    If the variable `lisp-indent-offset' is non-`nil', it overrides the
  140. usual indentation pattern for the second line of an expression, so that
  141. such lines are always indented `lisp-indent-offset' more columns than
  142. the containing list.
  143.    The standard pattern is overridden for certain functions.  Functions
  144. whose names start with `def' always indent the second line by
  145. `lisp-body-indent' extra columns beyond the open-parenthesis starting
  146. the expression.
  147.    The standard pattern can be overridden in various ways for individual
  148. functions, according to the `lisp-indent-hook' property of the function
  149. name.  There are four possibilities for this property:
  150. `nil'
  151.      This is the same as no property; the standard indentation pattern
  152.      is used.
  153. `defun'
  154.      The pattern used for function names that start with `def' is used
  155.      for this function also.
  156. a number, NUMBER
  157.      The first NUMBER arguments of the function are "distinguished"
  158.      arguments; the rest are considered the "body" of the expression.
  159.      A line in the expression is indented according to whether the
  160.      first argument on it is distinguished or not.  If the argument is
  161.      part of the body, the line is indented `lisp-body-indent' more
  162.      columns than the open-parenthesis starting the containing
  163.      expression.  If the argument is distinguished and is either the
  164.      first or second argument, it is indented *twice* that many extra
  165.      columns.  If the argument is distinguished and not the first or
  166.      second argument, the standard pattern is followed for that line.
  167. a symbol, SYMBOL
  168.      SYMBOL should be a function name; that function is called to
  169.      calculate the indentation of a line within this expression.  The
  170.      function receives two arguments:
  171.     STATE
  172.           The value returned by `parse-partial-sexp' (a Lisp primitive
  173.           for indentation and nesting computation) when it parses up to
  174.           the beginning of this line.
  175.     POS
  176.           The position at which the line being indented begins.
  177.      It should return either a number, which is the number of columns of
  178.      indentation for that line, or a list whose car is such a number.
  179.      The difference between returning a number and returning a list is
  180.      that a number says that all following lines at the same nesting
  181.      level should be indented just like this one; a list says that
  182.      following lines might call for different indentations.  This makes
  183.      a difference when the indentation is being computed by `C-M-q'; if
  184.      the value is a number, `C-M-q' need not recalculate indentation
  185.      for the following lines until the end of the list.
  186. File: emacs,  Node: C Indent,  Prev: Lisp Indent,  Up: Program Indent
  187. Customizing C Indentation
  188. -------------------------
  189.    Two variables control which commands perform C indentation and when.
  190.    If `c-auto-newline' is non-`nil', newlines are inserted both before
  191. and after braces that you insert, and after colons and semicolons.
  192. Correct C indentation is done on all the lines that are made this way.
  193.    If `c-tab-always-indent' is `nil', the TAB command in C mode does
  194. indentation only if point is at the left margin or within the line's
  195. indentation.  If there is non-whitespace to the left of point, then TAB
  196. just inserts a tab character in the buffer.  Normally, this variable is
  197. `t', and TAB always reindents the current line.  The default behavior
  198. means that to insert a real tab character you must quote it by typing
  199. `C-q' TAB.
  200.    C does not have anything analogous to particular function names for
  201. which special forms of indentation are desirable.  However, it has a
  202. different need for customization facilities: many different styles of C
  203. indentation are in common use.
  204.    There are six variables you can set to control the style that Emacs C
  205. mode uses.
  206. `c-indent-level'
  207.      Indentation of C statements within surrounding block.  The
  208.      surrounding block's indentation is the indentation of the line on
  209.      which the open-brace appears.
  210. `c-continued-statement-offset'
  211.      Extra indentation given to a substatement, such as the then-clause
  212.      of an if or body of a while.
  213. `c-brace-offset'
  214.      Extra indentation for line if it starts with an open brace.
  215. `c-brace-imaginary-offset'
  216.      An open brace following other text is treated as if it were this
  217.      far to the right of the start of its line.
  218. `c-argdecl-indent'
  219.      Indentation level of declarations of C function arguments.
  220. `c-label-offset'
  221.      Extra indentation for line that is a label, or case or default.
  222.    The variable `c-indent-level' controls the indentation for C
  223. statements with respect to the surrounding block.  In the example
  224.          {
  225.            foo ();
  226. the difference in indentation between the lines is `c-indent-level'.
  227. Its standard value is 2.
  228.    If the open-brace beginning the compound statement is not at the
  229. beginning of its line, the `c-indent-level' is added to the indentation
  230. of the line, not the column of the open-brace.  For example,
  231.      if (losing) {
  232.        do_this ();
  233. One popular indentation style is that which results from setting
  234. `c-indent-level' to 8 and putting open-braces at the end of a line in
  235. this way.  I prefer to put the open-brace on a separate line.
  236.    In fact, the value of the variable `c-brace-imaginary-offset' is
  237. also added to the indentation of such a statement.  Normally this
  238. variable is zero.  Think of this variable as the imaginary position of
  239. the open brace, relative to the first nonblank character on the line.
  240. By setting this variable to 4 and `c-indent-level' to 0, you can get
  241. this style:
  242.      if (x == y) {
  243.          do_it ();
  244.          }
  245.    When `c-indent-level' is zero, the statements inside most braces
  246. will line up right under the open brace.  But there is an exception made
  247. for braces in column zero, such as surrounding a function's body.  The
  248. statements just inside it do not go at column zero.  Instead,
  249. `c-brace-offset' and `c-continued-statement-offset' (see below) are
  250. added to produce a typical offset between brace levels, and the
  251. statements are indented that far.
  252.    `c-continued-statement-offset' controls the extra indentation for a
  253. line that starts within a statement (but not within parentheses or
  254. brackets).  These lines are usually statements that are within other
  255. statements, such as the then-clauses of `if' statements and the bodies
  256. of `while' statements.  This parameter is the difference in indentation
  257. between the two lines in
  258.      if (x == y)
  259.        do_it ();
  260. Its standard value is 2.  Some popular indentation styles correspond to
  261. a value of zero for `c-continued-statement-offset'.
  262.    `c-brace-offset' is the extra indentation given to a line that
  263. starts with an open-brace.  Its standard value is zero; compare
  264.      if (x == y)
  265.        {
  266.      if (x == y)
  267.        do_it ();
  268. if `c-brace-offset' were set to 4, the first example would become
  269.      if (x == y)
  270.            {
  271.    `c-argdecl-indent' controls the indentation of declarations of the
  272. arguments of a C function.  It is absolute: argument declarations
  273. receive exactly `c-argdecl-indent' spaces.  The standard value is 5,
  274. resulting in code like this:
  275.      char *
  276.      index (string, c)
  277.           char *string;
  278.           int c;
  279.    `c-label-offset' is the extra indentation given to a line that
  280. contains a label, a case statement, or a `default:' statement.  Its
  281. standard value is -2, resulting in code like this
  282.      switch (c)
  283.        {
  284.        case 'x':
  285. If `c-label-offset' were zero, the same code would be indented as
  286.      switch (c)
  287.        {
  288.          case 'x':
  289. This example assumes that the other variables above also have their
  290. standard values.
  291.    I strongly recommend that you try out the indentation style produced
  292. by the standard settings of these variables, together with putting open
  293. braces on separate lines.  You can see how it looks in all the C source
  294. files of GNU Emacs.
  295. File: emacs,  Node: Matching,  Next: Comments,  Prev: Program Indent,  Up: Programs
  296. Automatic Display Of Matching Parentheses
  297. =========================================
  298.    The Emacs parenthesis-matching feature is designed to show
  299. automatically how parentheses match in the text.  Whenever you type a
  300. self-inserting character that is a closing delimiter, the cursor moves
  301. momentarily to the location of the matching opening delimiter, provided
  302. that is on the screen.  If it is not on the screen, some text near it is
  303. displayed in the echo area.  Either way, you can tell what grouping is
  304. being closed off.
  305.    In Lisp, automatic matching applies only to parentheses.  In C, it
  306. applies to braces and brackets too.  Emacs knows which characters to
  307. regard as matching delimiters based on the syntax table, which is set
  308. by the major mode.  *Note Syntax::.
  309.    If the opening delimiter and closing delimiter are mismatched--such
  310. as in `[x)'--a warning message is displayed in the echo area.  The
  311. correct matches are specified in the syntax table.
  312.    Two variables control parenthesis match display.
  313. `blink-matching-paren' turns the feature on or off; `nil' turns it off,
  314. but the default is `t' to turn match display on.
  315. `blink-matching-paren-distance' specifies how many characters back to
  316. search to find the matching opening delimiter.  If the match is not
  317. found in that far, scanning stops, and nothing is displayed.  This is
  318. to prevent scanning for the matching delimiter from wasting lots of
  319. time when there is no match.  The default is 12,000.
  320.    When using X Windows, you can request a more powerful kind of
  321. automatic parenthesis matching by loading the `paren' library.  To load
  322. it, type `M-x load-library RET paren RET'.  This library turns off the
  323. usual kind of matching parenthesis display and substitutes another:
  324. whenever point is after a close parenthesis, the close parenthesis and
  325. its matching open parenthesis are both highlighted; otherwise, if point
  326. is before an open parenthesis, the matching close parenthesis is
  327. highlighted.  (There is no need to highlight the open parenthesis after
  328. point because the cursor appears on top of that character.)
  329. File: emacs,  Node: Comments,  Next: Balanced Editing,  Prev: Matching,  Up: Programs
  330. Manipulating Comments
  331. =====================
  332.    Because comments are such an important part of programming, Emacs
  333. provides special commands for editing and inserting comments.
  334. * Menu:
  335. * Comment Commands::
  336. * Multi-Line Comments::
  337. * Options for Comments::
  338. File: emacs,  Node: Comment Commands,  Next: Multi-Line Comments,  Up: Comments
  339. Comment Commands
  340. ----------------
  341.    The comment commands insert, kill and align comments.
  342. `M-;'
  343.      Insert or align comment (`indent-for-comment').
  344. `C-x ;'
  345.      Set comment column (`set-comment-column').
  346. `C-u - C-x ;'
  347.      Kill comment on current line (`kill-comment').
  348. `M-LFD'
  349.      Like RET followed by inserting and aligning a comment
  350.      (`indent-new-comment-line').
  351. `M-x comment-region'
  352.      Add or remove comment delimiters on all the lines in the region.
  353.    The command that creates a comment is `M-;' (`indent-for-comment').
  354. If there is no comment already on the line, a new comment is created,
  355. aligned at a specific column called the "comment column".  The comment
  356. is created by inserting the string Emacs thinks comments should start
  357. with (the value of `comment-start'; see below).  Point is left after
  358. that string.  If the text of the line extends past the comment column,
  359. then the indentation is done to a suitable boundary (usually, at least
  360. one space is inserted).  If the major mode has specified a string to
  361. terminate comments, that is inserted after point, to keep the syntax
  362. valid.
  363.    `M-;' can also be used to align an existing comment.  If a line
  364. already contains the string that starts comments, then `M-;' just moves
  365. point after it and re-indents it to the conventional place.  Exception:
  366. comments starting in column 0 are not moved.
  367.    Some major modes have special rules for indenting certain kinds of
  368. comments in certain contexts.  For example, in Lisp code, comments which
  369. start with two semicolons are indented as if they were lines of code,
  370. instead of at the comment column.  Comments which start with three
  371. semicolons are supposed to start at the left margin.  Emacs understands
  372. these conventions by indenting a double-semicolon comment using TAB,
  373. and by not changing the indentation of a triple-semicolon comment at
  374.      ;; This function is just an example
  375.      ;;; Here either two or three semicolons are appropriate.
  376.      (defun foo (x)
  377.      ;;; And now, the first part of the function:
  378.        ;; The following line adds one.
  379.        (1+ x))           ; This line adds one.
  380.    In C code, a comment preceded on its line by nothing but whitespace
  381. is indented like a line of code.
  382.    Even when an existing comment is properly aligned, `M-;' is still
  383. useful for moving directly to the start of the comment.
  384.    `C-u - C-x ;' (`kill-comment') kills the comment on the current line,
  385. if there is one.  The indentation before the start of the comment is
  386. killed as well.  If there does not appear to be a comment in the line,
  387. nothing is done.  To reinsert the comment on another line, move to the
  388. end of that line, do `C-y', and then do `M-;' to realign it.  Note that
  389. `C-u - C-x ;' is not a distinct key; it is `C-x ;'
  390. (`set-comment-column') with a negative argument.  That command is
  391. programmed so that when it receives a negative argument it calls
  392. `kill-comment'.  However, `kill-comment' is a valid command which you
  393. could bind directly to a key if you wanted to.
  394. File: emacs,  Node: Multi-Line Comments,  Next: Options for Comments,  Prev: Comment Commands,  Up: Comments
  395. Multiple Lines of Comments
  396. --------------------------
  397.    If you are typing a comment and wish to continue it on another line,
  398. you can use the command `M-LFD' (`indent-new-comment-line').  This
  399. terminates the comment you are typing, creates a new blank line
  400. afterward, and begins a new comment indented under the old one.  When
  401. Auto Fill mode is on, going past the fill column while typing a comment
  402. causes the comment to be continued in just this fashion.  If point is
  403. not at the end of the line when `M-LFD' is typed, the text on the rest
  404. of the line becomes part of the new comment line.
  405.    To turn existing lines into comment lines, use the `M-x
  406. comment-region' command.  It adds comment delimiters to the lines that
  407. start in the region, thus commenting them out.  With a negative
  408. argument, it does the opposite--it deletes comment delimiters from the
  409. lines in the region.
  410.    With a positive argument, `comment-region' duplicates the last
  411. character of the comment start sequence it adds; the argument specifies
  412. how many copies of the character to insert.  Thus, in Lisp mode, `C-u 2
  413. M-x comment-region' adds `;;' to each line.  Duplicating the comment
  414. delimiter is a way of calling attention to the comment.  It can also
  415. affect how the comment is indented.  In Lisp, for proper indentation,
  416. you should use an argument of two, if between defuns, and three, if
  417. within a defun.
  418. File: emacs,  Node: Options for Comments,  Prev: Multi-Line Comments,  Up: Comments
  419. Options Controlling Comments
  420. ----------------------------
  421.    The comment column is stored in the variable `comment-column'.  You
  422. can set it to a number explicitly.  Alternatively, the command `C-x ;'
  423. (`set-comment-column') sets the comment column to the column point is
  424. at.  `C-u C-x ;' sets the comment column to match the last comment
  425. before point in the buffer, and then does a `M-;' to align the current
  426. line's comment under the previous one.  Note that `C-u - C-x ;' runs
  427. the function `kill-comment' as described above.
  428.    The variable `comment-column' is per-buffer: setting the variable in
  429. the normal fashion affects only the current buffer, but there is a
  430. default value which you can change with `setq-default'.  *Note
  431. Locals::.  Many major modes initialize this variable for the current
  432. buffer.
  433.    The comment commands recognize comments based on the regular
  434. expression that is the value of the variable `comment-start-skip'.
  435. Make sure this regexp does not match the null string.  It may match more
  436. than the comment starting delimiter in the strictest sense of the word;
  437. for example, in C mode the value of the variable is `"/\\*+ *"', which
  438. matches extra stars and spaces after the `/*' itself.  (Note that `\\'
  439. is needed in Lisp syntax to include a `\' in the string, which is
  440. needed to deny the first star its special meaning in regexp syntax.
  441. *Note Regexps::.)
  442.    When a comment command makes a new comment, it inserts the value of
  443. `comment-start' to begin it.  The value of `comment-end' is inserted
  444. after point, so that it will follow the text that you will insert into
  445. the comment.  In C mode, `comment-start' has the value `"/* "' and
  446. `comment-end' has the value `" */"'.
  447.    The variable `comment-multi-line' controls how `M-LFD'
  448. (`indent-new-comment-line') behaves when used inside a comment.  If
  449. `comment-multi-line' is `nil', as it normally is, then the comment on
  450. the starting line is terminated and a new comment is started on the new
  451. following line.  If `comment-multi-line' is not `nil', then the new
  452. following line is set up as part of the same comment that was found on
  453. the starting line.  This is done by not inserting a terminator on the
  454. old line, and not inserting a starter on the new line.  In languages
  455. where multi-line comments work, the choice of value for this variable
  456. is a matter of taste.
  457.    The variable `comment-indent-function' should contain a function
  458. that will be called to compute the indentation for a newly inserted
  459. comment or for aligning an existing comment.  It is set differently by
  460. various major modes.  The function is called with no arguments, but with
  461. point at the beginning of the comment, or at the end of a line if a new
  462. comment is to be inserted.  It should return the column in which the
  463. comment ought to start.  For example, in Lisp mode, the indent hook
  464. function bases its decision on how many semicolons begin an existing
  465. comment, and on the code in the preceding lines.
  466. File: emacs,  Node: Balanced Editing,  Next: Symbol Completion,  Prev: Comments,  Up: Programs
  467. Editing Without Unbalanced Parentheses
  468. ======================================
  469. `M-('
  470.      Put parentheses around next sexp(s) (`insert-parentheses').
  471. `M-)'
  472.      Move past next close parenthesis and re-indent
  473.      (`move-over-close-and-reindent').
  474.    The commands `M-(' (`insert-parentheses') and `M-)'
  475. (`move-over-close-and-reindent') are designed to facilitate a style of
  476. editing which keeps parentheses balanced at all times.  `M-(' inserts a
  477. pair of parentheses, either together as in `()', or, if given an
  478. argument, around the next several sexps.  It leaves point after the
  479. open parenthesis.  The command `M-)' moves past the close parenthesis,
  480. deleting any indentation preceding it (in this example there is none),
  481. and indenting with LFD after it.
  482.    For example, instead of typing `( F O O )', you can type `M-( F O
  483. O', which has the same effect except for leaving the cursor before the
  484. close parenthesis.
  485.    `M-(' may insert a space before the open parenthesis, depending on
  486. the syntax class of the preceding character.  Set
  487. `parens-dont-require-spaces' to a non-`nil' value if you wish to
  488. inhibit this.
  489. File: emacs,  Node: Symbol Completion,  Next: Documentation,  Prev: Balanced Editing,  Up: Programs
  490. Completion for Symbol Names
  491. ===========================
  492.    Usually completion happens in the minibuffer.  But one kind of
  493. completion is available in all buffers: completion for symbol names.
  494.    The character `M-TAB' runs a command to complete the partial symbol
  495. before point against the set of meaningful symbol names.  Any
  496. additional characters determined by the partial name are inserted at
  497. point.
  498.    If the partial name in the buffer has more than one possible
  499. completion and they have no additional characters in common, a list of
  500. all possible completions is displayed in another window.
  501.    There are two ways of determining the set of legitimate symbol names
  502. to complete against.  In most major modes, this uses a tags table
  503. (*note Tags::.); the legitimate symbol names are the tag names listed in
  504. the tags table file.  The command which implements this is
  505. `complete-tag'.
  506.    In Emacs-Lisp mode, the name space for completion normally consists
  507. of nontrivial symbols present in Emacs--those that have function
  508. definitions, values or properties.  However, if there is an
  509. open-parenthesis immediately before the beginning of the partial symbol,
  510. only symbols with function definitions are considered as completions.
  511. The command which implements this is `lisp-complete-symbol'.
  512.    In text mode and related modes, `M-TAB' completes words based on the
  513. spell-checker's dictionary.  *Note Spelling::.
  514. File: emacs,  Node: Documentation,  Next: Change Log,  Prev: Symbol Completion,  Up: Programs
  515. Documentation Commands
  516. ======================
  517.    As you edit Lisp code to be run in Emacs, the commands `C-h f'
  518. (`describe-function') and `C-h v' (`describe-variable') can be used to
  519. print documentation of functions and variables that you want to call.
  520. These commands use the minibuffer to read the name of a function or
  521. variable to document, and display the documentation in a window.
  522.    For extra convenience, these commands provide default arguments
  523. based on the code in the neighborhood of point.  `C-h f' sets the
  524. default to the function called in the innermost list containing point.
  525. `C-h v' uses the symbol name around or adjacent to point as its default.
  526.    Documentation on operating system commands, library functions and
  527. system calls can be obtained with the `M-x manual-entry' command.  This
  528. reads a topic as an argument, and displays the "man page" on that
  529. topic.  `manual-entry' starts a background process that formats the
  530. manual page, by running the `man' program.  The result goes in a buffer
  531. named `*man TOPIC*'.  These buffers use a special major mode, Man mode,
  532. that facilitates scrolling and examining other manual pages.  For
  533. details, type `C-h m' while in a man page buffer.
  534.    Eventually the GNU project hopes to replace most man pages with
  535. better-organized manuals that you can browse with Info.  *Note Misc
  536. Help::.  Since this process is only partially completed, it is still
  537. useful to read manual pages.
  538. File: emacs,  Node: Change Log,  Next: Tags,  Prev: Documentation,  Up: Programs
  539. Change Logs
  540. ===========
  541.    The Emacs command `C-x 4 a' adds a new entry to the change log file
  542. for the file you are editing (`add-change-log-entry-other-window').
  543.    A change log file contains a chronological record of when and why you
  544. have changed a program, consisting of a sequence of entries describing
  545. individual changes.  Normally it is kept in a file called `ChangeLog'
  546. in the same directory as the file you are editing, or one of its parent
  547. directories.  A single `ChangeLog' file can record changes for all the
  548. files in its directory and all its subdirectories.
  549.    A change log entry starts with a header line that contains your name,
  550. your email address (taken from the variable `user-mail-address'), and
  551. the current date and time.  Aside from these header lines, every line
  552. in the change log starts with a space or a tab.  The bulk of the entry
  553. consists of "items", each of which starts with a line starting with
  554. whitespace and a star.  Here are two entries, each with two items:
  555.      Wed May  5 14:11:45 1993  Richard Stallman  <rms@gnu.ai.mit.edu>
  556.      
  557.              * man.el: Rename symbols `man-*' to `Man-*'.
  558.              (manual-entry): Make prompt string clearer.
  559.      
  560.              * simple.el (blink-matching-paren-distance):
  561.              Change default to 12,000.
  562.      
  563.      Tue May  4 12:42:19 1993  Richard Stallman  <rms@gnu.ai.mit.edu>
  564.      
  565.              * vc.el (minor-mode-map-alist): Don't use it if it's void.
  566.              (vc-cancel-version): Doc fix.
  567.    One entry can describe several changes; each change should have its
  568. own item.  Normally there should be a blank line between items.  When
  569. items are related (parts of the same change, in different places), group
  570. them by leaving no blank line between them.  The second entry above
  571. contains two items grouped in this way.
  572.    `C-x 4 a' visits the change log file and creates a new entry unless
  573. the most recent entry is for today's date and your name.  It also
  574. creates a new item for the current file.  For many languages, it can
  575. even guess the name of the function or other object that was changed.
  576.    The change log file is visited in Change Log mode.  In this major
  577. mode, each bunch of grouped items counts as one paragraph, and each
  578. entry is considered a page.  This facilitates editing the entries.  LFD
  579. and auto-fill indent each new line like the previous line; this is
  580. convenient for entering the contents of an entry.
  581. File: emacs,  Node: Tags,  Next: Emerge,  Prev: Change Log,  Up: Programs
  582. Tags Tables
  583. ===========
  584.    A "tags table" is a description of how a multi-file program is
  585. broken up into files.  It lists the names of the component files and the
  586. names and positions of the functions (or other named subunits) in each
  587. file.  Grouping the related files makes it possible to search or replace
  588. through all the files with one command.  Recording the function names
  589. and positions makes possible the `M-.'  command which finds the
  590. definition of a function by looking up which of the files it is in.
  591.    Tags tables are stored in files called "tags table files".  The
  592. conventional name for a tags table file is `TAGS'.
  593.    Each entry in the tags table records the name of one tag, the name
  594. of the file that the tag is defined in (implicitly), and the position
  595. in that file of the tag's definition.
  596.    Just what names from the described files are recorded in the tags
  597. table depends on the programming language of the described file.  They
  598. normally include all functions and subroutines, and may also include
  599. global variables, data types, and anything else convenient.  Each name
  600. recorded is called a "tag".
  601. * Menu:
  602. * Tag Syntax::        Tag syntax for various types of code and text files.
  603. * Create Tags Table::    Creating a tags table with `etags'.
  604. * Select Tags Table::    How to visit a tags table.
  605. * Find Tag::        Commands to find the definition of a specific tag.
  606. * Tags Search::        Using a tags table for searching and replacing.
  607. * Tags Stepping::    Visiting files in a tags table, one by one.
  608. * List Tags::        Listing and finding tags defined in a file.
  609. File: emacs,  Node: Tag Syntax,  Next: Create Tags Table,  Up: Tags
  610. Source File Tag Syntax
  611. ----------------------
  612.    * In Lisp code, any function defined with `defun', any variable
  613.      defined with `defvar' or `defconst', and in general the first
  614.      argument of any expression that starts with `(def' in column zero,
  615.      is a tag.
  616.    * In Scheme code, tags include anything defined with `def' or with a
  617.      construct whose name starts with `def'.  They also include
  618.      variables set with `set!' at top level in the file.
  619.    * In C code, any C function or macro is a tag, and so is any typedef
  620.      if `-t' is specified when the tags table is constructed.  In C++
  621.      code, member functions are also recognized.
  622.    * In Yacc or Bison input files, each rule defines as a tag the
  623.      nonterminal it constructs.  The portions of the file that contain
  624.      C code are parsed as C code.
  625.    * In Fortran code, functions and subroutines are tags.
  626.    * In Pascal code, the tags are the functions and procedures defined
  627.      in the file.
  628.    * In Prolog code, a tag name appears at the left margin.
  629.    * In assembler code, labels appearing at the beginning of a line,
  630.      followed by a colon, are tags.
  631.    * In LaTeX text, the argument of any of the commands `\chapter',
  632.      `\section', `\subsection', `\subsubsection', `\eqno', `\label',
  633.      `\ref', `\cite', `\bibitem' and `\typeout' is a tag.
  634. File: emacs,  Node: Create Tags Table,  Next: Select Tags Table,  Prev: Tag Syntax,  Up: Tags
  635. Creating Tags Tables
  636. --------------------
  637.    The `etags' program is used to create a tags table file.  It knows
  638. the syntax of several languages, as described in *Note Tag Syntax::.
  639. Here is how to run `etags':
  640.      etags INPUTFILES...
  641. The `etags' program reads the specified files, and writes a tags table
  642. named `TAGS' in the current working directory.  `etags' recognizes the
  643. language used in an input file based on its file name and contents;
  644. there are no switches for specifying the language.
  645.    If the tags table data become outdated due to changes in the files
  646. described in the table, the way to update the tags table is the same
  647. way it was made in the first place.  It is not necessary to do this
  648. often.
  649.    If the tags table fails to record a tag, or records it for the wrong
  650. file, then Emacs cannot possibly find its definition.  However, if the
  651. position recorded in the tags table becomes a little bit wrong (due to
  652. some editing in the file that the tag definition is in), the only
  653. consequence is a slight delay in finding the tag.  Even if the stored
  654. position is very wrong, Emacs will still find the tag, but it must
  655. search the entire file for it.
  656.    So you should update a tags table when you define new tags that you
  657. want to have listed, or when you move tag definitions from one file to
  658. another, or when changes become substantial.  Normally there is no need
  659. to update the tags table after each edit, or even every day.
  660.    One tags table can effectively include another.  Specify the included
  661. tags file name with the `-include=FILE' option when creating the file
  662. that is to include it.  The latter file then acts as if it contained
  663. all the files specified in the included file, as well as the files it
  664. directly contains.
  665.    For a list of available `etags' options, type `etags --help'.
  666. File: emacs,  Node: Select Tags Table,  Next: Find Tag,  Prev: Create Tags Table,  Up: Tags
  667. Selecting a Tags Table
  668. ----------------------
  669.    Emacs has at any time one "selected" tags table, and all the commands
  670. for working with tags tables use the selected one.  To select a tags
  671. table, type `M-x visit-tags-table', which reads the tags table file
  672. name as an argument.  The name `TAGS' in the default directory is used
  673. as the default file name.
  674.    All this command does is store the file name in the variable
  675. `tags-file-name'.  Emacs does not actually read in the tags table
  676. contents until you try to use them.  Setting this variable yourself is
  677. just as good as using `visit-tags-table'.  The variable's initial value
  678. is `nil'; that value tells all the commands for working with tags tables
  679. that they must ask for a tags table file name to use.
  680.    Using `visit-tags-table' when a tags table is already loaded gives
  681. you a choice: you can add the new tags table to the current list of
  682. tags tables, or start a new list.  The tags commands use all the tags
  683. tables in the current list.  If you start a new list, the new tags table
  684. is used *instead* of others.  If you add the new table to the current
  685. list, it is used *as well as* the others.  When the tags commands scan
  686. the list of tags tables, they don't always start at the beginning of
  687. the list; they start with the first tags table (if any) that describes
  688. the current file, proceed from there to the end of the list, and then
  689. scan from the beginning of the list until they have covered all the
  690. tables in the list.
  691.    You can specify a precise list of tags tables by setting the variable
  692. `tags-table-list' to a list of strings, like this:
  693.      (setq tags-table-list
  694.            '("~/emacs" "/usr/local/lib/emacs/src"))
  695. This tells the tags commands to look at the `TAGS' files in your
  696. `~/emacs' directory and in the `/usr/local/lib/emacs/src' directory.
  697. The order depends on which file you are in and which tags table
  698. mentions that file, as explained above.
  699.    Do not set both `tags-file-name' and `tags-table-list'.
  700. File: emacs,  Node: Find Tag,  Next: Tags Search,  Prev: Select Tags Table,  Up: Tags
  701. Finding a Tag
  702. -------------
  703.    The most important thing that a tags table enables you to do is to
  704. find the definition of a specific tag.
  705. `M-. TAG RET'
  706.      Find first definition of TAG (`find-tag').
  707. `C-u M-.'
  708.      Find next alternate definition of last tag specified.
  709. `C-u - M-.'
  710.      Go back to previous tag found.
  711. `C-M-. PATTERN RET'
  712.      Find a tag whose name matches PATTERN (`find-tag-regexp').
  713. `C-u C-M-.'
  714.      Find the next tag whose name matches the last pattern used.
  715. `C-x 4 . TAG RET'
  716.      Find first definition of TAG, but display it in another window
  717.      (`find-tag-other-window').
  718. `C-x 5 . TAG RET'
  719.      Find first definition of TAG, and create a new frame to select the
  720.      buffer (`find-tag-other-frame').
  721.    `M-.' (`find-tag') is the command to find the definition of a
  722. specified tag.  It searches through the tags table for that tag, as a
  723. string, and then uses the tags table info to determine the file that the
  724. definition is in and the approximate character position in the file of
  725. the definition.  Then `find-tag' visits that file, moves point to the
  726. approximate character position, and searches ever-increasing distances
  727. away to find the tag definition.
  728.    If an empty argument is given (just type RET), the sexp in the
  729. buffer before or around point is used as the TAG argument.  *Note
  730. Lists::, for info on sexps.
  731.    You don't need to give `M-.' the full name of the tag; a part will
  732. do.  This is because `M-.' finds tags in the table which contain TAG as
  733. a substring.  However, it prefers an exact match to a substring match.
  734. To find other tags that match the same substring, give `find-tag' a
  735. numeric argument, as in `C-u M-.'; this does not read a tag name, but
  736. continues searching the tags table's text for another tag containing
  737. the same substring last used.  If you have a real META key, `M-0 M-.'
  738. is an easier alternative to `C-u M-.'.
  739.    Like most commands that can switch buffers, `find-tag' has a variant
  740. that displays the new buffer in another window, and one that makes a
  741. new frame for it.  The former is `C-x 4 .', which invokes the command
  742. `find-tag-other-window'.  The latter is `C-x 5 .', which invokes
  743. `find-tag-other-frame'.
  744.    To move back to places you've found tags recently, use `C-u - M-.';
  745. more generally, `M-.' with a negative numeric argument.  This command
  746. can take you to another buffer.  `C-x 4 .' with a negative argument
  747. finds the previous tag location in another window.
  748.    The command `C-M-.' (`find-tag-regexp') visits the tags that match a
  749. specified regular expression.  It is just like `M-.'  except that it
  750. does regexp matching instead of substring matching.
  751. File: emacs,  Node: Tags Search,  Next: Tags Stepping,  Prev: Find Tag,  Up: Tags
  752. Searching and Replacing with Tags Tables
  753. ----------------------------------------
  754.    The commands in this section visit and search all the files listed
  755. in the selected tags table, one by one.  For these commands, the tags
  756. table serves only to specify a sequence of files to search.
  757. `M-x tags-search RET REGEXP RET'
  758.      Search for REGEXP through the files in the selected tags table.
  759. `M-x tags-query-replace RET REGEXP RET REPLACEMENT RET'
  760.      Perform a `query-replace-regexp' on each file in the selected tags
  761.      table.
  762. `M-,'
  763.      Restart one of the commands above, from the current location of
  764.      point (`tags-loop-continue').
  765.    `M-x tags-search' reads a regexp using the minibuffer, then searches
  766. for matches in all the files in the selected tags table, one file at a
  767. time.  It displays the name of the file being searched so you can
  768. follow its progress.  As soon as it finds an occurrence, `tags-search'
  769. returns.
  770.    Having found one match, you probably want to find all the rest.  To
  771. find one more match, type `M-,' (`tags-loop-continue') to resume the
  772. `tags-search'.  This searches the rest of the current buffer, followed
  773. by the remaining files of the tags table.
  774.    `M-x tags-query-replace' performs a single `query-replace-regexp'
  775. through all the files in the tags table.  It reads a regexp to search
  776. for and a string to replace with, just like ordinary `M-x
  777. query-replace-regexp'.  It searches much like `M-x tags-search', but
  778. repeatedly, processing matches according to your input.  *Note
  779. Replace::, for more information on query replace.
  780.    It is possible to get through all the files in the tags table with a
  781. single invocation of `M-x tags-query-replace'.  But often it is useful
  782. to exit temporarily, which you can do with any input event that has no
  783. special query replace meaning.  You can resume the query replace
  784. subsequently by typing `M-,'; this command resumes the last tags search
  785. or replace command that you did.
  786.    The commands in this section carry out much broader searches than the
  787. `find-tags' family.  The `find-tags' commands search only for
  788. definitions of tags that match your substring or regexp.  The commands
  789. `tags-search' and `tags-query-replace' find every occurrence of the
  790. regexp, as ordinary search commands and replace commands do in the
  791. current buffer.
  792.    These commands create buffers only temporarily for the files that
  793. they have to search (those which are not already visited in Emacs
  794. buffers).  Buffers in which no match is found are quickly killed; the
  795. others continue to exist.
  796.    It may have struck you that `tags-search' is a lot like `grep'.  You
  797. can also run `grep' itself as an inferior of Emacs and have Emacs show
  798. you the matching lines one by one.  This works much like running a
  799. compilation; finding the source locations of the `grep' matches works
  800. like finding the compilation errors.  *Note Compilation::.
  801. File: emacs,  Node: Tags Stepping,  Next: List Tags,  Prev: Tags Search,  Up: Tags
  802. Stepping Through a Tags Table
  803. -----------------------------
  804.    If you wish to process all the files in the selected tags table, but
  805. not in the specific ways that `M-x tags-search' and `M-x
  806. tags-query-replace' do, you can use `M-x next-file' to visit the files
  807. one by one.
  808. `C-u M-x next-file'
  809.      Visit the first file in the tags table, and prepare to advance
  810.      sequentially by files.
  811. `M-x next-file'
  812.      Visit the next file in the selected tags table.
  813. File: emacs,  Node: List Tags,  Prev: Tags Stepping,  Up: Tags
  814. Tags Table Inquiries
  815. --------------------
  816. `M-x list-tags RET FILE RET'
  817.      Display a list of the tags defined in the program file `file'.
  818. `M-x tags-apropos RET REGEXP RET'
  819.      Display a list of all tags matching REGEXP.
  820.    `M-x list-tags' reads the name of one of the files described by the
  821. selected tags table, and displays a list of all the tags defined in that
  822. file.  The "file name" argument is really just a string to compare
  823. against the names recorded in the tags table; it is read as a string
  824. rather than as a file name.  Therefore, completion and defaulting are
  825. not available, and you must enter the string the same way it appears in
  826. the tags table.  Do not include a directory as part of the file name
  827. unless the file name recorded in the tags table includes a directory.
  828.    `M-x tags-apropos' is like `apropos' for tags (*note Apropos::.).
  829. It reads a regexp, then finds all the tags in the selected tags table
  830. whose entries match that regexp, and displays the tag names found.
  831.    You can also perform completion in the buffer on the name space of
  832. tag names in the current tags tables.  *Note Symbol Completion::.
  833. File: emacs,  Node: Emerge,  Next: C Mode,  Prev: Tags,  Up: Programs
  834. Merging Files with Emerge
  835. =========================
  836.    It's not unusual for programmers to get their signals crossed and
  837. modify the same program in two different directions.  To recover from
  838. this confusion, you need to merge the two versions.  Emerge makes this
  839. easier.  See also *Note Comparing Files::.
  840. * Menu:
  841. * Overview of Emerge::        How to start Emerge.  Basic concepts.
  842. * Submodes of Emerge::      Fast mode vs. Edit mode.
  843.                   Skip Prefers mode and Auto Advance mode.
  844. * State of Difference::        You do the merge by specifying state A or B
  845.                   for each difference.
  846. * Merge Commands::        Commands for selecting a difference,
  847.                   changing states of differences, etc.
  848. * Exiting Emerge::        What to do when you've finished the merge.
  849. * Combining in Emerge::        How to keep both alternatives for a difference.
  850. * Fine Points of Emerge::   Misc.
  851.