This commit was generated by cvs2svn to compensate for changes in r6453,
[chise/xemacs-chise.git.1] / info / xemacs.info-10
1 This is Info file ../../info/xemacs.info, produced by Makeinfo version
2 1.68 from the input file xemacs.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * XEmacs: (xemacs).             XEmacs Editor.
7 END-INFO-DIR-ENTRY
8
9    This file documents the XEmacs editor.
10
11    Copyright (C) 1985, 1986, 1988 Richard M. Stallman.  Copyright (C)
12 1991, 1992, 1993, 1994 Lucid, Inc.  Copyright (C) 1993, 1994 Sun
13 Microsystems, Inc.  Copyright (C) 1995 Amdahl Corporation.
14
15    Permission is granted to make and distribute verbatim copies of this
16 manual provided the copyright notice and this permission notice are
17 preserved on all copies.
18
19    Permission is granted to copy and distribute modified versions of
20 this manual under the conditions for verbatim copying, provided also
21 that the sections entitled "The GNU Manifesto", "Distribution" and "GNU
22 General Public License" are included exactly as in the original, and
23 provided that the entire resulting derived work is distributed under the
24 terms of a permission notice identical to this one.
25
26    Permission is granted to copy and distribute translations of this
27 manual into another language, under the above conditions for modified
28 versions, except that the sections entitled "The GNU Manifesto",
29 "Distribution" and "GNU General Public License" may be included in a
30 translation approved by the author instead of in the original English.
31
32 \1f
33 File: xemacs.info,  Node: Pages,  Next: Filling,  Prev: Paragraphs,  Up: Text
34
35 Pages
36 =====
37
38    Files are often thought of as divided into "pages" by the "formfeed"
39 character (ASCII Control-L, octal code 014).  For example, if a file is
40 printed on a line printer, each "page" of the file starts on a new page
41 of paper.  Emacs treats a page-separator character just like any other
42 character.  It can be inserted with `C-q C-l' or deleted with <DEL>.
43 You are free to paginate your file or not.  However, since pages are
44 often meaningful divisions of the file, commands are provided to move
45 over them and operate on them.
46
47 `C-x ['
48      Move point to previous page boundary (`backward-page').
49
50 `C-x ]'
51      Move point to next page boundary (`forward-page').
52
53 `C-x C-p'
54      Put point and mark around this page (or another page)
55      (`mark-page').
56
57 `C-x l'
58      Count the lines in this page (`count-lines-page').
59
60    The `C-x [' (`backward-page') command moves point to immediately
61 after the previous page delimiter.  If point is already right after a
62 page delimiter, the command skips that one and stops at the previous
63 one.  A numeric argument serves as a repeat count.  The `C-x ]'
64 (`forward-page') command moves forward past the next page delimiter.
65
66    The `C-x C-p' command (`mark-page') puts point at the beginning of
67 the current page and the mark at the end.  The page delimiter at the end
68 is included (the mark follows it).  The page delimiter at the front is
69 excluded (point follows it).  You can follow this command  by `C-w' to
70 kill a page you want to move elsewhere.  If you insert the page after a
71 page delimiter, at a place where `C-x ]' or `C-x [' would take you, the
72 page will be properly delimited before and after once again.
73
74    A numeric argument to `C-x C-p' is used to specify which page to go
75 to, relative to the current one.  Zero means the current page.  One
76 means the next page, and -1 means the previous one.
77
78    The `C-x l' command (`count-lines-page') can help you decide where
79 to break a page in two.  It prints the total number of lines in the
80 current page in the echo area, then divides the lines into those
81 preceding the current line and those following it, for example
82
83      Page has 96 (72+25) lines
84
85 Notice that the sum is off by one; this is correct if point is not at
86 the beginning of a line.
87
88    The variable `page-delimiter' should have as its value a regexp that
89 matches the beginning of a line that separates pages.  This defines
90 where pages begin.  The normal value of this variable is `"^\f"', which
91 matches a formfeed character at the beginning of a line.
92
93 \1f
94 File: xemacs.info,  Node: Filling,  Next: Case,  Prev: Pages,  Up: Text
95
96 Filling Text
97 ============
98
99    If you use Auto Fill mode, Emacs "fills" text (breaks it up into
100 lines that fit in a specified width) as you insert it.  When you alter
101 existing text it is often no longer be properly filled afterwards and
102 you can use explicit commands for filling.
103
104 * Menu:
105
106 * Auto Fill::     Auto Fill mode breaks long lines automatically.
107 * Fill Commands:: Commands to refill paragraphs and center lines.
108 * Fill Prefix::   Filling when every line is indented or in a comment, etc.
109
110 \1f
111 File: xemacs.info,  Node: Auto Fill,  Next: Fill Commands,  Prev: Filling,  Up: Filling
112
113 Auto Fill Mode
114 --------------
115
116    "Auto Fill" mode is a minor mode in which lines are broken
117 automatically when they become too wide.  Breaking happens only when
118 you type a <SPC> or <RET>.
119
120 `M-x auto-fill-mode'
121      Enable or disable Auto Fill mode.
122
123 `<SPC>'
124 `<RET>'
125      In Auto Fill mode, break lines when appropriate.
126
127    `M-x auto-fill-mode' turns Auto Fill mode on if it was off, or off
128 if it was on.  With a positive numeric argument the command always turns
129 Auto Fill mode on, and with a negative argument it always turns it off.
130 The presence of the word `Fill' in the mode line, inside the
131 parentheses, indicates that Auto Fill mode is in effect.  Auto Fill mode
132 is a minor mode; you can turn it on or off for each buffer individually.
133 *Note Minor Modes::.
134
135    In Auto Fill mode, lines are broken automatically at spaces when
136 they get longer than desired.  Line breaking and rearrangement takes
137 place only when you type <SPC> or <RET>.  To insert a space or newline
138 without permitting line-breaking, type `C-q <SPC>' or `C-q <LFD>'
139 (recall that a newline is really a linefeed).  `C-o' inserts a newline
140 without line breaking.
141
142    Auto Fill mode works well with Lisp mode: when it makes a new line in
143 Lisp mode, it indents that line with <TAB>.  If a line ending in a Lisp
144 comment gets too long, the text of the comment is split into two
145 comment lines.  Optionally, new comment delimiters are inserted at the
146 end of the first line and the beginning of the second, so that each line
147 is a separate comment.  The variable `comment-multi-line' controls the
148 choice (*note Comments::.).
149
150    Auto Fill mode does not refill entire paragraphs.  It can break
151 lines but cannot merge lines.  Editing in the middle of a paragraph can
152 result in a paragraph that is not correctly filled.  The easiest way to
153 make the paragraph properly filled again is using an explicit fill
154 commands.
155
156    Many users like Auto Fill mode and want to use it in all text files.
157 The section on init files explains how you can arrange this permanently
158 for yourself.  *Note Init File::.
159
160 \1f
161 File: xemacs.info,  Node: Fill Commands,  Next: Fill Prefix,  Prev: Auto Fill,  Up: Filling
162
163 Explicit Fill Commands
164 ----------------------
165
166 `M-q'
167      Fill current paragraph (`fill-paragraph').
168
169 `M-g'
170      Fill each paragraph in the region (`fill-region').
171
172 `C-x f'
173      Set the fill column (`set-fill-column').
174
175 `M-x fill-region-as-paragraph'
176      Fill the region, considering it as one paragraph.
177
178 `M-s'
179      Center a line.
180
181    To refill a paragraph, use the command `Meta-q' (`fill-paragraph').
182 It causes the paragraph containing point, or the one after point if
183 point is between paragraphs, to be refilled.  All line breaks are
184 removed, and new ones are inserted where necessary.  `M-q' can be
185 undone with `C-_'.  *Note Undo::.
186
187    To refill many paragraphs, use `M-g' (`fill-region'), which divides
188 the region into paragraphs and fills each of them.
189
190    `Meta-q' and `Meta-g' use the same criteria as `Meta-h' for finding
191 paragraph boundaries (*note Paragraphs::.).  For more control, you can
192 use `M-x fill-region-as-paragraph', which refills everything between
193 point and mark.  This command recognizes only blank lines as paragraph
194 separators.
195
196    A numeric argument to `M-g' or `M-q' causes it to "justify" the text
197 as well as filling it.  Extra spaces are inserted to make the right
198 margin line up exactly at the fill column.  To remove the extra spaces,
199 use `M-q' or `M-g' with no argument.
200
201    The variable `auto-fill-inhibit-regexp' takes as a value a regexp to
202 match lines that should not be auto-filled.
203
204    The command `Meta-s' (`center-line') centers the current line within
205 the current fill column.  With an argument, it centers several lines
206 individually and moves past them.
207
208    The maximum line width for filling is in the variable `fill-column'.
209 Altering the value of `fill-column' makes it local to the current
210 buffer; until then, the default value--initially 70--is in effect.
211 *Note Locals::.
212
213    The easiest way to set `fill-column' is to use the command `C-x f'
214 (`set-fill-column').  With no argument, it sets `fill-column' to the
215 current horizontal position of point.  With a numeric argument, it uses
216 that number as the new fill column.
217
218 \1f
219 File: xemacs.info,  Node: Fill Prefix,  Prev: Fill Commands,  Up: Filling
220
221 The Fill Prefix
222 ---------------
223
224    To fill a paragraph in which each line starts with a special marker
225 (which might be a few spaces, giving an indented paragraph), use the
226 "fill prefix" feature.  The fill prefix is a string which is not
227 included in filling.  Emacs expects every line to start with a fill
228 prefix.
229
230 `C-x .'
231      Set the fill prefix (`set-fill-prefix').
232
233 `M-q'
234      Fill a paragraph using current fill prefix (`fill-paragraph').
235
236 `M-x fill-individual-paragraphs'
237      Fill the region, considering each change of indentation as
238      starting a new paragraph.
239
240    To specify a fill prefix, move to a line that starts with the desired
241 prefix, put point at the end of the prefix, and give the command
242 `C-x .' (`set-fill-prefix').  That's a period after the `C-x'.  To turn
243 off the fill prefix, specify an empty prefix: type `C-x .' with point
244 at the beginning of a line.
245
246    When a fill prefix is in effect, the fill commands remove the fill
247 prefix from each line before filling and insert it on each line after
248 filling.  Auto Fill mode also inserts the fill prefix inserted on new
249 lines it creates.  Lines that do not start with the fill prefix are
250 considered to start paragraphs, both in `M-q' and the paragraph
251 commands; this is just right if you are using paragraphs with hanging
252 indentation (every line indented except the first one).  Lines which are
253 blank or indented once the prefix is removed also separate or start
254 paragraphs; this is what you want if you are writing multi-paragraph
255 comments with a comment delimiter on each line.
256
257    The fill prefix is stored in the variable `fill-prefix'.  Its value
258 is a string, or `nil' when there is no fill prefix.  This is a
259 per-buffer variable; altering the variable affects only the current
260 buffer, but there is a default value which you can change as well.
261 *Note Locals::.
262
263    Another way to use fill prefixes is through `M-x
264 fill-individual-paragraphs'.  This function divides the region into
265 groups of consecutive lines with the same amount and kind of
266 indentation and fills each group as a paragraph, using its indentation
267 as a fill prefix.
268
269 \1f
270 File: xemacs.info,  Node: Case,  Prev: Filling,  Up: Text
271
272 Case Conversion Commands
273 ========================
274
275    Emacs has commands for converting either a single word or any
276 arbitrary range of text to upper case or to lower case.
277
278 `M-l'
279      Convert following word to lower case (`downcase-word').
280
281 `M-u'
282      Convert following word to upper case (`upcase-word').
283
284 `M-c'
285      Capitalize the following word (`capitalize-word').
286
287 `C-x C-l'
288      Convert region to lower case (`downcase-region').
289
290 `C-x C-u'
291      Convert region to upper case (`upcase-region').
292
293    The word conversion commands are used most frequently.  `Meta-l'
294 (`downcase-word') converts the word after point to lower case, moving
295 past it.  Thus, repeating `Meta-l' converts successive words.  `Meta-u'
296 (`upcase-word') converts to all capitals instead, while `Meta-c'
297 (`capitalize-word') puts the first letter of the word into upper case
298 and the rest into lower case.  The word conversion commands convert
299 several words at once if given an argument.  They are especially
300 convenient for converting a large amount of text from all upper case to
301 mixed case: you can move through the text using `M-l', `M-u', or `M-c'
302 on each word as appropriate, occasionally using `M-f' instead to skip a
303 word.
304
305    When given a negative argument, the word case conversion commands
306 apply to the appropriate number of words before point, but do not move
307 point.  This is convenient when you have just typed a word in the wrong
308 case: you can give the case conversion command and continue typing.
309
310    If a word case conversion command is given in the middle of a word,
311 it applies only to the part of the word which follows point.  This is
312 just like what `Meta-d' (`kill-word') does.  With a negative argument,
313 case conversion applies only to the part of the word before point.
314
315    The other case conversion commands are `C-x C-u' (`upcase-region')
316 and `C-x C-l' (`downcase-region'), which convert everything between
317 point and mark to the specified case.  Point and mark do not move.
318
319 \1f
320 File: xemacs.info,  Node: Programs,  Next: Running,  Prev: Text,  Up: Top
321
322 Editing Programs
323 ****************
324
325    Emacs has many commands designed to understand the syntax of
326 programming languages such as Lisp and C.  These commands can:
327
328    * Move over or kill balanced expressions or "sexps" (*note Lists::.).
329
330    * Move over or mark top-level balanced expressions ("defuns", in
331      Lisp; functions, in C).
332
333    * Show how parentheses balance (*note Matching::.).
334
335    * Insert, kill, or align comments (*note Comments::.).
336
337    * Follow the usual indentation conventions of the language (*note
338      Grinding::.).
339
340    The commands available for words, sentences, and paragraphs are
341 useful in editing code even though their canonical application is for
342 editing human language text.  Most symbols contain words (*note
343 Words::.); sentences can be found in strings and comments (*note
344 Sentences::.).  Paragraphs per se are not present in code, but the
345 paragraph commands are useful anyway, because Lisp mode and C mode
346 define paragraphs to begin and end at blank lines (*note
347 Paragraphs::.).  Judicious use of blank lines to make the program
348 clearer also provides interesting chunks of text for the paragraph
349 commands to work on.
350
351    The selective display feature is useful for looking at the overall
352 structure of a function (*note Selective Display::.).  This feature
353 causes only the lines that are indented less than a specified amount to
354 appear on the screen.
355
356 * Menu:
357
358 * Program Modes::       Major modes for editing programs.
359 * Lists::               Expressions with balanced parentheses.
360                          There are editing commands to operate on them.
361 * Defuns::              Each program is made up of separate functions.
362                          There are editing commands to operate on them.
363 * Grinding::            Adjusting indentation to show the nesting.
364 * Matching::            Insertion of a close-delimiter flashes matching open.
365 * Comments::            Inserting, illing and aligning comments.
366 * Balanced Editing::    Inserting two matching parentheses at once, etc.
367 * Lisp Completion::     Completion on symbol names in Lisp code.
368 * Documentation::       Getting documentation of functions you plan to call.
369 * Change Log::          Maintaining a change history for your program.
370 * Tags::                Go direct to any function in your program in one
371                          command.  Tags remembers which file it is in.
372 * Fortran::             Fortran mode and its special features.
373 * Asm Mode::            Asm mode and its special features.
374
375 \1f
376 File: xemacs.info,  Node: Program Modes,  Next: Lists,  Prev: Programs,  Up: Programs
377
378 Major Modes for Programming Languages
379 =====================================
380
381    Emacs has several major modes for the programming languages Lisp,
382 Scheme (a variant of Lisp), C, Fortran, and Muddle.  Ideally, a major
383 mode should be implemented for each programming language you might want
384 to edit with Emacs; but often the mode for one language can serve for
385 other syntactically similar languages.  The language modes that exist
386 are those that someone decided to take the trouble to write.
387
388    There are several variants of Lisp mode, which differ in the way they
389 interface to Lisp execution.  *Note Lisp Modes::.
390
391    Each of the programming language modes defines the <TAB> key to run
392 an indentation function that knows the indentation conventions of that
393 language and updates the current line's indentation accordingly.  For
394 example, in C mode <TAB> is bound to `c-indent-line'.  <LFD> is
395 normally defined to do <RET> followed by <TAB>; thus it, too, indents
396 in a mode-specific fashion.
397
398    In most programming languages, indentation is likely to vary from
399 line to line.  So the major modes for those languages rebind <DEL> to
400 treat a tab as if it were the equivalent number of spaces (using the
401 command `backward-delete-char-untabify').  This makes it possible to
402 rub out indentation one column at a time without worrying whether it is
403 made up of spaces or tabs.  In these modes, use `C-b C-d' to delete a
404 tab character before point.
405
406    Programming language modes define paragraphs to be separated only by
407 blank lines, so that the paragraph commands remain useful.  Auto Fill
408 mode, if enabled in a programming language major mode, indents the new
409 lines which it creates.
410
411    Turning on a major mode calls a user-supplied function called the
412 "mode hook", which is the value of a Lisp variable.  For example,
413 turning on C mode calls the value of the variable `c-mode-hook' if that
414 value exists and is non-`nil'.  Mode hook variables for other
415 programming language modes include `lisp-mode-hook',
416 `emacs-lisp-mode-hook', `lisp-interaction-mode-hook',
417 `scheme-mode-hook', and `muddle-mode-hook'.  The mode hook function
418 receives no arguments.
419
420 \1f
421 File: xemacs.info,  Node: Lists,  Next: Defuns,  Prev: Program Modes,  Up: Programs
422
423 Lists and Sexps
424 ===============
425
426    By convention, Emacs keys for dealing with balanced expressions are
427 usually `Control-Meta-' characters.  They tend to be analogous in
428 function to their `Control-' and `Meta-' equivalents.  These commands
429 are usually thought of as pertaining to expressions in programming
430 languages, but can be useful with any language in which some sort of
431 parentheses exist (including English).
432
433    The commands fall into two classes.  Some commands deal only with
434 "lists" (parenthetical groupings).  They see nothing except
435 parentheses, brackets, braces (depending on what must balance in the
436 language you are working with), and escape characters that might be used
437 to quote those.
438
439    The other commands deal with expressions or "sexps".  The word `sexp'
440 is derived from "s-expression", the term for a symbolic expression in
441 Lisp.  In Emacs, the notion of `sexp' is not limited to Lisp.  It
442 refers to an expression in the language  your program is written in.
443 Each programming language has its own major mode, which customizes the
444 syntax tables so that expressions in that language count as sexps.
445
446    Sexps typically include symbols, numbers, and string constants, as
447 well as anything contained in parentheses, brackets, or braces.
448
449    In languages that use prefix and infix operators, such as C, it is
450 not possible for all expressions to be sexps.  For example, C mode does
451 not recognize `foo + bar' as an sexp, even though it is a C expression;
452 it recognizes `foo' as one sexp and `bar' as another, with the `+' as
453 punctuation between them.  This is a fundamental ambiguity: both `foo +
454 bar' and `foo' are legitimate choices for the sexp to move over if
455 point is at the `f'.  Note that `(foo + bar)' is a sexp in C mode.
456
457    Some languages have obscure forms of syntax for expressions that
458 nobody has bothered to make Emacs understand properly.
459
460 `C-M-f'
461      Move forward over an sexp (`forward-sexp').
462
463 `C-M-b'
464      Move backward over an sexp (`backward-sexp').
465
466 `C-M-k'
467      Kill sexp forward (`kill-sexp').
468
469 `C-M-u'
470      Move up and backward in list structure (`backward-up-list').
471
472 `C-M-d'
473      Move down and forward in list structure (`down-list').
474
475 `C-M-n'
476      Move forward over a list (`forward-list').
477
478 `C-M-p'
479      Move backward over a list (`backward-list').
480
481 `C-M-t'
482      Transpose expressions (`transpose-sexps').
483
484 `C-M-@'
485      Put mark after following expression (`mark-sexp').
486
487    To move forward over an sexp, use `C-M-f' (`forward-sexp').  If the
488 first significant character after point is an opening delimiter (`(' in
489 Lisp; `(', `[', or `{' in C), `C-M-f' moves past the matching closing
490 delimiter.  If the character begins a symbol, string, or number,
491 `C-M-f' moves over that.  If the character after point is a closing
492 delimiter, `C-M-f' just moves past it.  (This last is not really moving
493 across an sexp; it is an exception which is included in the definition
494 of `C-M-f' because it is as useful a behavior as anyone can think of
495 for that situation.)
496
497    The command `C-M-b' (`backward-sexp') moves backward over a sexp.
498 The detailed rules are like those above for `C-M-f', but with
499 directions reversed.  If there are any prefix characters (single quote,
500 back quote, and comma, in Lisp) preceding the sexp, `C-M-b' moves back
501 over them as well.
502
503    `C-M-f' or `C-M-b' with an argument repeats that operation the
504 specified number of times; with a negative argument, it moves in the
505 opposite direction.
506
507    In languages such as C where the comment-terminator can be
508 recognized, the sexp commands move across comments as if they were
509 whitespace.  In Lisp and other languages where comments run until the
510 end of a line, it is very difficult to ignore comments when parsing
511 backwards; therefore, in such languages the sexp commands treat the
512 text of comments as if it were code.
513
514    Killing an sexp at a time can be done with `C-M-k' (`kill-sexp').
515 `C-M-k' kills the characters that `C-M-f' would move over.
516
517    The "list commands", `C-M-n' (`forward-list') and `C-M-p'
518 (`backward-list'), move over lists like the sexp commands but skip over
519 any number of other kinds of sexps (symbols, strings, etc).  In some
520 situations, these commands are useful because they usually ignore
521 comments, since the comments usually do not contain any lists.
522
523    `C-M-n' and `C-M-p' stay at the same level in parentheses, when that
524 is possible.  To move up one (or N) levels, use `C-M-u'
525 (`backward-up-list').  `C-M-u' moves backward up past one unmatched
526 opening delimiter.  A positive argument serves as a repeat count; a
527 negative argument reverses direction of motion and also requests
528 repetition, so it moves forward and up one or more levels.
529
530    To move down in list structure, use `C-M-d' (`down-list').  In Lisp
531 mode, where `(' is the only opening delimiter, this is nearly the same
532 as searching for a `('.  An argument specifies the number of levels of
533 parentheses to go down.
534
535    `C-M-t' (`transpose-sexps') drags the previous sexp across the next
536 one.  An argument serves as a repeat count, and a negative argument
537 drags backwards (thus canceling out the effect of `C-M-t' with a
538 positive argument).  An argument of zero, rather than doing nothing,
539 transposes the sexps ending after point and the mark.
540
541    To make the region be the next sexp in the buffer, use `C-M-@'
542 (`mark-sexp') which sets the mark at the same place that `C-M-f' would
543 move to.  `C-M-@' takes arguments like `C-M-f'.  In particular, a
544 negative argument is useful for putting the mark at the beginning of
545 the previous sexp.
546
547    The list and sexp commands' understanding of syntax is completely
548 controlled by the syntax table.  Any character can, for example, be
549 declared to be an opening delimiter and act like an open parenthesis.
550 *Note Syntax::.
551
552 \1f
553 File: xemacs.info,  Node: Defuns,  Next: Grinding,  Prev: Lists,  Up: Programs
554
555 Defuns
556 ======
557
558    In Emacs, a parenthetical grouping at the top level in the buffer is
559 called a "defun".  The name derives from the fact that most top-level
560 lists in Lisp are instances of the special form `defun', but Emacs
561 calls any top-level parenthetical grouping counts a defun regardless of
562 its contents or the programming language.  For example, in C, the body
563 of a function definition is a defun.
564
565 `C-M-a'
566      Move to beginning of current or preceding defun
567      (`beginning-of-defun').
568
569 `C-M-e'
570      Move to end of current or following defun (`end-of-defun').
571
572 `C-M-h'
573      Put region around whole current or following defun (`mark-defun').
574
575    The commands to move to the beginning and end of the current defun
576 are `C-M-a' (`beginning-of-defun') and `C-M-e' (`end-of-defun').
577
578    To operate on the current defun, use `C-M-h' (`mark-defun') which
579 puts point at the beginning and the mark at the end of the current or
580 next defun.  This is the easiest way to prepare for moving the defun to
581 a different place.  In C mode, `C-M-h' runs the function
582 `mark-c-function', which is almost the same as `mark-defun', but which
583 backs up over the argument declarations, function name, and returned
584 data type so that the entire C function is inside the region.
585
586    To compile and evaluate the current defun, use `M-x compile-defun'.
587 This function prints the results in the minibuffer. If you include an
588 argument, it inserts the value in the current buffer after the defun.
589
590    Emacs assumes that any open-parenthesis found in the leftmost column
591 is the start of a defun.  Therefore, never put an open-parenthesis at
592 the left margin in a Lisp file unless it is the start of a top level
593 list.  Never put an open-brace or other opening delimiter at the
594 beginning of a line of C code unless it starts the body of a function.
595 The most likely problem case is when you want an opening delimiter at
596 the start of a line inside a string.  To avoid trouble, put an escape
597 character (`\' in C and Emacs Lisp, `/' in some other Lisp dialects)
598 before the opening delimiter.  It will not affect the contents of the
599 string.
600
601    The original Emacs found defuns by moving upward a level of
602 parentheses until there were no more levels to go up.  This required
603 scanning back to the beginning of the buffer for every function.  To
604 speed this up, Emacs was changed to assume that any `(' (or other
605 character assigned the syntactic class of opening-delimiter) at the
606 left margin is the start of a defun.  This heuristic is nearly always
607 right; however, it mandates the convention described above.
608
609 \1f
610 File: xemacs.info,  Node: Grinding,  Next: Matching,  Prev: Defuns,  Up: Programs
611
612 Indentation for Programs
613 ========================
614
615    The best way to keep a program properly indented ("ground") is to
616 use Emacs to re-indent it as you change the program.  Emacs has commands
617 to indent properly either a single line, a specified number of lines, or
618 all of the lines inside a single parenthetical grouping.
619
620 * Menu:
621
622 * Basic Indent::
623 * Multi-line Indent::   Commands to reindent many lines at once.
624 * Lisp Indent::         Specifying how each Lisp function should be indented.
625 * C Indent::            Choosing an indentation style for C code.
626
627 \1f
628 File: xemacs.info,  Node: Basic Indent,  Next: Multi-line Indent,  Prev: Grinding,  Up: Grinding
629
630 Basic Program Indentation Commands
631 ----------------------------------
632
633 `<TAB>'
634      Adjust indentation of current line.
635
636 `<LFD>'
637      Equivalent to <RET> followed by <TAB> (`newline-and-indent').
638
639    The basic indentation command is <TAB>, which gives the current line
640 the correct indentation as determined from the previous lines.  The
641 function that <TAB> runs depends on the major mode; it is
642 `lisp-indent-line' in Lisp mode, `c-indent-line' in C mode, etc.  These
643 functions understand different syntaxes for different languages, but
644 they all do about the same thing.  <TAB> in any programming language
645 major mode inserts or deletes whitespace at the beginning of the
646 current line, independent of where point is in the line.  If point is
647 inside the whitespace at the beginning of the line, <TAB> leaves it at
648 the end of that whitespace; otherwise, <TAB> leaves point fixed with
649 respect to the characters around it.
650
651    Use `C-q <TAB>' to insert a tab at point.
652
653    When entering a large amount of new code, use <LFD>
654 (`newline-and-indent'), which is equivalent to a <RET> followed by a
655 <TAB>.  <LFD> creates a blank line, then gives it the appropriate
656 indentation.
657
658    <TAB> indents the second and following lines of the body of a
659 parenthetical grouping each under the preceding one; therefore, if you
660 alter one line's indentation to be nonstandard, the lines below tend to
661 follow it.  This is the right behavior in cases where the standard
662 result of <TAB> does not look good.
663
664    Remember that Emacs assumes that an open-parenthesis, open-brace, or
665 other opening delimiter at the left margin (including the indentation
666 routines) is the start of a function.  You should therefore never have
667 an opening delimiter in column zero that is not the beginning of a
668 function, not even inside a string.  This restriction is vital for
669 making the indentation commands fast. *Note Defuns::, for more
670 information on this behavior.
671
672 \1f
673 File: xemacs.info,  Node: Multi-line Indent,  Next: Lisp Indent,  Prev: Basic Indent,  Up: Grinding
674
675 Indenting Several Lines
676 -----------------------
677
678    Several commands are available to re-indent several lines of code
679 which have been altered or moved to a different level in a list
680 structure.
681
682 `C-M-q'
683      Re-indent all the lines within one list (`indent-sexp').
684
685 `C-u <TAB>'
686      Shift an entire list rigidly sideways so that its first line is
687      properly indented.
688
689 `C-M-\'
690      Re-indent all lines in the region (`indent-region').
691
692    To re-indent the contents of a single list, position point before the
693 beginning of it and type `C-M-q'. This key is bound to `indent-sexp' in
694 Lisp mode, `indent-c-exp' in C mode, and bound to other suitable
695 functions in other modes.  The indentation of the line the sexp starts
696 on is not changed; therefore, only the relative indentation within the
697 list, and not its position, is changed.  To correct the position as
698 well, type a <TAB> before `C-M-q'.
699
700    If the relative indentation within a list is correct but the
701 indentation of its beginning is not, go to the line on which the list
702 begins and type `C-u <TAB>'.  When you give <TAB> a numeric argument,
703 it moves all the lines in the group, starting on the current line,
704 sideways the same amount that the current line moves.  The command does
705 not move lines that start inside strings, or C preprocessor lines when
706 in C mode.
707
708    Another way to specify a range to be re-indented is with point and
709 mark.  The command `C-M-\' (`indent-region') applies <TAB> to every
710 line whose first character is between point and mark.
711
712 \1f
713 File: xemacs.info,  Node: Lisp Indent,  Next: C Indent,  Prev: Multi-line Indent,  Up: Grinding
714
715 Customizing Lisp Indentation
716 ----------------------------
717
718    The indentation pattern for a Lisp expression can depend on the
719 function called by the expression.  For each Lisp function, you can
720 choose among several predefined patterns of indentation, or define an
721 arbitrary one with a Lisp program.
722
723    The standard pattern of indentation is as follows: the second line
724 of the expression is indented under the first argument, if that is on
725 the same line as the beginning of the expression; otherwise, the second
726 line is indented underneath the function name.  Each following line is
727 indented under the previous line whose nesting depth is the same.
728
729    If the variable `lisp-indent-offset' is non-`nil', it overrides the
730 usual indentation pattern for the second line of an expression, so that
731 such lines are always indented `lisp-indent-offset' more columns than
732 the containing list.
733
734    Certain functions override the standard pattern.  Functions whose
735 names start with `def' always indent the second line by
736 `lisp-body-indention' extra columns beyond the open-parenthesis
737 starting the expression.
738
739    Individual functions can override the standard pattern in various
740 ways, according to the `lisp-indent-function' property of the function
741 name.  (Note: `lisp-indent-function' was formerly called
742 `lisp-indent-hook').  There are four possibilities for this property:
743
744 `nil'
745      This is the same as no property; the standard indentation pattern
746      is used.
747
748 `defun'
749      The pattern used for function names that start with `def' is used
750      for this function also.
751
752 a number, NUMBER
753      The first NUMBER arguments of the function are "distinguished"
754      arguments; the rest are considered the "body" of the expression.
755      A line in the expression is indented according to whether the
756      first argument on it is distinguished or not.  If the argument is
757      part of the body, the line is indented `lisp-body-indent' more
758      columns than the open-parenthesis starting the containing
759      expression.  If the argument is distinguished and is either the
760      first or second argument, it is indented twice that many extra
761      columns.  If the argument is distinguished and not the first or
762      second argument, the standard pattern is followed for that line.
763
764 a symbol, SYMBOL
765      SYMBOL should be a function name; that function is called to
766      calculate the indentation of a line within this expression.  The
767      function receives two arguments:
768     STATE
769           The value returned by `parse-partial-sexp' (a Lisp primitive
770           for indentation and nesting computation) when it parses up to
771           the beginning of this line.
772
773     POS
774           The position at which the line being indented begins.
775
776      It should return either a number, which is the number of columns of
777      indentation for that line, or a list whose first element is such a
778      number.  The difference between returning a number and returning a
779      list is that a number says that all following lines at the same
780      nesting level should be indented just like this one; a list says
781      that following lines might call for different indentations.  This
782      makes a difference when the indentation is computed by `C-M-q'; if
783      the value is a number, `C-M-q' need not recalculate indentation
784      for the following lines until the end of the list.
785
786 \1f
787 File: xemacs.info,  Node: C Indent,  Prev: Lisp Indent,  Up: Grinding
788
789 Customizing C Indentation
790 -------------------------
791
792    Two variables control which commands perform C indentation and when.
793
794    If `c-auto-newline' is non-`nil', newlines are inserted both before
795 and after braces that you insert and after colons and semicolons.
796 Correct C indentation is done on all the lines that are made this way.
797
798    If `c-tab-always-indent' is non-`nil', the <TAB> command in C mode
799 does indentation only if point is at the left margin or within the
800 line's indentation.  If there is non-whitespace to the left of point,
801 <TAB> just inserts a tab character in the buffer.  Normally, this
802 variable is `nil', and <TAB> always reindents the current line.
803
804    C does not have anything analogous to particular function names for
805 which special forms of indentation are desirable.  However, it has a
806 different need for customization facilities: many different styles of C
807 indentation are in common use.
808
809    There are six variables you can set to control the style that Emacs C
810 mode will use.
811
812 `c-indent-level'
813      Indentation of C statements within surrounding block.  The
814      surrounding block's indentation is the indentation of the line on
815      which the open-brace appears.
816
817 `c-continued-statement-offset'
818      Extra indentation given to a substatement, such as the then-clause
819      of an `if' or body of a `while'.
820
821 `c-brace-offset'
822      Extra indentation for lines that start with an open brace.
823
824 `c-brace-imaginary-offset'
825      An open brace following other text is treated as if it were this
826      far to the right of the start of its line.
827
828 `c-argdecl-indent'
829      Indentation level of declarations of C function arguments.
830
831 `c-label-offset'
832      Extra indentation for a line that is a label, case, or default.
833
834    The variable `c-indent-level' controls the indentation for C
835 statements with respect to the surrounding block.  In the example:
836
837          {
838            foo ();
839
840 the difference in indentation between the lines is `c-indent-level'.
841 Its standard value is 2.
842
843    If the open-brace beginning the compound statement is not at the
844 beginning of its line, the `c-indent-level' is added to the indentation
845 of the line, not the column of the open-brace.  For example,
846
847      if (losing) {
848        do_this ();
849
850 One popular indentation style is that which results from setting
851 `c-indent-level' to 8 and putting open-braces at the end of a line in
852 this way.  Another popular style prefers to put the open-brace on a
853 separate line.
854
855    In fact, the value of the variable `c-brace-imaginary-offset' is
856 also added to the indentation of such a statement.  Normally this
857 variable is zero.  Think of this variable as the imaginary position of
858 the open brace, relative to the first non-blank character on the line.
859 By setting the variable to 4 and `c-indent-level' to 0, you can get
860 this style:
861
862      if (x == y) {
863          do_it ();
864          }
865
866    When `c-indent-level' is zero, the statements inside most braces
867 line up exactly under the open brace.  An exception are braces in column
868 zero, like those surrounding a function's body.  The statements inside
869 those braces are not placed at column zero.  Instead, `c-brace-offset'
870 and `c-continued-statement-offset' (see below) are added to produce a
871 typical offset between brace levels, and the statements are indented
872 that far.
873
874    `c-continued-statement-offset' controls the extra indentation for a
875 line that starts within a statement (but not within parentheses or
876 brackets).  These lines are usually statements inside other statements,
877 like the then-clauses of `if' statements and the bodies of `while'
878 statements.  The `c-continued-statement-offset' parameter determines
879 the difference in indentation between the two lines in:
880
881      if (x == y)
882        do_it ();
883
884 The default value for `c-continued-statement-offset' is 2.  Some
885 popular indentation styles correspond to a value of zero for
886 `c-continued-statement-offset'.
887
888    `c-brace-offset' is the extra indentation given to a line that
889 starts with an open-brace.  Its standard value is zero; compare:
890
891      if (x == y)
892        {
893
894 with:
895
896      if (x == y)
897        do_it ();
898
899 If you set `c-brace-offset' to 4, the first example becomes:
900
901      if (x == y)
902            {
903
904    `c-argdecl-indent' controls the indentation of declarations of the
905 arguments of a C function.  It is absolute: argument declarations
906 receive exactly `c-argdecl-indent' spaces.  The standard value is 5 and
907 results in code like this:
908
909      char *
910      index (string, char)
911           char *string;
912           int char;
913
914    `c-label-offset' is the extra indentation given to a line that
915 contains a label, a case statement, or a `default:' statement.  Its
916 standard value is -2 and results in code like this:
917
918      switch (c)
919        {
920        case 'x':
921
922 If `c-label-offset' were zero, the same code would be indented as:
923
924      switch (c)
925        {
926          case 'x':
927
928 This example assumes that the other variables above also have their
929 default values.
930
931    Using the indentation style produced by the default settings of the
932 variables just discussed and putting open braces on separate lines
933 produces clear and readable files.  For an example, look at any of the C
934 source files of XEmacs.
935
936 \1f
937 File: xemacs.info,  Node: Matching,  Next: Comments,  Prev: Grinding,  Up: Programs
938
939 Automatic Display of Matching Parentheses
940 =========================================
941
942    The Emacs parenthesis-matching feature shows you automatically how
943 parentheses match in the text.  Whenever a self-inserting character that
944 is a closing delimiter is typed, the cursor moves momentarily to the
945 location of the matching opening delimiter, provided that is visible on
946 the screen.  If it is not on the screen, some text starting with that
947 opening delimiter is displayed in the echo area.  Either way, you see
948 the grouping you are closing off.
949
950    In Lisp, automatic matching applies only to parentheses.  In C, it
951 also applies to braces and brackets.  Emacs knows which characters to
952 regard as matching delimiters based on the syntax table set by the major
953 mode.  *Note Syntax::.
954
955    If the opening delimiter and closing delimiter are mismatched--as in
956 `[x)'--the echo area displays a warning message.  The correct matches
957 are specified in the syntax table.
958
959    Two variables control parenthesis matching displays.
960 `blink-matching-paren' turns the feature on or off. The default is `t'
961 (match display is on); `nil' turns it off.
962 `blink-matching-paren-distance' specifies how many characters back
963 Emacs searches to find a matching opening delimiter.  If the match is
964 not found in the specified region, scanning stops, and nothing is
965 displayed.  This prevents wasting lots of time scanning when there is no
966 match.  The default is 4000.
967
968 \1f
969 File: xemacs.info,  Node: Comments,  Next: Balanced Editing,  Prev: Matching,  Up: Programs
970
971 Manipulating Comments
972 =====================
973
974    The comment commands insert, kill and align comments.
975
976 `M-;'
977      Insert or align comment (`indent-for-comment').
978
979 `C-x ;'
980      Set comment column (`set-comment-column').
981
982 `C-u - C-x ;'
983      Kill comment on current line (`kill-comment').
984
985 `M-<LFD>'
986      Like <RET> followed by inserting and aligning a comment
987      (`indent-new-comment-line').
988
989    The command that creates a comment is `Meta-;'
990 (`indent-for-comment').  If there is no comment already on the line, a
991 new comment is created and aligned at a specific column called the
992 "comment column".  Emacs creates the comment by inserting the string at
993 the value of `comment-start'; see below.  Point is left after that
994 string.  If the text of the line extends past the comment column,
995 indentation is done to a suitable boundary (usually, at least one space
996 is inserted).  If the major mode has specified a string to terminate
997 comments, that string is inserted after point, to keep the syntax valid.
998
999    You can also use `Meta-;' to align an existing comment.  If a line
1000 already contains the string that starts comments, `M-;' just moves
1001 point after it and re-indents it to the conventional place.  Exception:
1002 comments starting in column 0 are not moved.
1003
1004    Some major modes have special rules for indenting certain kinds of
1005 comments in certain contexts.  For example, in Lisp code, comments which
1006 start with two semicolons are indented as if they were lines of code,
1007 instead of at the comment column.  Comments which start with three
1008 semicolons are supposed to start at the left margin.  Emacs understands
1009 these conventions by indenting a double-semicolon comment using <TAB>
1010 and by not changing the indentation of a triple-semicolon comment at
1011 all.
1012
1013      ;; This function is just an example.
1014      ;;; Here either two or three semicolons are appropriate.
1015      (defun foo (x)
1016      ;;; And now, the first part of the function:
1017        ;; The following line adds one.
1018        (1+ x))           ; This line adds one.
1019
1020    In C code, a comment preceded on its line by nothing but whitespace
1021 is indented like a line of code.
1022
1023    Even when an existing comment is properly aligned, `M-;' is still
1024 useful for moving directly to the start of the comment.
1025
1026    `C-u - C-x ;' (`kill-comment') kills the comment on the current
1027 line, if there is one.  The indentation before the start of the comment
1028 is killed as well.  If there does not appear to be a comment in the
1029 line, nothing happens.  To reinsert the comment on another line, move
1030 to the end of that line, type first `C-y', and then `M-;' to realign
1031 the comment.  Note that `C-u - C-x ;' is not a distinct key; it is `C-x
1032 ;' (`set-comment-column') with a negative argument.  That command is
1033 programmed to call `kill-comment' when called with a negative argument.
1034 However, `kill-comment' is a valid command which you could bind
1035 directly to a key if you wanted to.
1036
1037 Multiple Lines of Comments
1038 --------------------------
1039
1040    If you are typing a comment and want to continue it on another line,
1041 use the command `Meta-<LFD>' (`indent-new-comment-line'), which
1042 terminates the comment you are typing, creates a new blank line
1043 afterward, and begins a new comment indented under the old one.  If
1044 Auto Fill mode is on and you go past the fill column while typing, the
1045 comment is continued in just this fashion.  If point is not at the end
1046 of the line when you type `M-<LFD>', the text on the rest of the line
1047 becomes part of the new comment line.
1048
1049 Options Controlling Comments
1050 ----------------------------
1051
1052    The comment column is stored in the variable `comment-column'.  You
1053 can explicitly set it to a number.  Alternatively, the command `C-x ;'
1054 (`set-comment-column') sets the comment column to the column point is
1055 at.  `C-u C-x ;' sets the comment column to match the last comment
1056 before point in the buffer, and then calls `Meta-;' to align the
1057 current line's comment under the previous one.  Note that `C-u - C-x ;'
1058 runs the function `kill-comment' as described above.
1059
1060    `comment-column' is a per-buffer variable; altering the variable
1061 affects only the current buffer.  You can also change the default value.
1062 *Note Locals::.  Many major modes initialize this variable for the
1063 current buffer.
1064
1065    The comment commands recognize comments based on the regular
1066 expression that is the value of the variable `comment-start-skip'.
1067 This regexp should not match the null string.  It may match more than
1068 the comment starting delimiter in the strictest sense of the word; for
1069 example, in C mode the value of the variable is `"/\\*+ *"', which
1070 matches extra stars and spaces after the `/*' itself.  (Note that `\\'
1071 is needed in Lisp syntax to include a `\' in the string, which is needed
1072 to deny the first star its special meaning in regexp syntax.  *Note
1073 Regexps::.)
1074
1075    When a comment command makes a new comment, it inserts the value of
1076 `comment-start' to begin it.  The value of `comment-end' is inserted
1077 after point and will follow the text you will insert into the comment.
1078 In C mode, `comment-start' has the value `"/* "' and `comment-end' has
1079 the value `" */"'.
1080
1081    `comment-multi-line' controls how `M-<LFD>'
1082 (`indent-new-comment-line') behaves when used inside a comment.  If
1083 `comment-multi-line' is `nil', as it normally is, then `M-<LFD>'
1084 terminates the comment on the starting line and starts a new comment on
1085 the new following line.  If `comment-multi-line' is not `nil', then
1086 `M-<LFD>' sets up the new following line as part of the same comment
1087 that was found on the starting line.  This is done by not inserting a
1088 terminator on the old line and not inserting a starter on the new line.
1089 In languages where multi-line comments are legal, the value you choose
1090 for this variable is a matter of taste.
1091
1092    The variable `comment-indent-hook' should contain a function that is
1093 called to compute the indentation for a newly inserted comment or for
1094 aligning an existing comment.  Major modes set this variable
1095 differently.  The function is called with no arguments, but with point
1096 at the beginning of the comment, or at the end of a line if a new
1097 comment is to be inserted.  The function should return the column in
1098 which the comment ought to start.  For example, in Lisp mode, the
1099 indent hook function bases its decision on the number of semicolons
1100 that begin an existing comment and on the code in the preceding lines.
1101
1102 \1f
1103 File: xemacs.info,  Node: Balanced Editing,  Next: Lisp Completion,  Prev: Comments,  Up: Programs
1104
1105 Editing Without Unbalanced Parentheses
1106 ======================================
1107
1108 `M-('
1109      Put parentheses around next sexp(s) (`insert-parentheses').
1110
1111 `M-)'
1112      Move past next close parenthesis and re-indent
1113      (`move-over-close-and-reindent').
1114
1115    The commands `M-(' (`insert-parentheses') and `M-)'
1116 (`move-over-close-and-reindent') are designed to facilitate a style of
1117 editing which keeps parentheses balanced at all times.  `M-(' inserts a
1118 pair of parentheses, either together as in `()', or, if given an
1119 argument, around the next several sexps, and leaves point after the open
1120 parenthesis.  Instead of typing `( F O O )', you can type `M-( F O O',
1121 which has the same effect except for leaving the cursor before the
1122 close parenthesis.  You can then type `M-)', which moves past the close
1123 parenthesis, deletes any indentation preceding it (in this example
1124 there is none), and indents with <LFD> after it.
1125
1126 \1f
1127 File: xemacs.info,  Node: Lisp Completion,  Next: Documentation,  Prev: Balanced Editing,  Up: Programs
1128
1129 Completion for Lisp Symbols
1130 ===========================
1131
1132    Completion usually happens in the minibuffer.  An exception is
1133 completion for Lisp symbol names, which is available in all buffers.
1134
1135    The command `M-<TAB>' (`lisp-complete-symbol') takes the partial
1136 Lisp symbol before point to be an abbreviation, and compares it against
1137 all non-trivial Lisp symbols currently known to Emacs.  Any additional
1138 characters that they all have in common are inserted at point.
1139 Non-trivial symbols are those that have function definitions, values, or
1140 properties.
1141
1142    If there is an open-parenthesis immediately before the beginning of
1143 the partial symbol, only symbols with function definitions are
1144 considered as completions.
1145
1146    If the partial name in the buffer has more than one possible
1147 completion and they have no additional characters in common, a list of
1148 all possible completions is displayed in another window.
1149
1150 \1f
1151 File: xemacs.info,  Node: Documentation,  Next: Change Log,  Prev: Lisp Completion,  Up: Programs
1152
1153 Documentation Commands
1154 ======================
1155
1156    As you edit Lisp code to be run in Emacs, you can use the commands
1157 `C-h f' (`describe-function') and `C-h v' (`describe-variable') to
1158 print documentation of functions and variables you want to call.  These
1159 commands use the minibuffer to read the name of a function or variable
1160 to document, and display the documentation in a window.
1161
1162    For extra convenience, these commands provide default arguments
1163 based on the code in the neighborhood of point.  `C-h f' sets the
1164 default to the function called in the innermost list containing point.
1165 `C-h v' uses the symbol name around or adjacent to point as its default.
1166
1167    The `M-x manual-entry' command gives you access to documentation on
1168 Unix commands, system calls, and libraries.  The command reads a topic
1169 as an argument, and displays the Unix manual page for that topic.
1170 `manual-entry' always searches all 8 sections of the manual and
1171 concatenates all the entries it finds.  For example, the topic
1172 `termcap' finds the description of the termcap library from section 3,
1173 followed by the description of the termcap data base from section 5.
1174