8e0ab08a16baa780203bb87a802716dbd9e64b54
[chise/xemacs-chise.git-] / info / xemacs.info-11
1 This is ../info/xemacs.info, produced by makeinfo version 4.0 from
2 xemacs/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 Paragraphs::).
347 Judicious use of blank lines to make the program clearer also provides
348 interesting chunks of text for the paragraph commands to work on.
349
350    The selective display feature is useful for looking at the overall
351 structure of a function (*note Selective Display::).  This feature
352 causes only the lines that are indented less than a specified amount to
353 appear on the screen.
354
355 * Menu:
356
357 * Program Modes::       Major modes for editing programs.
358 * Lists::               Expressions with balanced parentheses.
359                          There are editing commands to operate on them.
360 * Defuns::              Each program is made up of separate functions.
361                          There are editing commands to operate on them.
362 * Grinding::            Adjusting indentation to show the nesting.
363 * Matching::            Insertion of a close-delimiter flashes matching open.
364 * Comments::            Inserting, filling and aligning comments.
365 * Balanced Editing::    Inserting two matching parentheses at once, etc.
366 * Lisp Completion::     Completion on symbol names in Lisp code.
367 * Documentation::       Getting documentation of functions you plan to call.
368 * Change Log::          Maintaining a change history for your program.
369 * Tags::                Go direct to any function in your program in one
370                          command.  Tags remembers which file it is in.
371 * Fortran::             Fortran mode and its special features.
372 * Asm Mode::            Asm mode and its special features.
373
374 \1f
375 File: xemacs.info,  Node: Program Modes,  Next: Lists,  Prev: Programs,  Up: Programs
376
377 Major Modes for Programming Languages
378 =====================================
379
380    Emacs has several major modes for the programming languages Lisp,
381 Scheme (a variant of Lisp), C, Fortran, and Muddle.  Ideally, a major
382 mode should be implemented for each programming language you might want
383 to edit with Emacs; but often the mode for one language can serve for
384 other syntactically similar languages.  The language modes that exist
385 are those that someone decided to take the trouble to write.
386
387    There are several variants of Lisp mode, which differ in the way they
388 interface to Lisp execution.  *Note Lisp Modes::.
389
390    Each of the programming language modes defines the <TAB> key to run
391 an indentation function that knows the indentation conventions of that
392 language and updates the current line's indentation accordingly.  For
393 example, in C mode <TAB> is bound to `c-indent-line'.  <LFD> is
394 normally defined to do <RET> followed by <TAB>; thus it, too, indents
395 in a mode-specific fashion.
396
397    In most programming languages, indentation is likely to vary from
398 line to line.  So the major modes for those languages rebind <DEL> to
399 treat a tab as if it were the equivalent number of spaces (using the
400 command `backward-delete-char-untabify').  This makes it possible to
401 rub out indentation one column at a time without worrying whether it is
402 made up of spaces or tabs.  In these modes, use `C-b C-d' to delete a
403 tab character before point.
404
405    Programming language modes define paragraphs to be separated only by
406 blank lines, so that the paragraph commands remain useful.  Auto Fill
407 mode, if enabled in a programming language major mode, indents the new
408 lines which it creates.
409
410    Turning on a major mode calls a user-supplied function called the
411 "mode hook", which is the value of a Lisp variable.  For example,
412 turning on C mode calls the value of the variable `c-mode-hook' if that
413 value exists and is non-`nil'.  Mode hook variables for other
414 programming language modes include `lisp-mode-hook',
415 `emacs-lisp-mode-hook', `lisp-interaction-mode-hook',
416 `scheme-mode-hook', and `muddle-mode-hook'.  The mode hook function
417 receives no arguments.
418
419 \1f
420 File: xemacs.info,  Node: Lists,  Next: Defuns,  Prev: Program Modes,  Up: Programs
421
422 Lists and Sexps
423 ===============
424
425    By convention, Emacs keys for dealing with balanced expressions are
426 usually `Control-Meta-' characters.  They tend to be analogous in
427 function to their `Control-' and `Meta-' equivalents.  These commands
428 are usually thought of as pertaining to expressions in programming
429 languages, but can be useful with any language in which some sort of
430 parentheses exist (including English).
431
432    The commands fall into two classes.  Some commands deal only with
433 "lists" (parenthetical groupings).  They see nothing except
434 parentheses, brackets, braces (depending on what must balance in the
435 language you are working with), and escape characters that might be used
436 to quote those.
437
438    The other commands deal with expressions or "sexps".  The word `sexp'
439 is derived from "s-expression", the term for a symbolic expression in
440 Lisp.  In Emacs, the notion of `sexp' is not limited to Lisp.  It
441 refers to an expression in the language  your program is written in.
442 Each programming language has its own major mode, which customizes the
443 syntax tables so that expressions in that language count as sexps.
444
445    Sexps typically include symbols, numbers, and string constants, as
446 well as anything contained in parentheses, brackets, or braces.
447
448    In languages that use prefix and infix operators, such as C, it is
449 not possible for all expressions to be sexps.  For example, C mode does
450 not recognize `foo + bar' as an sexp, even though it is a C expression;
451 it recognizes `foo' as one sexp and `bar' as another, with the `+' as
452 punctuation between them.  This is a fundamental ambiguity: both `foo +
453 bar' and `foo' are legitimate choices for the sexp to move over if
454 point is at the `f'.  Note that `(foo + bar)' is a sexp in C mode.
455
456    Some languages have obscure forms of syntax for expressions that
457 nobody has bothered to make Emacs understand properly.
458
459 `C-M-f'
460      Move forward over an sexp (`forward-sexp').
461
462 `C-M-b'
463      Move backward over an sexp (`backward-sexp').
464
465 `C-M-k'
466      Kill sexp forward (`kill-sexp').
467
468 `C-M-u'
469      Move up and backward in list structure (`backward-up-list').
470
471 `C-M-d'
472      Move down and forward in list structure (`down-list').
473
474 `C-M-n'
475      Move forward over a list (`forward-list').
476
477 `C-M-p'
478      Move backward over a list (`backward-list').
479
480 `C-M-t'
481      Transpose expressions (`transpose-sexps').
482
483 `C-M-@'
484      Put mark after following expression (`mark-sexp').
485
486    To move forward over an sexp, use `C-M-f' (`forward-sexp').  If the
487 first significant character after point is an opening delimiter (`(' in
488 Lisp; `(', `[', or `{' in C), `C-M-f' moves past the matching closing
489 delimiter.  If the character begins a symbol, string, or number,
490 `C-M-f' moves over that.  If the character after point is a closing
491 delimiter, `C-M-f' just moves past it.  (This last is not really moving
492 across an sexp; it is an exception which is included in the definition
493 of `C-M-f' because it is as useful a behavior as anyone can think of
494 for that situation.)
495
496    The command `C-M-b' (`backward-sexp') moves backward over a sexp.
497 The detailed rules are like those above for `C-M-f', but with
498 directions reversed.  If there are any prefix characters (single quote,
499 back quote, and comma, in Lisp) preceding the sexp, `C-M-b' moves back
500 over them as well.
501
502    `C-M-f' or `C-M-b' with an argument repeats that operation the
503 specified number of times; with a negative argument, it moves in the
504 opposite direction.
505
506    In languages such as C where the comment-terminator can be
507 recognized, the sexp commands move across comments as if they were
508 whitespace.  In Lisp and other languages where comments run until the
509 end of a line, it is very difficult to ignore comments when parsing
510 backwards; therefore, in such languages the sexp commands treat the
511 text of comments as if it were code.
512
513    Killing an sexp at a time can be done with `C-M-k' (`kill-sexp').
514 `C-M-k' kills the characters that `C-M-f' would move over.
515
516    The "list commands", `C-M-n' (`forward-list') and `C-M-p'
517 (`backward-list'), move over lists like the sexp commands but skip over
518 any number of other kinds of sexps (symbols, strings, etc).  In some
519 situations, these commands are useful because they usually ignore
520 comments, since the comments usually do not contain any lists.
521
522    `C-M-n' and `C-M-p' stay at the same level in parentheses, when that
523 is possible.  To move up one (or N) levels, use `C-M-u'
524 (`backward-up-list').  `C-M-u' moves backward up past one unmatched
525 opening delimiter.  A positive argument serves as a repeat count; a
526 negative argument reverses direction of motion and also requests
527 repetition, so it moves forward and up one or more levels.
528
529    To move down in list structure, use `C-M-d' (`down-list').  In Lisp
530 mode, where `(' is the only opening delimiter, this is nearly the same
531 as searching for a `('.  An argument specifies the number of levels of
532 parentheses to go down.
533
534    `C-M-t' (`transpose-sexps') drags the previous sexp across the next
535 one.  An argument serves as a repeat count, and a negative argument
536 drags backwards (thus canceling out the effect of `C-M-t' with a
537 positive argument).  An argument of zero, rather than doing nothing,
538 transposes the sexps ending after point and the mark.
539
540    To make the region be the next sexp in the buffer, use `C-M-@'
541 (`mark-sexp') which sets the mark at the same place that `C-M-f' would
542 move to.  `C-M-@' takes arguments like `C-M-f'.  In particular, a
543 negative argument is useful for putting the mark at the beginning of
544 the previous sexp.
545
546    The list and sexp commands' understanding of syntax is completely
547 controlled by the syntax table.  Any character can, for example, be
548 declared to be an opening delimiter and act like an open parenthesis.
549 *Note Syntax::.
550
551 \1f
552 File: xemacs.info,  Node: Defuns,  Next: Grinding,  Prev: Lists,  Up: Programs
553
554 Defuns
555 ======
556
557    In Emacs, a parenthetical grouping at the top level in the buffer is
558 called a "defun".  The name derives from the fact that most top-level
559 lists in Lisp are instances of the special form `defun', but Emacs
560 calls any top-level parenthetical grouping counts a defun regardless of
561 its contents or the programming language.  For example, in C, the body
562 of a function definition is a defun.
563
564 `C-M-a'
565      Move to beginning of current or preceding defun
566      (`beginning-of-defun').
567
568 `C-M-e'
569      Move to end of current or following defun (`end-of-defun').
570
571 `C-M-h'
572      Put region around whole current or following defun (`mark-defun').
573
574    The commands to move to the beginning and end of the current defun
575 are `C-M-a' (`beginning-of-defun') and `C-M-e' (`end-of-defun').
576
577    To operate on the current defun, use `C-M-h' (`mark-defun') which
578 puts point at the beginning and the mark at the end of the current or
579 next defun.  This is the easiest way to prepare for moving the defun to
580 a different place.  In C mode, `C-M-h' runs the function
581 `mark-c-function', which is almost the same as `mark-defun', but which
582 backs up over the argument declarations, function name, and returned
583 data type so that the entire C function is inside the region.
584
585    To compile and evaluate the current defun, use `M-x compile-defun'.
586 This function prints the results in the minibuffer. If you include an
587 argument, it inserts the value in the current buffer after the defun.
588
589    Emacs assumes that any open-parenthesis found in the leftmost column
590 is the start of a defun.  Therefore, never put an open-parenthesis at
591 the left margin in a Lisp file unless it is the start of a top level
592 list.  Never put an open-brace or other opening delimiter at the
593 beginning of a line of C code unless it starts the body of a function.
594 The most likely problem case is when you want an opening delimiter at
595 the start of a line inside a string.  To avoid trouble, put an escape
596 character (`\' in C and Emacs Lisp, `/' in some other Lisp dialects)
597 before the opening delimiter.  It will not affect the contents of the
598 string.
599
600    The original Emacs found defuns by moving upward a level of
601 parentheses until there were no more levels to go up.  This required
602 scanning back to the beginning of the buffer for every function.  To
603 speed this up, Emacs was changed to assume that any `(' (or other
604 character assigned the syntactic class of opening-delimiter) at the
605 left margin is the start of a defun.  This heuristic is nearly always
606 right; however, it mandates the convention described above.
607
608 \1f
609 File: xemacs.info,  Node: Grinding,  Next: Matching,  Prev: Defuns,  Up: Programs
610
611 Indentation for Programs
612 ========================
613
614    The best way to keep a program properly indented ("ground") is to
615 use Emacs to re-indent it as you change the program.  Emacs has commands
616 to indent properly either a single line, a specified number of lines, or
617 all of the lines inside a single parenthetical grouping.
618
619 * Menu:
620
621 * Basic Indent::
622 * Multi-line Indent::   Commands to reindent many lines at once.
623 * Lisp Indent::         Specifying how each Lisp function should be indented.
624 * C Indent::            Choosing an indentation style for C code.
625
626 \1f
627 File: xemacs.info,  Node: Basic Indent,  Next: Multi-line Indent,  Prev: Grinding,  Up: Grinding
628
629 Basic Program Indentation Commands
630 ----------------------------------
631
632 `<TAB>'
633      Adjust indentation of current line.
634
635 `<LFD>'
636      Equivalent to <RET> followed by <TAB> (`newline-and-indent').
637
638    The basic indentation command is <TAB>, which gives the current line
639 the correct indentation as determined from the previous lines.  The
640 function that <TAB> runs depends on the major mode; it is
641 `lisp-indent-line' in Lisp mode, `c-indent-line' in C mode, etc.  These
642 functions understand different syntaxes for different languages, but
643 they all do about the same thing.  <TAB> in any programming language
644 major mode inserts or deletes whitespace at the beginning of the
645 current line, independent of where point is in the line.  If point is
646 inside the whitespace at the beginning of the line, <TAB> leaves it at
647 the end of that whitespace; otherwise, <TAB> leaves point fixed with
648 respect to the characters around it.
649
650    Use `C-q <TAB>' to insert a tab at point.
651
652    When entering a large amount of new code, use <LFD>
653 (`newline-and-indent'), which is equivalent to a <RET> followed by a
654 <TAB>.  <LFD> creates a blank line, then gives it the appropriate
655 indentation.
656
657    <TAB> indents the second and following lines of the body of a
658 parenthetical grouping each under the preceding one; therefore, if you
659 alter one line's indentation to be nonstandard, the lines below tend to
660 follow it.  This is the right behavior in cases where the standard
661 result of <TAB> does not look good.
662
663    Remember that Emacs assumes that an open-parenthesis, open-brace, or
664 other opening delimiter at the left margin (including the indentation
665 routines) is the start of a function.  You should therefore never have
666 an opening delimiter in column zero that is not the beginning of a
667 function, not even inside a string.  This restriction is vital for
668 making the indentation commands fast. *Note Defuns::, for more
669 information on this behavior.
670
671 \1f
672 File: xemacs.info,  Node: Multi-line Indent,  Next: Lisp Indent,  Prev: Basic Indent,  Up: Grinding
673
674 Indenting Several Lines
675 -----------------------
676
677    Several commands are available to re-indent several lines of code
678 which have been altered or moved to a different level in a list
679 structure.
680
681 `C-M-q'
682      Re-indent all the lines within one list (`indent-sexp').
683
684 `C-u <TAB>'
685      Shift an entire list rigidly sideways so that its first line is
686      properly indented.
687
688 `C-M-\'
689      Re-indent all lines in the region (`indent-region').
690
691    To re-indent the contents of a single list, position point before the
692 beginning of it and type `C-M-q'. This key is bound to `indent-sexp' in
693 Lisp mode, `indent-c-exp' in C mode, and bound to other suitable
694 functions in other modes.  The indentation of the line the sexp starts
695 on is not changed; therefore, only the relative indentation within the
696 list, and not its position, is changed.  To correct the position as
697 well, type a <TAB> before `C-M-q'.
698
699    If the relative indentation within a list is correct but the
700 indentation of its beginning is not, go to the line on which the list
701 begins and type `C-u <TAB>'.  When you give <TAB> a numeric argument,
702 it moves all the lines in the group, starting on the current line,
703 sideways the same amount that the current line moves.  The command does
704 not move lines that start inside strings, or C preprocessor lines when
705 in C mode.
706
707    Another way to specify a range to be re-indented is with point and
708 mark.  The command `C-M-\' (`indent-region') applies <TAB> to every
709 line whose first character is between point and mark.
710
711 \1f
712 File: xemacs.info,  Node: Lisp Indent,  Next: C Indent,  Prev: Multi-line Indent,  Up: Grinding
713
714 Customizing Lisp Indentation
715 ----------------------------
716
717    The indentation pattern for a Lisp expression can depend on the
718 function called by the expression.  For each Lisp function, you can
719 choose among several predefined patterns of indentation, or define an
720 arbitrary one with a Lisp program.
721
722    The standard pattern of indentation is as follows: the second line
723 of the expression is indented under the first argument, if that is on
724 the same line as the beginning of the expression; otherwise, the second
725 line is indented underneath the function name.  Each following line is
726 indented under the previous line whose nesting depth is the same.
727
728    If the variable `lisp-indent-offset' is non-`nil', it overrides the
729 usual indentation pattern for the second line of an expression, so that
730 such lines are always indented `lisp-indent-offset' more columns than
731 the containing list.
732
733    Certain functions override the standard pattern.  Functions whose
734 names start with `def' always indent the second line by
735 `lisp-body-indention' extra columns beyond the open-parenthesis
736 starting the expression.
737
738    Individual functions can override the standard pattern in various
739 ways, according to the `lisp-indent-function' property of the function
740 name.  (Note: `lisp-indent-function' was formerly called
741 `lisp-indent-hook').  There are four possibilities for this property:
742
743 `nil'
744      This is the same as no property; the standard indentation pattern
745      is used.
746
747 `defun'
748      The pattern used for function names that start with `def' is used
749      for this function also.
750
751 a number, NUMBER
752      The first NUMBER arguments of the function are "distinguished"
753      arguments; the rest are considered the "body" of the expression.
754      A line in the expression is indented according to whether the
755      first argument on it is distinguished or not.  If the argument is
756      part of the body, the line is indented `lisp-body-indent' more
757      columns than the open-parenthesis starting the containing
758      expression.  If the argument is distinguished and is either the
759      first or second argument, it is indented twice that many extra
760      columns.  If the argument is distinguished and not the first or
761      second argument, the standard pattern is followed for that line.
762
763 a symbol, SYMBOL
764      SYMBOL should be a function name; that function is called to
765      calculate the indentation of a line within this expression.  The
766      function receives two arguments:
767     STATE
768           The value returned by `parse-partial-sexp' (a Lisp primitive
769           for indentation and nesting computation) when it parses up to
770           the beginning of this line.
771
772     POS
773           The position at which the line being indented begins.
774
775      It should return either a number, which is the number of columns of
776      indentation for that line, or a list whose first element is such a
777      number.  The difference between returning a number and returning a
778      list is that a number says that all following lines at the same
779      nesting level should be indented just like this one; a list says
780      that following lines might call for different indentations.  This
781      makes a difference when the indentation is computed by `C-M-q'; if
782      the value is a number, `C-M-q' need not recalculate indentation
783      for the following lines until the end of the list.
784
785 \1f
786 File: xemacs.info,  Node: C Indent,  Prev: Lisp Indent,  Up: Grinding
787
788 Customizing C Indentation
789 -------------------------
790
791    Two variables control which commands perform C indentation and when.
792
793    If `c-auto-newline' is non-`nil', newlines are inserted both before
794 and after braces that you insert and after colons and semicolons.
795 Correct C indentation is done on all the lines that are made this way.
796
797    If `c-tab-always-indent' is non-`nil', the <TAB> command in C mode
798 does indentation only if point is at the left margin or within the
799 line's indentation.  If there is non-whitespace to the left of point,
800 <TAB> just inserts a tab character in the buffer.  Normally, this
801 variable is `nil', and <TAB> always reindents the current line.
802
803    C does not have anything analogous to particular function names for
804 which special forms of indentation are desirable.  However, it has a
805 different need for customization facilities: many different styles of C
806 indentation are in common use.
807
808    There are six variables you can set to control the style that Emacs C
809 mode will use.
810
811 `c-indent-level'
812      Indentation of C statements within surrounding block.  The
813      surrounding block's indentation is the indentation of the line on
814      which the open-brace appears.
815
816 `c-continued-statement-offset'
817      Extra indentation given to a substatement, such as the then-clause
818      of an `if' or body of a `while'.
819
820 `c-brace-offset'
821      Extra indentation for lines that start with an open brace.
822
823 `c-brace-imaginary-offset'
824      An open brace following other text is treated as if it were this
825      far to the right of the start of its line.
826
827 `c-argdecl-indent'
828      Indentation level of declarations of C function arguments.
829
830 `c-label-offset'
831      Extra indentation for a line that is a label, case, or default.
832
833    The variable `c-indent-level' controls the indentation for C
834 statements with respect to the surrounding block.  In the example:
835
836          {
837            foo ();
838
839 the difference in indentation between the lines is `c-indent-level'.
840 Its standard value is 2.
841
842    If the open-brace beginning the compound statement is not at the
843 beginning of its line, the `c-indent-level' is added to the indentation
844 of the line, not the column of the open-brace.  For example,
845
846      if (losing) {
847        do_this ();
848
849 One popular indentation style is that which results from setting
850 `c-indent-level' to 8 and putting open-braces at the end of a line in
851 this way.  Another popular style prefers to put the open-brace on a
852 separate line.
853
854    In fact, the value of the variable `c-brace-imaginary-offset' is
855 also added to the indentation of such a statement.  Normally this
856 variable is zero.  Think of this variable as the imaginary position of
857 the open brace, relative to the first non-blank character on the line.
858 By setting the variable to 4 and `c-indent-level' to 0, you can get
859 this style:
860
861      if (x == y) {
862          do_it ();
863          }
864
865    When `c-indent-level' is zero, the statements inside most braces
866 line up exactly under the open brace.  An exception are braces in column
867 zero, like those surrounding a function's body.  The statements inside
868 those braces are not placed at column zero.  Instead, `c-brace-offset'
869 and `c-continued-statement-offset' (see below) are added to produce a
870 typical offset between brace levels, and the statements are indented
871 that far.
872
873    `c-continued-statement-offset' controls the extra indentation for a
874 line that starts within a statement (but not within parentheses or
875 brackets).  These lines are usually statements inside other statements,
876 like the then-clauses of `if' statements and the bodies of `while'
877 statements.  The `c-continued-statement-offset' parameter determines
878 the difference in indentation between the two lines in:
879
880      if (x == y)
881        do_it ();
882
883 The default value for `c-continued-statement-offset' is 2.  Some
884 popular indentation styles correspond to a value of zero for
885 `c-continued-statement-offset'.
886
887    `c-brace-offset' is the extra indentation given to a line that
888 starts with an open-brace.  Its standard value is zero; compare:
889
890      if (x == y)
891        {
892
893 with:
894
895      if (x == y)
896        do_it ();
897
898 If you set `c-brace-offset' to 4, the first example becomes:
899
900      if (x == y)
901            {
902
903    `c-argdecl-indent' controls the indentation of declarations of the
904 arguments of a C function.  It is absolute: argument declarations
905 receive exactly `c-argdecl-indent' spaces.  The standard value is 5 and
906 results in code like this:
907
908      char *
909      index (string, char)
910           char *string;
911           int char;
912
913    `c-label-offset' is the extra indentation given to a line that
914 contains a label, a case statement, or a `default:' statement.  Its
915 standard value is -2 and results in code like this:
916
917      switch (c)
918        {
919        case 'x':
920
921 If `c-label-offset' were zero, the same code would be indented as:
922
923      switch (c)
924        {
925          case 'x':
926
927 This example assumes that the other variables above also have their
928 default values.
929
930    Using the indentation style produced by the default settings of the
931 variables just discussed and putting open braces on separate lines
932 produces clear and readable files.  For an example, look at any of the C
933 source files of XEmacs.
934
935 \1f
936 File: xemacs.info,  Node: Matching,  Next: Comments,  Prev: Grinding,  Up: Programs
937
938 Automatic Display of Matching Parentheses
939 =========================================
940
941    The Emacs parenthesis-matching feature shows you automatically how
942 parentheses match in the text.  Whenever a self-inserting character that
943 is a closing delimiter is typed, the cursor moves momentarily to the
944 location of the matching opening delimiter, provided that is visible on
945 the screen.  If it is not on the screen, some text starting with that
946 opening delimiter is displayed in the echo area.  Either way, you see
947 the grouping you are closing off.
948
949    In Lisp, automatic matching applies only to parentheses.  In C, it
950 also applies to braces and brackets.  Emacs knows which characters to
951 regard as matching delimiters based on the syntax table set by the major
952 mode.  *Note Syntax::.
953
954    If the opening delimiter and closing delimiter are mismatched--as in
955 `[x)'--the echo area displays a warning message.  The correct matches
956 are specified in the syntax table.
957
958    Two variables control parenthesis matching displays.
959 `blink-matching-paren' turns the feature on or off. The default is `t'
960 (match display is on); `nil' turns it off.
961 `blink-matching-paren-distance' specifies how many characters back
962 Emacs searches to find a matching opening delimiter.  If the match is
963 not found in the specified region, scanning stops, and nothing is
964 displayed.  This prevents wasting lots of time scanning when there is no
965 match.  The default is 4000.
966
967 \1f
968 File: xemacs.info,  Node: Comments,  Next: Balanced Editing,  Prev: Matching,  Up: Programs
969
970 Manipulating Comments
971 =====================
972
973    The comment commands insert, kill and align comments.
974
975 `M-;'
976      Insert or align comment (`indent-for-comment').
977
978 `C-x ;'
979      Set comment column (`set-comment-column').
980
981 `C-u - C-x ;'
982      Kill comment on current line (`kill-comment').
983
984 `M-<LFD>'
985      Like <RET> followed by inserting and aligning a comment
986      (`indent-new-comment-line').
987
988    The command that creates a comment is `Meta-;'
989 (`indent-for-comment').  If there is no comment already on the line, a
990 new comment is created and aligned at a specific column called the
991 "comment column".  Emacs creates the comment by inserting the string at
992 the value of `comment-start'; see below.  Point is left after that
993 string.  If the text of the line extends past the comment column,
994 indentation is done to a suitable boundary (usually, at least one space
995 is inserted).  If the major mode has specified a string to terminate
996 comments, that string is inserted after point, to keep the syntax valid.
997
998    You can also use `Meta-;' to align an existing comment.  If a line
999 already contains the string that starts comments, `M-;' just moves
1000 point after it and re-indents it to the conventional place.  Exception:
1001 comments starting in column 0 are not moved.
1002
1003    Some major modes have special rules for indenting certain kinds of
1004 comments in certain contexts.  For example, in Lisp code, comments which
1005 start with two semicolons are indented as if they were lines of code,
1006 instead of at the comment column.  Comments which start with three
1007 semicolons are supposed to start at the left margin.  Emacs understands
1008 these conventions by indenting a double-semicolon comment using <TAB>
1009 and by not changing the indentation of a triple-semicolon comment at
1010 all.
1011
1012      ;; This function is just an example.
1013      ;;; Here either two or three semicolons are appropriate.
1014      (defun foo (x)
1015      ;;; And now, the first part of the function:
1016        ;; The following line adds one.
1017        (1+ x))           ; This line adds one.
1018
1019    In C code, a comment preceded on its line by nothing but whitespace
1020 is indented like a line of code.
1021
1022    Even when an existing comment is properly aligned, `M-;' is still
1023 useful for moving directly to the start of the comment.
1024
1025    `C-u - C-x ;' (`kill-comment') kills the comment on the current
1026 line, if there is one.  The indentation before the start of the comment
1027 is killed as well.  If there does not appear to be a comment in the
1028 line, nothing happens.  To reinsert the comment on another line, move
1029 to the end of that line, type first `C-y', and then `M-;' to realign
1030 the comment.  Note that `C-u - C-x ;' is not a distinct key; it is `C-x
1031 ;' (`set-comment-column') with a negative argument.  That command is
1032 programmed to call `kill-comment' when called with a negative argument.
1033 However, `kill-comment' is a valid command which you could bind
1034 directly to a key if you wanted to.
1035
1036 Multiple Lines of Comments
1037 --------------------------
1038
1039    If you are typing a comment and want to continue it on another line,
1040 use the command `Meta-<LFD>' (`indent-new-comment-line'), which
1041 terminates the comment you are typing, creates a new blank line
1042 afterward, and begins a new comment indented under the old one.  If
1043 Auto Fill mode is on and you go past the fill column while typing, the
1044 comment is continued in just this fashion.  If point is not at the end
1045 of the line when you type `M-<LFD>', the text on the rest of the line
1046 becomes part of the new comment line.
1047
1048 Options Controlling Comments
1049 ----------------------------
1050
1051    The comment column is stored in the variable `comment-column'.  You
1052 can explicitly set it to a number.  Alternatively, the command `C-x ;'
1053 (`set-comment-column') sets the comment column to the column point is
1054 at.  `C-u C-x ;' sets the comment column to match the last comment
1055 before point in the buffer, and then calls `Meta-;' to align the
1056 current line's comment under the previous one.  Note that `C-u - C-x ;'
1057 runs the function `kill-comment' as described above.
1058
1059    `comment-column' is a per-buffer variable; altering the variable
1060 affects only the current buffer.  You can also change the default value.
1061 *Note Locals::.  Many major modes initialize this variable for the
1062 current buffer.
1063
1064    The comment commands recognize comments based on the regular
1065 expression that is the value of the variable `comment-start-skip'.
1066 This regexp should not match the null string.  It may match more than
1067 the comment starting delimiter in the strictest sense of the word; for
1068 example, in C mode the value of the variable is `"/\\*+ *"', which
1069 matches extra stars and spaces after the `/*' itself.  (Note that `\\'
1070 is needed in Lisp syntax to include a `\' in the string, which is needed
1071 to deny the first star its special meaning in regexp syntax.  *Note
1072 Regexps::.)
1073
1074    When a comment command makes a new comment, it inserts the value of
1075 `comment-start' to begin it.  The value of `comment-end' is inserted
1076 after point and will follow the text you will insert into the comment.
1077 In C mode, `comment-start' has the value `"/* "' and `comment-end' has
1078 the value `" */"'.
1079
1080    `comment-multi-line' controls how `M-<LFD>'
1081 (`indent-new-comment-line') behaves when used inside a comment.  If
1082 `comment-multi-line' is `nil', as it normally is, then `M-<LFD>'
1083 terminates the comment on the starting line and starts a new comment on
1084 the new following line.  If `comment-multi-line' is not `nil', then
1085 `M-<LFD>' sets up the new following line as part of the same comment
1086 that was found on the starting line.  This is done by not inserting a
1087 terminator on the old line and not inserting a starter on the new line.
1088 In languages where multi-line comments are legal, the value you choose
1089 for this variable is a matter of taste.
1090
1091    The variable `comment-indent-hook' should contain a function that is
1092 called to compute the indentation for a newly inserted comment or for
1093 aligning an existing comment.  Major modes set this variable
1094 differently.  The function is called with no arguments, but with point
1095 at the beginning of the comment, or at the end of a line if a new
1096 comment is to be inserted.  The function should return the column in
1097 which the comment ought to start.  For example, in Lisp mode, the
1098 indent hook function bases its decision on the number of semicolons
1099 that begin an existing comment and on the code in the preceding lines.
1100
1101 \1f
1102 File: xemacs.info,  Node: Balanced Editing,  Next: Lisp Completion,  Prev: Comments,  Up: Programs
1103
1104 Editing Without Unbalanced Parentheses
1105 ======================================
1106
1107 `M-('
1108      Put parentheses around next sexp(s) (`insert-parentheses').
1109
1110 `M-)'
1111      Move past next close parenthesis and re-indent
1112      (`move-over-close-and-reindent').
1113
1114    The commands `M-(' (`insert-parentheses') and `M-)'
1115 (`move-over-close-and-reindent') are designed to facilitate a style of
1116 editing which keeps parentheses balanced at all times.  `M-(' inserts a
1117 pair of parentheses, either together as in `()', or, if given an
1118 argument, around the next several sexps, and leaves point after the open
1119 parenthesis.  Instead of typing `( F O O )', you can type `M-( F O O',
1120 which has the same effect except for leaving the cursor before the
1121 close parenthesis.  You can then type `M-)', which moves past the close
1122 parenthesis, deletes any indentation preceding it (in this example
1123 there is none), and indents with <LFD> after it.
1124
1125 \1f
1126 File: xemacs.info,  Node: Lisp Completion,  Next: Documentation,  Prev: Balanced Editing,  Up: Programs
1127
1128 Completion for Lisp Symbols
1129 ===========================
1130
1131    Completion usually happens in the minibuffer.  An exception is
1132 completion for Lisp symbol names, which is available in all buffers.
1133
1134    The command `M-<TAB>' (`lisp-complete-symbol') takes the partial
1135 Lisp symbol before point to be an abbreviation, and compares it against
1136 all non-trivial Lisp symbols currently known to Emacs.  Any additional
1137 characters that they all have in common are inserted at point.
1138 Non-trivial symbols are those that have function definitions, values, or
1139 properties.
1140
1141    If there is an open-parenthesis immediately before the beginning of
1142 the partial symbol, only symbols with function definitions are
1143 considered as completions.
1144
1145    If the partial name in the buffer has more than one possible
1146 completion and they have no additional characters in common, a list of
1147 all possible completions is displayed in another window.
1148
1149 \1f
1150 File: xemacs.info,  Node: Documentation,  Next: Change Log,  Prev: Lisp Completion,  Up: Programs
1151
1152 Documentation Commands
1153 ======================
1154
1155    As you edit Lisp code to be run in Emacs, you can use the commands
1156 `C-h f' (`describe-function') and `C-h v' (`describe-variable') to
1157 print documentation of functions and variables you want to call.  These
1158 commands use the minibuffer to read the name of a function or variable
1159 to document, and display the documentation in a window.
1160
1161    For extra convenience, these commands provide default arguments
1162 based on the code in the neighborhood of point.  `C-h f' sets the
1163 default to the function called in the innermost list containing point.
1164 `C-h v' uses the symbol name around or adjacent to point as its default.
1165
1166    The `M-x manual-entry' command gives you access to documentation on
1167 Unix commands, system calls, and libraries.  The command reads a topic
1168 as an argument, and displays the Unix manual page for that topic.
1169 `manual-entry' always searches all 8 sections of the manual and
1170 concatenates all the entries it finds.  For example, the topic
1171 `termcap' finds the description of the termcap library from section 3,
1172 followed by the description of the termcap data base from section 5.
1173