home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / E17INFO.ZIP / EMACS-9 < prev    next >
Encoding:
GNU Info File  |  1993-07-18  |  45.2 KB  |  1,085 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.54 from the
  2. input file emacs.texi.
  3.  
  4. 
  5. File: emacs,  Node: Outline Visibility,  Prev: Outline Motion,  Up: Outline Mode
  6.  
  7. Outline Visibility Commands
  8. ---------------------------
  9.  
  10.    The other special commands of outline mode are used to make lines
  11. visible or invisible.  Their names all start with `hide' or `show'.
  12. Most of them fall into pairs of opposites.  They are not undoable;
  13. instead, you can undo right past them.  Making lines visible or
  14. invisible is simply not recorded by the undo mechanism.
  15.  
  16. `M-x hide-body'
  17.      Make all body lines in the buffer invisible.
  18.  
  19. `M-x show-all'
  20.      Make all lines in the buffer visible.
  21.  
  22. `C-c C-h'
  23.      Make everything under this heading invisible, not including this
  24.      heading itself
  25.      (`hide-subtree').
  26.  
  27. `C-c C-s'
  28.      Make everything under this heading visible, including body,
  29.      subheadings, and their bodies (`show-subtree').
  30.  
  31. `M-x hide-leaves'
  32.      Make the body of this heading line, and of all its subheadings,
  33.      invisible.
  34.  
  35. `M-x show-branches'
  36.      Make all subheadings of this heading line, at all levels, visible.
  37.  
  38. `C-c C-i'
  39.      Make immediate subheadings (one level down) of this heading line
  40.      visible (`show-children').
  41.  
  42. `M-x hide-entry'
  43.      Make this heading line's body invisible.
  44.  
  45. `M-x show-entry'
  46.      Make this heading line's body visible.
  47.  
  48.    Two commands that are exact opposites are `M-x hide-entry' and `M-x
  49. show-entry'.  They are used with point on a heading line, and apply
  50. only to the body lines of that heading.  The subtopics and their bodies
  51. are not affected.
  52.  
  53.    Two more powerful opposites are `C-c C-h' (`hide-subtree') and `C-c
  54. C-s' (`show-subtree').  Both expect to be used when point is on a
  55. heading line, and both apply to all the lines of that heading's
  56. "subtree": its body, all its subheadings, both direct and indirect, and
  57. all of their bodies.  In other words, the subtree contains everything
  58. following this heading line, up to and not including the next heading of
  59. the same or higher rank.
  60.  
  61.    Intermediate between a visible subtree and an invisible one is having
  62. all the subheadings visible but none of the body.  There are two
  63. commands for doing this, depending on whether you want to hide the
  64. bodies or make the subheadings visible.  They are `M-x hide-leaves' and
  65. `M-x show-branches'.
  66.  
  67.    A little weaker than `show-branches' is `C-c C-i' (`show-children').
  68. It makes just the direct subheadings visible--those one level down.
  69. Deeper subheadings remain invisible, if they were invisible.
  70.  
  71.    Two commands have a blanket effect on the whole file.  `M-x
  72. hide-body' makes all body lines invisible, so that you see just the
  73. outline structure.  `M-x show-all' makes all lines visible.  These
  74. commands can be thought of as a pair of opposites even though `M-x
  75. show-all' applies to more than just body lines.
  76.  
  77.    You can turn off the use of ellipses at the ends of visible lines by
  78. setting `selective-display-ellipses' to `nil'.  Then there is no
  79. visible indication of the presence of invisible lines.
  80.  
  81. 
  82. File: emacs,  Node: TeX Mode,  Next: Nroff Mode,  Prev: Outline Mode,  Up: Text
  83.  
  84. TeX Mode
  85. ========
  86.  
  87.    TeX is a powerful text formatter written by Donald Knuth; it is also
  88. free, like GNU Emacs.  LaTeX is a simplified input format for TeX,
  89. implemented by TeX macros; it comes with TeX.  SliTeX is a special form
  90. of LaTeX.
  91.  
  92.    Emacs has a special TeX mode for editing TeX input files.  It
  93. provides facilities for checking the balance of delimiters and for
  94. invoking TeX on all or part of the file.
  95.  
  96.    TeX mode has three variants, Plain TeX mode, LaTeX mode, and SliTeX
  97. mode (these three distinct major modes differ only slightly).  They are
  98. designed for editing the three different formats.  The command `M-x
  99. tex-mode' looks at the contents of the buffer to determine whether the
  100. contents appear to be either LaTeX input or SliTeX input; it then
  101. selects the appropriate mode.  If it can't tell which is right (e.g.,
  102. the buffer is empty), the variable `tex-default-mode' controls which
  103. mode is used.
  104.  
  105.    When `M-x tex-mode' does not guess right, you can use the commands
  106. `M-x plain-tex-mode', `M-x latex-mode', and `M-x slitex-mode' to select
  107. explicitly the particular variants of TeX mode.
  108.  
  109. * Menu:
  110.  
  111. * Editing: TeX Editing.   Special commands for editing in TeX mode.
  112. * LaTeX: LaTeX Editing.   Additional commands for LaTeX input files.
  113. * Printing: TeX Print.    Commands for printing part of a file with TeX.
  114. * Getting: TeX Distrib.   Getting the latest Unix TeX distribution.
  115.  
  116. 
  117. File: emacs,  Node: TeX Editing,  Next: LaTeX Editing,  Up: TeX Mode
  118.  
  119. TeX Editing Commands
  120. --------------------
  121.  
  122.    Here are the special commands provided in TeX mode for editing the
  123. text of the file.
  124.  
  125. `"'
  126.      Insert, according to context, either ```' or `"' or `'''
  127.      (`tex-insert-quote').
  128.  
  129. `LFD'
  130.      Insert a paragraph break (two newlines) and check the previous
  131.      paragraph for unbalanced braces or dollar signs
  132.      (`tex-terminate-paragraph').
  133.  
  134. `M-x validate-tex-region'
  135.      Check each paragraph in the region for unbalanced braces or dollar
  136.      signs.
  137.  
  138. `C-c {'
  139.      Insert `{}' and position point between them (`tex-insert-braces').
  140.  
  141. `C-c }'
  142.      Move forward past the next unmatched close brace (`up-list').
  143.  
  144.    In TeX, the character `"' is not normally used; we use ```' to start
  145. a quotation and `''' to end one.  To make editing easier under this
  146. formatting convention, TeX mode overrides the normal meaning of the key
  147. `"' with a command that inserts a pair of single-quotes or backquotes
  148. (`tex-insert-quote').  To be precise, this command inserts ```' after
  149. whitespace or an open brace, `"' after a backslash, and `''' after any
  150. other character.
  151.  
  152.    If you need the character `"' itself in unusual contexts, use `C-q'
  153. to insert it.  Also, `"' with a numeric argument always inserts that
  154. number of `"' characters.
  155.  
  156.    In TeX mode, `$' has a special syntax code which attempts to
  157. understand the way TeX math mode delimiters match.  When you insert a
  158. `$' that is meant to exit math mode, the position of the matching `$'
  159. that entered math mode is displayed for a second.  This is the same
  160. feature that displays the open brace that matches a close brace that is
  161. inserted.  However, there is no way to tell whether a `$' enters math
  162. mode or leaves it; so when you insert a `$' that enters math mode, the
  163. previous `$' position is shown as if it were a match, even though they
  164. are actually unrelated.
  165.  
  166.    TeX uses braces as delimiters that must match.  Some users prefer to
  167. keep braces balanced at all times, rather than inserting them singly.
  168. Use `C-c {' (`tex-insert-braces') to insert a pair of braces.  It
  169. leaves point between the two braces so you can insert the text that
  170. belongs inside.  Afterward, use the command `C-c }' (`up-list') to move
  171. forward past the close brace.
  172.  
  173.    There are two commands for checking the matching of braces.  LFD
  174. (`tex-terminate-paragraph') checks the paragraph before point, and
  175. inserts two newlines to start a new paragraph.  It prints a message in
  176. the echo area if any mismatch is found.  `M-x validate-tex-region'
  177. checks a region, paragraph by paragraph.  When it finds a paragraph that
  178. contains a mismatch, it displays point at the beginning of the paragraph
  179. for a few seconds and pushes a mark at that spot.  Scanning continues
  180. until the whole buffer has been checked or until you type another key.
  181. The positions of the last several paragraphs with mismatches can be
  182. found in the mark ring (*note Mark Ring::.).
  183.  
  184.    Note that Emacs commands count square brackets and parentheses in
  185. TeX mode, not just braces.  This is not strictly correct for the
  186. purpose of checking TeX syntax.  However, parentheses and square
  187. brackets are likely to be used in text as matching delimiters and it is
  188. useful for the various motion commands and automatic match display to
  189. work with them.
  190.  
  191. 
  192. File: emacs,  Node: LaTeX Editing,  Next: TeX Print,  Prev: TeX Editing,  Up: TeX Mode
  193.  
  194. LaTeX Editing Commands
  195. ----------------------
  196.  
  197.    LaTeX mode provides a few extra features not applicable to plain TeX.
  198.  
  199. `C-c C-o'
  200.      Insert `\begin' and `\end' for LaTeX block and position point on a
  201.      line between them. (`tex-latex-block').
  202.  
  203. `C-c C-e'
  204.      Close the last unended block for LaTeX (`tex-close-latex-block').
  205.  
  206.    In LaTeX input, `\begin' and `\end' commands are used to group
  207. blocks of text.  To insert a `\begin' and a matching `\end' (on a new
  208. line following the `\begin'), use `C-c C-o' (`tex-latex-block').  A
  209. blank line is inserted between the two, and point is left there.
  210.  
  211.    Emacs knows all of the standard LaTeX block names and will
  212. permissively complete a partially entered block name (*note
  213. Completion::.).  You can add your own list of block names to those
  214. known by Emacs with the variable `latex-block-names'.  For example, to
  215. add `theorem', `corollary', and `proof', include the line
  216.  
  217.      (setq latex-block-names '("theorem" "corollary" "proof"))
  218.  
  219. to your `.emacs' file.
  220.  
  221.    In LaTeX input, `\begin' and `\end' commands must balance.  You can
  222. use `C-c C-e' (`tex-close-latex-block') to insert automatically a
  223. matching `\end' to match the last unmatched `\begin'.  The `\end' will
  224. be indented to match the corresponding `\begin'.  The `\end' will be
  225. followed by a newline if point is at the beginning of a line.
  226.  
  227. 
  228. File: emacs,  Node: TeX Print,  Next: TeX Distrib,  Prev: LaTeX Editing,  Up: TeX Mode
  229.  
  230. TeX Printing Commands
  231. ---------------------
  232.  
  233.    You can invoke TeX as an inferior of Emacs on either the entire
  234. contents of the buffer or just a region at a time.  Running TeX in this
  235. way on just one chapter is a good way to see what your changes look
  236. like without taking the time to format the entire file.
  237.  
  238. `C-c C-r'
  239.      Invoke TeX on the current region, together with the buffer's header
  240.      (`tex-region').
  241.  
  242. `C-c C-b'
  243.      Invoke TeX on the entire current buffer (`tex-buffer').
  244.  
  245. `C-c TAB'
  246.      Invoke BibTeX on the current file (`tex-bibtex-file').
  247.  
  248. `C-c C-f'
  249.      Invoke TeX on the current file (`tex-file').
  250.  
  251. `C-c C-l'
  252.      Recenter the window showing output from the inferior TeX so that
  253.      the last line can be seen (`tex-recenter-output-buffer').
  254.  
  255. `C-c C-k'
  256.      Kill the TeX subprocess (`tex-kill-job').
  257.  
  258. `C-c C-p'
  259.      Print the output from the last `C-c C-r', `C-c C-b', or `C-c C-f'
  260.      command (`tex-print').
  261.  
  262. `C-c C-v'
  263.      Preview the output from the last `C-c C-r', `C-c C-b', or `C-c
  264.      C-f' command (`tex-view').
  265.  
  266. `C-c C-q'
  267.      Show the printer queue (`tex-show-print-queue').
  268.  
  269.    You can pass the current buffer through an inferior TeX by means of
  270. `C-c C-b' (`tex-buffer').  The formatted output appears in a temporary;
  271. to print it, type `C-c C-p' (`tex-print').  Afterward use `C-c C-q'
  272. (`tex-show-print-queue') to view the progress of your output towards
  273. being printed. If your terminal has the ability to display TeX output
  274. files, you can preview the output on the terminal with `C-c C-v'
  275. (`tex-view').
  276.  
  277.    You can specify the directory to use for running TeX by setting the
  278. variable `tex-directory'.  `"."' is the default value.  If your
  279. environment variable `TEXINPUTS' contains relative directory names, or
  280. if your files contains `\input' commands with relative file names, then
  281. `tex-directory' *must* be `"."' or you will get the wrong results.
  282. Otherwise, it is safe to specify some other directory, such as `/tmp'.
  283.  
  284.    If you want to specify which shell commands are used in the inferior
  285. TeX, you can do so by setting the values of the variables
  286. `tex-run-command', `latex-run-command', `slitex-run-command',
  287. `tex-dvi-print-command', `tex-dvi-view-command', and
  288. `tex-show-queue-command'.  You *must* set the value of
  289. `tex-dvi-view-command' for your particular terminal; this variable has
  290. no default value.  The other variables have default values that may (or
  291. may not) be appropriate for your system.
  292.  
  293.    Normally, the file name given to these commands comes at the end of
  294. the command string; for example, `latex FILENAME'.  In some cases,
  295. however, the file name needs to be embedded in the command; an example
  296. is when you need to provide the file name as an argument to one command
  297. whose output is piped to another.  You can specify where to put the
  298. file name with `*' in the command string.  For example,
  299.  
  300.      (setq tex-dvi-print-command "dvips -f * | lpr")
  301.  
  302.    The terminal output from TeX, including any error messages, appears
  303. in a buffer called `*tex-shell*'.  If TeX gets an error, you can switch
  304. to this buffer and feed it input (this works as in Shell mode; *note
  305. Interactive Shell::.).  Without switching to this buffer you can scroll
  306. it so that its last line is visible by typing `C-c C-l'.
  307.  
  308.    Type `C-c C-k' (`tex-kill-job') to kill the TeX process if you see
  309. that its output is no longer useful.  Using `C-c C-b' or `C-c C-r' also
  310. kills any TeX process still running.
  311.  
  312.    You can also pass an arbitrary region through an inferior TeX by
  313. typing `C-c C-r' (`tex-region').  This is tricky, however, because most
  314. files of TeX input contain commands at the beginning to set parameters
  315. and define macros, without which no later part of the file will format
  316. correctly.  To solve this problem, `C-c C-r' allows you to designate a
  317. part of the file as containing essential commands; it is included before
  318. the specified region as part of the input to TeX.  The designated part
  319. of the file is called the "header".
  320.  
  321.    To indicate the bounds of the header in Plain TeX mode, you insert
  322. two special strings in the file.  Insert `%**start of header' before the
  323. header, and `%**end of header' after it.  Each string must appear
  324. entirely on one line, but there may be other text on the line before or
  325. after.  The lines containing the two strings are included in the header.
  326. If `%**start of header' does not appear within the first 100 lines of
  327. the buffer, `C-c C-r' assumes that there is no header.
  328.  
  329.    In LaTeX mode, the header begins with `\documentstyle' and ends with
  330. `\begin{document}'.  These are commands that LaTeX requires you to use
  331. in any case, so nothing special needs to be done to identify the header.
  332.  
  333.    The commands (`tex-buffer') and (`tex-region') do all of their work
  334. in a temporary directory, and do not have available any of the auxiliary
  335. files needed by TeX for cross-references; these commands are generally
  336. not suitable for running the final copy in which all of the
  337. cross-references need to be correct.  When you want the auxiliary
  338. files, use `C-c C-f' (`tex-file') which runs TeX on the current
  339. buffer's file, in that file's directory.  Before TeX runs, you will be
  340. asked about saving any modified buffers.  Generally, you need to use
  341. (`tex-file') twice to get cross-references correct.
  342.  
  343.    For LaTeX files, you can use BibTeX to process the auxiliary file
  344. for the current buffer's file.  BibTeX looks up bibliographic citations
  345. in a data base and prepares the cited references for the bibliography
  346. section.  The command `C-c TAB' (`tex-bibtex-file') runs the shell
  347. command (`tex-bibtex-command') to produce a `.bbl' file for the current
  348. buffer's file.  Generally, you need to do `C-c C-f' (`tex-file') once
  349. to generate the `.aux' file, then do `C-c TAB' (`tex-bibtex-file'), and
  350. then repeat `C-c C-f' (`tex-file') twice more to get the
  351. cross-references correct.
  352.  
  353.    Entering any kind of TeX mode runs the hooks `text-mode-hook' and
  354. `tex-mode-hook'.  Then it runs either `plain-tex-mode-hook' or
  355. `latex-mode-hook', whichever is appropriate.  For SliTeX files, it
  356. calls `slitex-mode-hook'.  Starting the TeX shell runs the hook
  357. `tex-shell-hook'.  *Note Hooks::.
  358.  
  359. 
  360. File: emacs,  Node: TeX Distrib,  Prev: TeX Print,  Up: TeX Mode
  361.  
  362. Unix TeX Distribution
  363. ---------------------
  364.  
  365.    TeX for Unix systems can be obtained from the University of
  366. Washington for a distribution fee.
  367.  
  368.    To order a full distribution, send $200.00 for a 1/2-inch 9-track
  369. 1600 bpi (tar or cpio) tape reel, or $210.00 for a 1/4-inch 4-track
  370. QIC-24 (tar or cpio) cartridge, payable to the University of Washington
  371. to:
  372.  
  373.      Northwest Computing Support Center
  374.      DR-10, Thomson Hall 35
  375.      University of Washington
  376.      Seattle, Washington 98195
  377.  
  378. Purchase orders are acceptable, but there is an extra charge of $10.00,
  379. to pay for processing charges.
  380.  
  381. For overseas orders please add $20.00 to the base cost for shipment via
  382. air parcel post, or $30.00 for shipment via courier.
  383.  
  384.    The normal distribution is a tar tape, blocked 20, 1600 bpi, on an
  385. industry standard 2400 foot half-inch reel.  The physical format for
  386. the 1/4 inch streamer cartridges uses QIC-11, 8000 bpi, 4-track
  387. serpentine recording for the SUN.  Also, System V tapes can be written
  388. in cpio format, blocked 5120 bytes, ASCII headers.
  389.  
  390. 
  391. File: emacs,  Node: Nroff Mode,  Prev: TeX Mode,  Up: Text
  392.  
  393. Nroff Mode
  394. ==========
  395.  
  396.    Nroff mode is a mode like Text mode but modified to handle nroff
  397. commands present in the text.  Invoke `M-x nroff-mode' to enter this
  398. mode.  It differs from Text mode in only a few ways.  All nroff command
  399. lines are considered paragraph separators, so that filling will never
  400. garble the nroff commands.  Pages are separated by `.bp' commands.
  401. Comments start with backslash-doublequote.  Also, three special
  402. commands are provided that are not in Text mode:
  403.  
  404. `M-n'
  405.      Move to the beginning of the next line that isn't an nroff command
  406.      (`forward-text-line').  An argument is a repeat count.
  407.  
  408. `M-p'
  409.      Like `M-n' but move up (`backward-text-line').
  410.  
  411. `M-?'
  412.      Prints in the echo area the number of text lines (lines that are
  413.      not nroff commands) in the region (`count-text-lines').
  414.  
  415.    The other feature of Nroff mode is that you can turn on Electric
  416. Nroff mode.  This is a minor mode that you can turn on or off with `M-x
  417. electric-nroff-mode' (*note Minor Modes::.).  When the mode is on, each
  418. time you use RET to end a line that contains an nroff command that
  419. opens a kind of grouping, the matching nroff command to close that
  420. grouping is automatically inserted on the following line.  For example,
  421. if you are at the beginning of a line and type `. ( b RET', this
  422. inserts the matching command `.)b' on a new line following point.
  423.  
  424.    Entering Nroff mode runs the hook `text-mode-hook', followed by the
  425. hook `nroff-mode-hook' (*note Hooks::.).
  426.  
  427. 
  428. File: emacs,  Node: Programs,  Next: Building,  Prev: Text,  Up: Top
  429.  
  430. Editing Programs
  431. ****************
  432.  
  433.    Emacs has many commands designed to understand the syntax of
  434. programming languages such as Lisp and C.  These commands can
  435.  
  436.    * Move over or kill balanced expressions or "sexps" (*note Lists::.).
  437.  
  438.    * Move over or mark top-level expressions--"defuns", in Lisp;
  439.      functions, in C (*note Defuns::.).
  440.  
  441.    * Show how parentheses balance (*note Matching::.).
  442.  
  443.    * Insert, kill or align comments (*note Comments::.).
  444.  
  445.    * Follow the usual indentation conventions of the language (*note
  446.      Program Indent::.).
  447.  
  448.    The commands for words, sentences and paragraphs are very useful in
  449. editing code even though their canonical application is for editing
  450. human language text.  Most symbols contain words (*note Words::.);
  451. sentences can be found in strings and comments (*note Sentences::.).
  452. Paragraphs per se don't exist in code, but the paragraph commands are
  453. useful anyway, because programming language major modes define
  454. paragraphs to begin and end at blank lines (*note Paragraphs::.).
  455. Judicious use of blank lines to make the program clearer will also
  456. provide interesting chunks of text for the paragraph commands to work
  457. on.
  458.  
  459.    The selective display feature is useful for looking at the overall
  460. structure of a function (*note Selective Display::.).  This feature
  461. causes only the lines that are indented less than a specified amount to
  462. appear on the screen.
  463.  
  464. * Menu:
  465.  
  466. * Program Modes::     Major modes for editing programs.
  467. * Lists::             Expressions with balanced parentheses.
  468. * List Commands::     The commands for working with list and sexps.
  469. * Defuns::            Each program is made up of separate functions.
  470.                         There are editing commands to operate on them.
  471. * Program Indent::    Adjusting indentation to show the nesting.
  472. * Matching::          Insertion of a close-delimiter flashes matching open.
  473. * Comments::          Inserting, killing, and aligning comments.
  474. * Balanced Editing::  Inserting two matching parentheses at once, etc.
  475. * Symbol Completion:: Completion on symbol names of your program or language.
  476. * Documentation::     Getting documentation of functions you plan to call.
  477. * Change Log::        Maintaining a change history for your program.
  478. * Tags::              Go direct to any function in your program in one
  479.                         command.  Tags remembers which file it is in.
  480. * Emerge::          A convenient way of merging two versions of a program.
  481. * C Mode::          Special commands of C mode (and C++ mode).
  482. * Fortran::          Fortran mode and its special features.
  483. * Asm Mode::          Asm mode and its special features.
  484.  
  485. 
  486. File: emacs,  Node: Program Modes,  Next: Lists,  Up: Programs
  487.  
  488. Major Modes for Programming Languages
  489. =====================================
  490.  
  491.    Emacs also has major modes for the programming languages Lisp, Scheme
  492. (a variant of Lisp), Awk, C, C++, Perl, Icon, Fortran and Muddle
  493. (another variant of Lisp).  There is also a major mode for makefiles,
  494. called Makefile mode.
  495.  
  496.    Ideally, a major mode should be implemented for each programming
  497. language that you might want to edit with Emacs; but often the mode for
  498. one language can serve for other syntactically similar languages.  The
  499. language modes that exist are those that someone decided to take the
  500. trouble to write.
  501.  
  502.    There are several forms of Lisp mode, which differ in the way they
  503. interface to Lisp execution.  *Note Executing Lisp::.
  504.  
  505.    Each of the programming language modes defines the TAB key to run an
  506. indentation function that knows the indentation conventions of that
  507. language and updates the current line's indentation accordingly.  For
  508. example, in C mode TAB is bound to `c-indent-line'.  LFD is normally
  509. defined to do RET followed by TAB; thus, it too indents in a
  510. mode-specific fashion.
  511.  
  512.    In most programming languages, indentation is likely to vary from
  513. line to line.  So the major modes for those languages rebind DEL to
  514. treat a tab as if it were the equivalent number of spaces (using the
  515. command `backward-delete-char-untabify').  This makes it possible to
  516. rub out indentation one column at a time without worrying whether it is
  517. made up of spaces or tabs.  Use `C-b C-d' to delete a tab character
  518. before point, in these modes.
  519.  
  520.    Programming language modes define paragraphs to be separated only by
  521. blank lines, so that the paragraph commands remain useful.  Auto Fill
  522. mode, if enabled in a programming language major mode, indents the new
  523. lines which it creates.
  524.  
  525.    Turning on a major mode runs a normal hook called the "mode hook",
  526. which is the value of a Lisp variable.  For example, turning on C mode
  527. runs the hook `c-mode-hook'.  Mode hook variables for other programming
  528. language modes include `lisp-mode-hook', `emacs-lisp-mode-hook',
  529. `lisp-interaction-mode-hook', `scheme-mode-hook' and
  530. `muddle-mode-hook'.  *Note Hooks::.
  531.  
  532. 
  533. File: emacs,  Node: Lists,  Next: List Commands,  Prev: Program Modes,  Up: Programs
  534.  
  535. Lists and Sexps
  536. ===============
  537.  
  538.    By convention, Emacs keys for dealing with balanced expressions are
  539. usually Control-Meta characters.  They tend to be analogous in function
  540. to their Control and Meta equivalents.  These commands are usually
  541. thought of as pertaining to expressions in programming languages, but
  542. can be useful with any language in which some sort of parentheses exist
  543. (including human languages).
  544.  
  545.    These commands fall into two classes.  Some deal only with "lists"
  546. (parenthetical groupings).  They see nothing except parentheses,
  547. brackets, braces (whichever ones must balance in the language you are
  548. working with), and escape characters that might be used to quote those.
  549.  
  550.    The other commands deal with expressions or "sexps".  The word `sexp'
  551. is derived from "s-expression", the ancient term for an expression in
  552. Lisp.  But in Emacs, the notion of `sexp' is not limited to Lisp.  It
  553. refers to an expression in whatever language your program is written in.
  554. Each programming language has its own major mode, which customizes the
  555. syntax tables so that expressions in that language count as sexps.
  556.  
  557.    Sexps typically include symbols, numbers, and string constants, as
  558. well as anything contained in parentheses, brackets or braces.
  559.  
  560.    In languages that use prefix and infix operators, such as C, it is
  561. not possible for all expressions to be sexps.  For example, C mode does
  562. not recognize `foo + bar' as a sexp, even though it *is* a C expression;
  563. it recognizes `foo' as one sexp and `bar' as another, with the `+' as
  564. punctuation between them.  This is a fundamental ambiguity: both `foo +
  565. bar' and `foo' are legitimate choices for the sexp to move over if
  566. point is at the `f'.  Note that `(foo + bar)' is a single sexp in C
  567. mode.
  568.  
  569.    Some languages have obscure forms of syntax for expressions that
  570. nobody has bothered to make Emacs understand properly.
  571.  
  572. 
  573. File: emacs,  Node: List Commands,  Next: Defuns,  Prev: Lists,  Up: Programs
  574.  
  575. List And Sexp Commands
  576. ======================
  577.  
  578. `C-M-f'
  579.      Move forward over a sexp (`forward-sexp').
  580.  
  581. `C-M-b'
  582.      Move backward over a sexp (`backward-sexp').
  583.  
  584. `C-M-k'
  585.      Kill sexp forward (`kill-sexp').
  586.  
  587. `C-M-u'
  588.      Move up and backward in list structure (`backward-up-list').
  589.  
  590. `C-M-d'
  591.      Move down and forward in list structure (`down-list').
  592.  
  593. `C-M-n'
  594.      Move forward over a list (`forward-list').
  595.  
  596. `C-M-p'
  597.      Move backward over a list (`backward-list').
  598.  
  599. `C-M-t'
  600.      Transpose expressions (`transpose-sexps').
  601.  
  602. `C-M-@'
  603.      Put mark after following expression (`mark-sexp').
  604.  
  605.    To move forward over a sexp, use `C-M-f' (`forward-sexp').  If the
  606. first significant character after point is an opening delimiter (`(' in
  607. Lisp; `(', `[' or `{' in C), `C-M-f' moves past the matching closing
  608. delimiter.  If the character begins a symbol, string, or number,
  609. `C-M-f' moves over that.
  610.  
  611.    The command `C-M-b' (`backward-sexp') moves backward over a sexp.
  612. The detailed rules are like those above for `C-M-f', but with
  613. directions reversed.  If there are any prefix characters (single-quote,
  614. backquote and comma, in Lisp) preceding the sexp, `C-M-b' moves back
  615. over them as well.  The sexp commands move across comments as if they
  616. were whitespace in most modes.
  617.  
  618.    `C-M-f' or `C-M-b' with an argument repeats that operation the
  619. specified number of times; with a negative argument, it moves in the
  620. opposite direction.
  621.  
  622.    Killing a sexp at a time can be done with `C-M-k' (`kill-sexp').
  623. `C-M-k' kills the characters that `C-M-f' would move over.
  624.  
  625.    The "list commands" move over lists like the sexp commands but skip
  626. blithely over any number of other kinds of sexps (symbols, strings,
  627. etc).  They are `C-M-n' (`forward-list') and `C-M-p' (`backward-list').
  628. The main reason they are useful is that they usually ignore comments
  629. (since the comments usually do not contain any lists).
  630.  
  631.    `C-M-n' and `C-M-p' stay at the same level in parentheses, when
  632. that's possible.  To move *up* one (or N) levels, use `C-M-u'
  633. (`backward-up-list').  `C-M-u' moves backward up past one unmatched
  634. opening delimiter.  A positive argument serves as a repeat count; a
  635. negative argument reverses direction of motion and also requests
  636. repetition, so it moves forward and up one or more levels.
  637.  
  638.    To move *down* in list structure, use `C-M-d' (`down-list').  In
  639. Lisp mode, where `(' is the only opening delimiter, this is nearly the
  640. same as searching for a `('.  An argument specifies the number of levels
  641. of parentheses to go down.
  642.  
  643.    A somewhat random-sounding command which is nevertheless handy is
  644. `C-M-t' (`transpose-sexps'), which drags the previous sexp across the
  645. next one.  An argument serves as a repeat count, and a negative
  646. argument drags backwards (thus canceling out the effect of `C-M-t' with
  647. a positive argument).  An argument of zero, rather than doing nothing,
  648. transposes the sexps ending after point and the mark.
  649.  
  650.    To make the region be the next sexp in the buffer, use `C-M-@'
  651. (`mark-sexp') which sets mark at the same place that `C-M-f' would move
  652. to.  `C-M-@' takes arguments like `C-M-f'.  In particular, a negative
  653. argument is useful for putting the mark at the beginning of the
  654. previous sexp.
  655.  
  656.    The list and sexp commands' understanding of syntax is completely
  657. controlled by the syntax table.  Any character can, for example, be
  658. declared to be an opening delimiter and act like an open parenthesis.
  659. *Note Syntax::.
  660.  
  661. 
  662. File: emacs,  Node: Defuns,  Next: Program Indent,  Prev: List Commands,  Up: Programs
  663.  
  664. Defuns
  665. ======
  666.  
  667.    In Emacs, a parenthetical grouping at the top level in the buffer is
  668. called a "defun".  The name derives from the fact that most top-level
  669. lists in a Lisp file are instances of the special form `defun', but any
  670. top-level parenthetical grouping counts as a defun in Emacs parlance
  671. regardless of what its contents are, and regardless of the programming
  672. language in use.  For example, in C, the body of a function definition
  673. is a defun.
  674.  
  675. `C-M-a'
  676.      Move to beginning of current or preceding defun
  677.      (`beginning-of-defun').
  678.  
  679. `C-M-e'
  680.      Move to end of current or following defun (`end-of-defun').
  681.  
  682. `C-M-h'
  683.      Put region around whole current or following defun (`mark-defun').
  684.  
  685.    The commands to move to the beginning and end of the current defun
  686. are `C-M-a' (`beginning-of-defun') and `C-M-e' (`end-of-defun').
  687.  
  688.    If you wish to operate on the current defun, use `C-M-h'
  689. (`mark-defun') which puts point at the beginning and mark at the end of
  690. the current or next defun.  For example, this is the easiest way to get
  691. ready to move the defun to a different place in the text.  In C mode,
  692. `C-M-h' runs the function `mark-c-function', which is almost the same
  693. as `mark-defun'; the difference is that it backs up over the argument
  694. declarations, function name and returned data type so that the entire C
  695. function is inside the region.  *Note Marking Objects::.
  696.  
  697.    Emacs assumes that any open-parenthesis found in the leftmost column
  698. is the start of a defun.  Therefore, *never put an open-parenthesis at
  699. the left margin in a Lisp file unless it is the start of a top level
  700. list.  Never put an open-brace or other opening delimiter at the
  701. beginning of a line of C code unless it starts the body of a function.*
  702. The most likely problem case is when you want an opening delimiter at
  703. the start of a line inside a string.  To avoid trouble, put an escape
  704. character (`\', in C and Emacs Lisp, `/' in some other Lisp dialects)
  705. before the opening delimiter.  It will not affect the contents of the
  706. string.
  707.  
  708.    In the remotest past, the original Emacs found defuns by moving
  709. upward a level of parentheses until there were no more levels to go up.
  710. This always required scanning all the way back to the beginning of the
  711. buffer, even for a small function.  To speed up the operation, Emacs
  712. was changed to assume that any `(' (or other character assigned the
  713. syntactic class of opening-delimiter) at the left margin is the start
  714. of a defun.  This heuristic is nearly always right and avoids the
  715. costly scan; however, it mandates the convention described above.
  716.  
  717. 
  718. File: emacs,  Node: Program Indent,  Next: Matching,  Prev: Defuns,  Up: Programs
  719.  
  720. Indentation for Programs
  721. ========================
  722.  
  723.    The best way to keep a program properly indented is to use Emacs to
  724. re-indent it as you change it.  Emacs has commands to indent properly
  725. either a single line, a specified number of lines, or all of the lines
  726. inside a single parenthetical grouping.
  727.  
  728. * Menu:
  729.  
  730. * Basic Indent::    Indenting a single line.
  731. * Multi-line Indent::   Commands to reindent many lines at once.
  732. * Lisp Indent::        Specifying how each Lisp function should be indented.
  733. * C Indent::        Choosing an indentation style for C code.
  734.  
  735. 
  736. File: emacs,  Node: Basic Indent,  Next: Multi-line Indent,  Up: Program Indent
  737.  
  738. Basic Program Indentation Commands
  739. ----------------------------------
  740.  
  741. `TAB'
  742.      Adjust indentation of current line.
  743.  
  744. `LFD'
  745.      Equivalent to RET followed by TAB (`newline-and-indent').
  746.  
  747.    The basic indentation command is TAB, which gives the current line
  748. the correct indentation as determined from the previous lines.  The
  749. function that TAB runs depends on the major mode; it is
  750. `lisp-indent-line' in Lisp mode, `c-indent-line' in C mode, etc.  These
  751. functions understand different syntaxes for different languages, but
  752. they all do about the same thing.  TAB in any programming language
  753. major mode inserts or deletes whitespace at the beginning of the
  754. current line, independent of where point is in the line.  If point is
  755. inside the whitespace at the beginning of the line, TAB leaves it at
  756. the end of that whitespace; otherwise, TAB leaves point fixed with
  757. respect to the characters around it.
  758.  
  759.    Use `C-q TAB' to insert a tab at point.
  760.  
  761.    When entering a large amount of new code, use LFD
  762. (`newline-and-indent'), which is equivalent to a RET followed by a TAB.
  763. LFD creates a blank line, and then gives it the appropriate
  764. indentation.
  765.  
  766.    TAB indents the second and following lines of the body of a
  767. parenthetical grouping each under the preceding one; therefore, if you
  768. alter one line's indentation to be nonstandard, the lines below will
  769. tend to follow it.  This is the right behavior in cases where the
  770. standard result of TAB is unaesthetic.
  771.  
  772.    Remember that an open-parenthesis, open-brace or other opening
  773. delimiter at the left margin is assumed by Emacs (including the
  774. indentation routines) to be the start of a function.  Therefore, you
  775. must never have an opening delimiter in column zero that is not the
  776. beginning of a function, not even inside a string.  This restriction is
  777. vital for making the indentation commands fast; you must simply accept
  778. it.  *Note Defuns::, for more information on this.
  779.  
  780. 
  781. File: emacs,  Node: Multi-line Indent,  Next: Lisp Indent,  Prev: Basic Indent,  Up: Program Indent
  782.  
  783. Indenting Several Lines
  784. -----------------------
  785.  
  786.    When you wish to re-indent several lines of code which have been
  787. altered or moved to a different level in the list structure, you have
  788. several commands available.
  789.  
  790. `C-M-q'
  791.      Re-indent all the lines within one list (`indent-sexp').
  792.  
  793. `C-u TAB'
  794.      Shift an entire list rigidly sideways so that its first line is
  795.      properly indented.
  796.  
  797. `C-M-\'
  798.      Re-indent all lines in the region (`indent-region').
  799.  
  800.    You can re-indent the contents of a single list by positioning point
  801. before the beginning of it and typing `C-M-q' (`indent-sexp' in Lisp
  802. mode, `indent-c-exp' in C mode; also bound to other suitable commands
  803. in other modes).  The indentation of the line the sexp starts on is not
  804. changed; therefore, only the relative indentation within the list, and
  805. not its position, is changed.  To correct the position as well, type a
  806. TAB before the `C-M-q'.
  807.  
  808.    If the relative indentation within a list is correct but the
  809. indentation of its beginning is not, go to the line the list begins on
  810. and type `C-u TAB'.  When TAB is given a numeric argument, it moves all
  811. the lines in the grouping starting on the current line sideways the
  812. same amount that the current line moves.  It is clever, though, and
  813. does not move lines that start inside strings, or C preprocessor lines
  814. when in C mode.
  815.  
  816.    Another way to specify the range to be re-indented is with point and
  817. mark.  The command `C-M-\' (`indent-region') applies TAB to every line
  818. whose first character is between point and mark.
  819.  
  820. 
  821. File: emacs,  Node: Lisp Indent,  Next: C Indent,  Prev: Multi-line Indent,  Up: Program Indent
  822.  
  823. Customizing Lisp Indentation
  824. ----------------------------
  825.  
  826.    The indentation pattern for a Lisp expression can depend on the
  827. function called by the expression.  For each Lisp function, you can
  828. choose among several predefined patterns of indentation, or define an
  829. arbitrary one with a Lisp program.
  830.  
  831.    The standard pattern of indentation is as follows: the second line
  832. of the expression is indented under the first argument, if that is on
  833. the same line as the beginning of the expression; otherwise, the second
  834. line is indented underneath the function name.  Each following line is
  835. indented under the previous line whose nesting depth is the same.
  836.  
  837.    If the variable `lisp-indent-offset' is non-`nil', it overrides the
  838. usual indentation pattern for the second line of an expression, so that
  839. such lines are always indented `lisp-indent-offset' more columns than
  840. the containing list.
  841.  
  842.    The standard pattern is overridden for certain functions.  Functions
  843. whose names start with `def' always indent the second line by
  844. `lisp-body-indent' extra columns beyond the open-parenthesis starting
  845. the expression.
  846.  
  847.    The standard pattern can be overridden in various ways for individual
  848. functions, according to the `lisp-indent-hook' property of the function
  849. name.  There are four possibilities for this property:
  850.  
  851. `nil'
  852.      This is the same as no property; the standard indentation pattern
  853.      is used.
  854.  
  855. `defun'
  856.      The pattern used for function names that start with `def' is used
  857.      for this function also.
  858.  
  859. a number, NUMBER
  860.      The first NUMBER arguments of the function are "distinguished"
  861.      arguments; the rest are considered the "body" of the expression.
  862.      A line in the expression is indented according to whether the
  863.      first argument on it is distinguished or not.  If the argument is
  864.      part of the body, the line is indented `lisp-body-indent' more
  865.      columns than the open-parenthesis starting the containing
  866.      expression.  If the argument is distinguished and is either the
  867.      first or second argument, it is indented *twice* that many extra
  868.      columns.  If the argument is distinguished and not the first or
  869.      second argument, the standard pattern is followed for that line.
  870.  
  871. a symbol, SYMBOL
  872.      SYMBOL should be a function name; that function is called to
  873.      calculate the indentation of a line within this expression.  The
  874.      function receives two arguments:
  875.     STATE
  876.           The value returned by `parse-partial-sexp' (a Lisp primitive
  877.           for indentation and nesting computation) when it parses up to
  878.           the beginning of this line.
  879.  
  880.     POS
  881.           The position at which the line being indented begins.
  882.  
  883.      It should return either a number, which is the number of columns of
  884.      indentation for that line, or a list whose car is such a number.
  885.      The difference between returning a number and returning a list is
  886.      that a number says that all following lines at the same nesting
  887.      level should be indented just like this one; a list says that
  888.      following lines might call for different indentations.  This makes
  889.      a difference when the indentation is being computed by `C-M-q'; if
  890.      the value is a number, `C-M-q' need not recalculate indentation
  891.      for the following lines until the end of the list.
  892.  
  893. 
  894. File: emacs,  Node: C Indent,  Prev: Lisp Indent,  Up: Program Indent
  895.  
  896. Customizing C Indentation
  897. -------------------------
  898.  
  899.    Two variables control which commands perform C indentation and when.
  900.  
  901.    If `c-auto-newline' is non-`nil', newlines are inserted both before
  902. and after braces that you insert, and after colons and semicolons.
  903. Correct C indentation is done on all the lines that are made this way.
  904.  
  905.    If `c-tab-always-indent' is `nil', the TAB command in C mode does
  906. indentation only if point is at the left margin or within the line's
  907. indentation.  If there is non-whitespace to the left of point, then TAB
  908. just inserts a tab character in the buffer.  Normally, this variable is
  909. `t', and TAB always reindents the current line.  The default behavior
  910. means that to insert a real tab character you must quote it by typing
  911. `C-q' TAB.
  912.  
  913.    C does not have anything analogous to particular function names for
  914. which special forms of indentation are desirable.  However, it has a
  915. different need for customization facilities: many different styles of C
  916. indentation are in common use.
  917.  
  918.    There are six variables you can set to control the style that Emacs C
  919. mode uses.
  920.  
  921. `c-indent-level'
  922.      Indentation of C statements within surrounding block.  The
  923.      surrounding block's indentation is the indentation of the line on
  924.      which the open-brace appears.
  925.  
  926. `c-continued-statement-offset'
  927.      Extra indentation given to a substatement, such as the then-clause
  928.      of an if or body of a while.
  929.  
  930. `c-brace-offset'
  931.      Extra indentation for line if it starts with an open brace.
  932.  
  933. `c-brace-imaginary-offset'
  934.      An open brace following other text is treated as if it were this
  935.      far to the right of the start of its line.
  936.  
  937. `c-argdecl-indent'
  938.      Indentation level of declarations of C function arguments.
  939.  
  940. `c-label-offset'
  941.      Extra indentation for line that is a label, or case or default.
  942.  
  943.    The variable `c-indent-level' controls the indentation for C
  944. statements with respect to the surrounding block.  In the example
  945.  
  946.          {
  947.            foo ();
  948.  
  949. the difference in indentation between the lines is `c-indent-level'.
  950. Its standard value is 2.
  951.  
  952.    If the open-brace beginning the compound statement is not at the
  953. beginning of its line, the `c-indent-level' is added to the indentation
  954. of the line, not the column of the open-brace.  For example,
  955.  
  956.      if (losing) {
  957.        do_this ();
  958.  
  959. One popular indentation style is that which results from setting
  960. `c-indent-level' to 8 and putting open-braces at the end of a line in
  961. this way.  I prefer to put the open-brace on a separate line.
  962.  
  963.    In fact, the value of the variable `c-brace-imaginary-offset' is
  964. also added to the indentation of such a statement.  Normally this
  965. variable is zero.  Think of this variable as the imaginary position of
  966. the open brace, relative to the first nonblank character on the line.
  967. By setting this variable to 4 and `c-indent-level' to 0, you can get
  968. this style:
  969.  
  970.      if (x == y) {
  971.          do_it ();
  972.          }
  973.  
  974.    When `c-indent-level' is zero, the statements inside most braces
  975. will line up right under the open brace.  But there is an exception made
  976. for braces in column zero, such as surrounding a function's body.  The
  977. statements just inside it do not go at column zero.  Instead,
  978. `c-brace-offset' and `c-continued-statement-offset' (see below) are
  979. added to produce a typical offset between brace levels, and the
  980. statements are indented that far.
  981.  
  982.    `c-continued-statement-offset' controls the extra indentation for a
  983. line that starts within a statement (but not within parentheses or
  984. brackets).  These lines are usually statements that are within other
  985. statements, such as the then-clauses of `if' statements and the bodies
  986. of `while' statements.  This parameter is the difference in indentation
  987. between the two lines in
  988.  
  989.      if (x == y)
  990.        do_it ();
  991.  
  992. Its standard value is 2.  Some popular indentation styles correspond to
  993. a value of zero for `c-continued-statement-offset'.
  994.  
  995.    `c-brace-offset' is the extra indentation given to a line that
  996. starts with an open-brace.  Its standard value is zero; compare
  997.  
  998.      if (x == y)
  999.        {
  1000.  
  1001. with
  1002.  
  1003.      if (x == y)
  1004.        do_it ();
  1005.  
  1006. if `c-brace-offset' were set to 4, the first example would become
  1007.  
  1008.      if (x == y)
  1009.            {
  1010.  
  1011.    `c-argdecl-indent' controls the indentation of declarations of the
  1012. arguments of a C function.  It is absolute: argument declarations
  1013. receive exactly `c-argdecl-indent' spaces.  The standard value is 5,
  1014. resulting in code like this:
  1015.  
  1016.      char *
  1017.      index (string, c)
  1018.           char *string;
  1019.           int c;
  1020.  
  1021.    `c-label-offset' is the extra indentation given to a line that
  1022. contains a label, a case statement, or a `default:' statement.  Its
  1023. standard value is -2, resulting in code like this
  1024.  
  1025.      switch (c)
  1026.        {
  1027.        case 'x':
  1028.  
  1029. If `c-label-offset' were zero, the same code would be indented as
  1030.  
  1031.      switch (c)
  1032.        {
  1033.          case 'x':
  1034.  
  1035. This example assumes that the other variables above also have their
  1036. standard values.
  1037.  
  1038.    I strongly recommend that you try out the indentation style produced
  1039. by the standard settings of these variables, together with putting open
  1040. braces on separate lines.  You can see how it looks in all the C source
  1041. files of GNU Emacs.
  1042.  
  1043. 
  1044. File: emacs,  Node: Matching,  Next: Comments,  Prev: Program Indent,  Up: Programs
  1045.  
  1046. Automatic Display Of Matching Parentheses
  1047. =========================================
  1048.  
  1049.    The Emacs parenthesis-matching feature is designed to show
  1050. automatically how parentheses match in the text.  Whenever you type a
  1051. self-inserting character that is a closing delimiter, the cursor moves
  1052. momentarily to the location of the matching opening delimiter, provided
  1053. that is on the screen.  If it is not on the screen, some text near it is
  1054. displayed in the echo area.  Either way, you can tell what grouping is
  1055. being closed off.
  1056.  
  1057.    In Lisp, automatic matching applies only to parentheses.  In C, it
  1058. applies to braces and brackets too.  Emacs knows which characters to
  1059. regard as matching delimiters based on the syntax table, which is set
  1060. by the major mode.  *Note Syntax::.
  1061.  
  1062.    If the opening delimiter and closing delimiter are mismatched--such
  1063. as in `[x)'--a warning message is displayed in the echo area.  The
  1064. correct matches are specified in the syntax table.
  1065.  
  1066.    Two variables control parenthesis match display.
  1067. `blink-matching-paren' turns the feature on or off; `nil' turns it off,
  1068. but the default is `t' to turn match display on.
  1069. `blink-matching-paren-distance' specifies how many characters back to
  1070. search to find the matching opening delimiter.  If the match is not
  1071. found in that far, scanning stops, and nothing is displayed.  This is
  1072. to prevent scanning for the matching delimiter from wasting lots of
  1073. time when there is no match.  The default is 12,000.
  1074.  
  1075.    When using X Windows, you can request a more powerful kind of
  1076. automatic parenthesis matching by loading the `paren' library.  To load
  1077. it, type `M-x load-library RET paren RET'.  This library turns off the
  1078. usual kind of matching parenthesis display and substitutes another:
  1079. whenever point is after a close parenthesis, the close parenthesis and
  1080. its matching open parenthesis are both highlighted; otherwise, if point
  1081. is before an open parenthesis, the matching close parenthesis is
  1082. highlighted.  (There is no need to highlight the open parenthesis after
  1083. point because the cursor appears on top of that character.)
  1084.  
  1085.