]> code.delx.au - gnu-emacs/blob - man/programs.texi
a80d3bad08a725d1d3b94f908c8863da29434223
[gnu-emacs] / man / programs.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 1999, 2000,
3 @c 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Programs, Building, Text, Top
6 @chapter Editing Programs
7 @cindex Lisp editing
8 @cindex C editing
9 @cindex program editing
10
11 Emacs provides many features to facilitate editing programs. Some
12 of these features can
13
14 @itemize @bullet
15 @item
16 Find or move over top-level definitions (@pxref{Defuns}).
17 @item
18 Apply the usual indentation conventions of the language
19 (@pxref{Program Indent}).
20 @item
21 Balance parentheses (@pxref{Parentheses}).
22 @item
23 Insert, kill or align comments (@pxref{Comments}).
24 @item
25 Highlight program syntax (@pxref{Font Lock}).
26 @end itemize
27
28 This chapter describes these features and many more.
29
30 @menu
31 * Program Modes:: Major modes for editing programs.
32 * Defuns:: Commands to operate on major top-level parts
33 of a program.
34 * Program Indent:: Adjusting indentation to show the nesting.
35 * Parentheses:: Commands that operate on parentheses.
36 * Comments:: Inserting, killing, and aligning comments.
37 * Documentation:: Getting documentation of functions you plan to call.
38 * Hideshow:: Displaying blocks selectively.
39 * Symbol Completion:: Completion on symbol names of your program or language.
40 * Glasses:: Making identifiersLikeThis more readable.
41 * Misc for Programs:: Other Emacs features useful for editing programs.
42 * C Modes:: Special commands of C, C++, Objective-C,
43 Java, and Pike modes.
44 * Fortran:: Fortran mode and its special features.
45 * Asm Mode:: Asm mode and its special features.
46 @end menu
47
48 @node Program Modes
49 @section Major Modes for Programming Languages
50 @cindex modes for programming languages
51
52 Emacs has specialized major modes for various programming languages.
53 @xref{Major Modes}. A programming language major mode typically
54 specifies the syntax of expressions, the customary rules for
55 indentation, how to do syntax highlighting for the language, and how
56 to find the beginning of a function definition. It often customizes
57 or provides facilities for compiling and debugging programs as well.
58
59 Ideally, Emacs should provide a major mode for each programming
60 language that you might want to edit; if it doesn't have a mode for
61 your favorite language, you can contribute one. But often the mode
62 for one language can serve for other syntactically similar languages.
63 The major mode for language @var{l} is called @code{@var{l}-mode},
64 and you can select it by typing @kbd{M-x @var{l}-mode @key{RET}}.
65 @xref{Choosing Modes}.
66
67 @cindex Perl mode
68 @cindex Icon mode
69 @cindex Makefile mode
70 @cindex Tcl mode
71 @cindex CPerl mode
72 @cindex DSSSL mode
73 @cindex Octave mode
74 @cindex Metafont mode
75 @cindex Modula2 mode
76 @cindex Prolog mode
77 @cindex Python mode
78 @cindex Simula mode
79 @cindex VHDL mode
80 @cindex M4 mode
81 @cindex Shell-script mode
82 @cindex Delphi mode
83 @cindex PostScript mode
84 @cindex Conf mode
85 @cindex DNS mode
86 The existing programming language major modes include Lisp, Scheme (a
87 variant of Lisp) and the Scheme-based DSSSL expression language, Ada,
88 ASM, AWK, C, C++, Delphi (Object Pascal), Fortran (free format and fixed
89 format), Icon, IDL (CORBA), IDLWAVE, Java, Metafont (@TeX{}'s
90 companion for font creation), Modula2, Objective-C, Octave, Pascal,
91 Perl, Pike, PostScript, Prolog, Python, Simula, Tcl, and VHDL. An
92 alternative mode for Perl is called CPerl mode. Modes are available for
93 the scripting languages of the common GNU and Unix shells, VMS DCL, and
94 MS-DOS/MS-Windows @samp{BAT} files. There are also major modes for
95 editing makefiles, DNS master files, and various sorts of configuration
96 files.
97
98 @kindex DEL @r{(programming modes)}
99 @findex c-electric-backspace
100 In most programming languages, indentation should vary from line to
101 line to illustrate the structure of the program. So the major modes
102 for programming languages arrange for @key{TAB} to update the
103 indentation of the current line. They also rebind @key{DEL} to treat
104 a tab as if it were the equivalent number of spaces; this lets you
105 delete one column of indentation without worrying whether the
106 whitespace consists of spaces or tabs. Use @kbd{C-b C-d} to delete a
107 tab character before point, in these modes.
108
109 Separate manuals are available for the modes for Ada (@pxref{Top, , Ada
110 Mode, ada-mode, Ada Mode}), C/C++/Objective C/Java/Corba IDL/Pike/AWK
111 (@pxref{Top, , CC Mode, ccmode, CC Mode}) and the IDLWAVE modes
112 (@pxref{Top, , IDLWAVE, idlwave, IDLWAVE User Manual}).
113
114 @cindex mode hook
115 @vindex c-mode-hook
116 @vindex lisp-mode-hook
117 @vindex emacs-lisp-mode-hook
118 @vindex lisp-interaction-mode-hook
119 @vindex scheme-mode-hook
120 Turning on a major mode runs a normal hook called the @dfn{mode
121 hook}, which is the value of a Lisp variable. Each major mode has a
122 mode hook, and the hook's name is always made from the mode command's
123 name by adding @samp{-hook}. For example, turning on C mode runs the
124 hook @code{c-mode-hook}, while turning on Lisp mode runs the hook
125 @code{lisp-mode-hook}. The purpose of the mode hook is to give you a
126 place to set up customizations for that major mode. @xref{Hooks}.
127
128 @node Defuns
129 @section Top-Level Definitions, or Defuns
130
131 In Emacs, a major definition at the top level in the buffer,
132 something like a function, is called a @dfn{defun}. The name comes
133 from Lisp, but in Emacs we use it for all languages.
134
135 In many programming language modes, Emacs assumes that a defun is
136 any pair of parentheses (or braces, if the language uses braces this
137 way) that starts at the left margin. For example, in C, the body of a
138 function definition is a defun, usually recognized as an open-brace
139 that begins at the left margin@footnote{Alternatively, you can set up
140 C Mode to recognize a defun at an opening brace at the outermost
141 level. @xref{Movement Commands,,, ccmode, the CC Mode Manual}.}. A
142 variable's initializer can also count as a defun, if the open-brace
143 that begins the initializer is at the left margin.
144
145 However, some language modes provide their own code for recognizing
146 defuns in a way that suits the language syntax and conventions better.
147
148 @menu
149 * Left Margin Paren:: An open-paren or similar opening delimiter
150 starts a defun if it is at the left margin.
151 * Moving by Defuns:: Commands to move over or mark a major definition.
152 * Imenu:: Making buffer indexes as menus.
153 * Which Function:: Which Function mode shows which function you are in.
154 @end menu
155
156 @node Left Margin Paren
157 @subsection Left Margin Convention
158
159 @cindex open-parenthesis in leftmost column
160 @cindex ( in leftmost column
161 Emacs assumes by default that any opening delimiter found at the
162 left margin is the start of a top-level definition, or defun. You can
163 override this default by setting this user option:
164
165 @defvar open-paren-in-column-0-is-defun-start
166 If this user option is set to @code{t} (the default), opening
167 parentheses or braces at column zero always start defuns. When it's
168 @code{nil}, defuns are found by searching for parens or braces at the
169 outermost level.
170 @end defvar
171
172 In buffers where @code{open-paren-in-column-0-is-defun-start} is
173 @code{t}, @strong{don't put an opening delimiter at the left margin
174 unless it is a defun start}. For instance, never put an
175 open-parenthesis at the left margin in a Lisp file unless it is the
176 start of a top-level list.
177
178 If you don't follow this convention, not only will you have trouble
179 when you explicitly use the commands for motion by defuns; other
180 features that use them will also give you trouble. This includes
181 the indentation commands (@pxref{Program Indent}) and Font Lock
182 mode (@pxref{Font Lock}).
183
184 The most likely problem case is when you want an opening delimiter
185 at the start of a line inside a string. To avoid trouble, put an
186 escape character (@samp{\}, in Emacs Lisp, @samp{/} in some other Lisp
187 dialects) before the opening delimiter. This will not affect the
188 contents of the string, but will prevent that opening delimiter from
189 starting a defun. Here's an example:
190
191 @example
192 (insert "Foo:
193 \(bar)
194 ")
195 @end example
196
197 To help you catch violations of this convention, Font Lock mode
198 highlights confusing opening delimiters (those that ought to be
199 quoted) in bold red.
200
201 Some major modes, including C and related modes, set
202 @code{open-paren-in-column-0-is-defun-start} buffer-locally to
203 @code{nil}, thus freeing you from all these restrictions. This makes
204 some commands run more slowly, though.
205
206 In the earliest days, the original Emacs found defuns by moving
207 upward a level of parentheses or braces until there were no more
208 levels to go up. This always required scanning all the way back to
209 the beginning of the buffer, even for a small function. To speed up
210 the operation, we changed Emacs to assume that any opening delimiter
211 at the left margin is the start of a defun. This heuristic is nearly
212 always right, and avoids the need to scan back to the beginning of the
213 buffer. However, now that modern computers are so powerful, this
214 scanning is rarely slow enough to annoy, so we've given you a way to
215 disable the heuristic.
216
217 @node Moving by Defuns
218 @subsection Moving by Defuns
219 @cindex defuns
220
221 These commands move point or set up the region based on top-level
222 major definitions, also called @dfn{defuns}.
223
224 @table @kbd
225 @item C-M-a
226 Move to beginning of current or preceding defun
227 (@code{beginning-of-defun}).
228 @item C-M-e
229 Move to end of current or following defun (@code{end-of-defun}).
230 @item C-M-h
231 Put region around whole current or following defun (@code{mark-defun}).
232 @end table
233
234 @cindex move to beginning or end of function
235 @cindex function, move to beginning or end
236 @kindex C-M-a
237 @kindex C-M-e
238 @kindex C-M-h
239 @findex beginning-of-defun
240 @findex end-of-defun
241 @findex mark-defun
242 The commands to move to the beginning and end of the current defun
243 are @kbd{C-M-a} (@code{beginning-of-defun}) and @kbd{C-M-e}
244 (@code{end-of-defun}). If you repeat one of these commands, or use a
245 positive numeric argument, each repetition moves to the next defun in
246 the direction of motion.
247
248 @kbd{C-M-a} with a negative argument @minus{}@var{n} moves forward
249 @var{n} times to the next beginning of a defun. This is not exactly
250 the same place that @kbd{C-M-e} with argument @var{n} would move to;
251 the end of this defun is not usually exactly the same place as the
252 beginning of the following defun. (Whitespace, comments, and perhaps
253 declarations can separate them.) Likewise, @kbd{C-M-e} with a
254 negative argument moves back to an end of a defun, which is not quite
255 the same as @kbd{C-M-a} with a positive argument.
256
257 @kindex C-M-h @r{(C mode)}
258 @findex c-mark-function
259 To operate on the current defun, use @kbd{C-M-h} (@code{mark-defun})
260 which puts point at the beginning and mark at the end of the current
261 defun. This is the easiest way to get ready to kill the defun in
262 order to move it to a different place in the file. If you use the
263 command while point is between defuns, it uses the following defun.
264 Successive uses of @kbd{C-M-h}, or using it in Transient Mark mode
265 when the mark is active, includes an additional defun in the region
266 each time.
267
268 In C mode, @kbd{C-M-h} runs the function @code{c-mark-function},
269 which is almost the same as @code{mark-defun}; the difference is that
270 it backs up over the argument declarations, function name and returned
271 data type so that the entire C function is inside the region. This is
272 an example of how major modes adjust the standard key bindings so that
273 they do their standard jobs in a way better fitting a particular
274 language. Other major modes may replace any or all of these key
275 bindings for that purpose.
276
277 @node Imenu
278 @subsection Imenu
279 @cindex index of buffer definitions
280 @cindex buffer definitions index
281 @cindex tags
282
283 The Imenu facility offers a way to find the major definitions in
284 a file by name. It is also useful in text formatter major modes,
285 where it treats each chapter, section, etc., as a definition.
286 (@xref{Tags}, for a more powerful feature that handles multiple files
287 together.)
288
289 @findex imenu
290 If you type @kbd{M-x imenu}, it reads the name of a definition using
291 the minibuffer, then moves point to that definition. You can use
292 completion to specify the name; the command always displays the whole
293 list of valid names.
294
295 @findex imenu-add-menubar-index
296 Alternatively, you can bind the command @code{imenu} to a mouse
297 click. Then it displays mouse menus for you to select a definition
298 name. You can also add the buffer's index to the menu bar by calling
299 @code{imenu-add-menubar-index}. If you want to have this menu bar
300 item available for all buffers in a certain major mode, you can do
301 this by adding @code{imenu-add-menubar-index} to its mode hook. But
302 if you have done that, you will have to wait each time you visit a
303 file in that mode, while Emacs finds all the definitions in that
304 buffer.
305
306 @vindex imenu-auto-rescan
307 When you change the contents of a buffer, if you add or delete
308 definitions, you can update the buffer's index based on the
309 new contents by invoking the @samp{*Rescan*} item in the menu.
310 Rescanning happens automatically if you set @code{imenu-auto-rescan} to
311 a non-@code{nil} value. There is no need to rescan because of small
312 changes in the text.
313
314 @vindex imenu-sort-function
315 You can customize the way the menus are sorted by setting the
316 variable @code{imenu-sort-function}. By default, names are ordered as
317 they occur in the buffer; if you want alphabetic sorting, use the
318 symbol @code{imenu--sort-by-name} as the value. You can also
319 define your own comparison function by writing Lisp code.
320
321 Imenu provides the information to guide Which Function mode
322 @ifnottex
323 (@pxref{Which Function}).
324 @end ifnottex
325 @iftex
326 (see below).
327 @end iftex
328 The Speedbar can also use it (@pxref{Speedbar}).
329
330 @node Which Function
331 @subsection Which Function Mode
332 @cindex current function name in mode line
333
334 Which Function mode is a minor mode that displays the current
335 function name in the mode line, updating it as you move around in a
336 buffer.
337
338 @findex which-function-mode
339 @vindex which-func-modes
340 To enable (or disable) Which Function mode, use the command @kbd{M-x
341 which-function-mode}. This command is global; it applies to all
342 buffers, both existing ones and those yet to be created. However, it
343 takes effect only in certain major modes, those listed in the value of
344 @code{which-func-modes}. If the value is @code{t}, then Which Function
345 mode applies to all major modes that know how to support it---in other
346 words, all the major modes that support Imenu.
347
348 @node Program Indent
349 @section Indentation for Programs
350 @cindex indentation for programs
351
352 The best way to keep a program properly indented is to use Emacs to
353 reindent it as you change it. Emacs has commands to indent properly
354 either a single line, a specified number of lines, or all of the lines
355 inside a single parenthetical grouping.
356
357 @menu
358 * Basic Indent:: Indenting a single line.
359 * Multi-line Indent:: Commands to reindent many lines at once.
360 * Lisp Indent:: Specifying how each Lisp function should be indented.
361 * C Indent:: Extra features for indenting C and related modes.
362 * Custom C Indent:: Controlling indentation style for C and related modes.
363 @end menu
364
365 @cindex pretty-printer
366 Emacs also provides a Lisp pretty-printer in the library @code{pp}.
367 This program reformats a Lisp object with indentation chosen to look nice.
368
369 @node Basic Indent
370 @subsection Basic Program Indentation Commands
371
372 The basic indentation commands indent a single line according to the
373 usual conventions of the language you are editing.
374
375 @table @kbd
376 @item @key{TAB}
377 Adjust indentation of current line.
378 @item C-j
379 Equivalent to @key{RET} followed by @key{TAB} (@code{newline-and-indent}).
380 @item @key{LINEFEED}
381 This key, if the keyboard has it, is another way to enter @kbd{C-j}.
382 @end table
383
384 @kindex TAB @r{(programming modes)}
385 @findex c-indent-command
386 @findex indent-line-function
387 @findex indent-for-tab-command
388 The basic indentation command is @key{TAB}, which gives the current line
389 the correct indentation as determined from the previous lines. The
390 function that @key{TAB} runs depends on the major mode; it is
391 @code{lisp-indent-line}
392 in Lisp mode, @code{c-indent-command} in C mode, etc. These functions
393 understand the syntax and conventions of different languages, but they all do
394 conceptually the same job: @key{TAB} in any programming-language major mode
395 inserts or deletes whitespace at the beginning of the current line,
396 independent of where point is in the line. If point was inside the
397 whitespace at the beginning of the line, @key{TAB} puts it at the end of
398 that whitespace; otherwise, @key{TAB} keeps point fixed with respect to
399 the characters around it.
400
401 Use @kbd{C-q @key{TAB}} to insert a tab character at point.
402
403 @kindex C-j
404 @findex newline-and-indent
405 When entering lines of new code, use @kbd{C-j}
406 (@code{newline-and-indent}), which is equivalent to a @key{RET}
407 followed by a @key{TAB}. @kbd{C-j} at the end of a line creates a
408 blank line and then gives it the appropriate indentation.
409
410 @key{TAB} indents a line that starts within a parenthetical grouping
411 under the preceding line within the grouping, or the text after the
412 parenthesis. Therefore, if you manually give one of these lines a
413 nonstandard indentation, the lines below will tend to follow it. This
414 behavior is convenient in cases where you have overridden the standard
415 result of @key{TAB} because you find it unaesthetic for a particular
416 line.
417
418 By default, an open-parenthesis, open-brace or other opening
419 delimiter at the left margin is assumed by Emacs (including the
420 indentation routines) to be the start of a function. This speeds up
421 indentation commands. If you will be editing text which contains
422 opening delimiters in column zero that aren't the beginning of a
423 functions, even inside strings or comments, you must set
424 @code{open-paren-in-column-0-is-defun-start}. @xref{Left Margin
425 Paren}, for more information on this.
426
427 Normally, lines are indented with tabs and spaces. If you want Emacs
428 to use spaces only, see @ref{Just Spaces}.
429
430 @node Multi-line Indent
431 @subsection Indenting Several Lines
432
433 When you wish to reindent several lines of code which have been
434 altered or moved to a different level in the parenthesis structure,
435 you have several commands available.
436
437 @table @kbd
438 @item C-M-q
439 Reindent all the lines within one parenthetical grouping (@code{indent-pp-sexp}).
440 @item C-M-\
441 Reindent all lines in the region (@code{indent-region}).
442 @item C-u @key{TAB}
443 Shift an entire parenthetical grouping rigidly sideways so that its
444 first line is properly indented.
445 @item M-x indent-code-rigidly
446 Shift all the lines in the region rigidly sideways, but do not alter
447 lines that start inside comments and strings.
448 @end table
449
450 @kindex C-M-q
451 @findex indent-pp-sexp
452 You can reindent the contents of a single parenthetical grouping by
453 positioning point before the beginning of it and typing @kbd{C-M-q}
454 (@code{indent-pp-sexp} in Lisp mode, @code{c-indent-exp} in C mode; also
455 bound to other suitable commands in other modes). The indentation of
456 the line where the grouping starts is not changed; therefore this
457 changes only the relative indentation within the grouping, not its
458 overall indentation. To correct that as well, type @key{TAB} first.
459
460 Another way to specify the range to be reindented is with the
461 region. The command @kbd{C-M-\} (@code{indent-region}) applies
462 @key{TAB} to every line whose first character is between point and
463 mark.
464
465 @kindex C-u TAB
466 If you like the relative indentation within a grouping, but not the
467 indentation of its first line, you can type @kbd{C-u @key{TAB}} to
468 reindent the whole grouping as a rigid unit. (This works in Lisp
469 modes and C and related modes.) @key{TAB} with a numeric argument
470 reindents the current line as usual, then reindents by the same amount
471 all the lines in the parenthetical grouping starting on the current
472 line. It is clever, though, and does not alter lines that start
473 inside strings. Neither does it alter C preprocessor lines when in C
474 mode, but it does reindent any continuation lines that may be attached
475 to them.
476
477 @findex indent-code-rigidly
478 You can also perform this operation on the region, using the command
479 @kbd{M-x indent-code-rigidly}. It rigidly shifts all the lines in the
480 region sideways, like @code{indent-rigidly} does (@pxref{Indentation
481 Commands}). It doesn't alter the indentation of lines that start
482 inside a string, unless the region also starts inside that string.
483 The prefix arg specifies the number of columns to indent.
484
485 @node Lisp Indent
486 @subsection Customizing Lisp Indentation
487 @cindex customizing Lisp indentation
488
489 The indentation pattern for a Lisp expression can depend on the function
490 called by the expression. For each Lisp function, you can choose among
491 several predefined patterns of indentation, or define an arbitrary one with
492 a Lisp program.
493
494 The standard pattern of indentation is as follows: the second line of the
495 expression is indented under the first argument, if that is on the same
496 line as the beginning of the expression; otherwise, the second line is
497 indented underneath the function name. Each following line is indented
498 under the previous line whose nesting depth is the same.
499
500 @vindex lisp-indent-offset
501 If the variable @code{lisp-indent-offset} is non-@code{nil}, it overrides
502 the usual indentation pattern for the second line of an expression, so that
503 such lines are always indented @code{lisp-indent-offset} more columns than
504 the containing list.
505
506 @vindex lisp-body-indent
507 Certain functions override the standard pattern. Functions whose
508 names start with @code{def} treat the second lines as the start of
509 a @dfn{body}, by indenting the second line @code{lisp-body-indent}
510 additional columns beyond the open-parenthesis that starts the
511 expression.
512
513 @cindex @code{lisp-indent-function} property
514 You can override the standard pattern in various ways for individual
515 functions, according to the @code{lisp-indent-function} property of
516 the function name. Normally you would use this for macro definitions
517 and specify it using the @code{declare} construct (@pxref{Defining
518 Macros,,, elisp, the Emacs Lisp Reference Manual}).
519
520 @node C Indent
521 @subsection Commands for C Indentation
522
523 Here are special features for indentation in C mode and related modes:
524
525 @table @code
526 @item C-c C-q
527 @kindex C-c C-q @r{(C mode)}
528 @findex c-indent-defun
529 Reindent the current top-level function definition or aggregate type
530 declaration (@code{c-indent-defun}).
531
532 @item C-M-q
533 @kindex C-M-q @r{(C mode)}
534 @findex c-indent-exp
535 Reindent each line in the balanced expression that follows point
536 (@code{c-indent-exp}). A prefix argument inhibits warning messages
537 about invalid syntax.
538
539 @item @key{TAB}
540 @findex c-indent-command
541 Reindent the current line, and/or in some cases insert a tab character
542 (@code{c-indent-command}).
543
544 @vindex c-tab-always-indent
545 If @code{c-tab-always-indent} is @code{t}, this command always reindents
546 the current line and does nothing else. This is the default.
547
548 If that variable is @code{nil}, this command reindents the current line
549 only if point is at the left margin or in the line's indentation;
550 otherwise, it inserts a tab (or the equivalent number of spaces,
551 if @code{indent-tabs-mode} is @code{nil}).
552
553 Any other value (not @code{nil} or @code{t}) means always reindent the
554 line, and also insert a tab if within a comment or a string.
555 @end table
556
557 To reindent the whole current buffer, type @kbd{C-x h C-M-\}. This
558 first selects the whole buffer as the region, then reindents that
559 region.
560
561 To reindent the current block, use @kbd{C-M-u C-M-q}. This moves
562 to the front of the block and then reindents it all.
563
564 @node Custom C Indent
565 @subsection Customizing C Indentation
566 @cindex style (for indentation)
567
568 C mode and related modes use a flexible mechanism for customizing
569 indentation. C mode indents a source line in two steps: first it
570 classifies the line syntactically according to its contents and
571 context; second, it determines the indentation offset associated by
572 your selected @dfn{style} with the syntactic construct and adds this
573 onto the indentation of the @dfn{anchor statement}.
574
575 @table @kbd
576 @item C-c . @key{RET} @var{style} @key{RET}
577 Select a predefined style @var{style} (@code{c-set-style}).
578 @end table
579
580 A @dfn{style} is a named collection of customizations that can be
581 used in C mode and the related modes. @ref{Styles,,, ccmode, The CC
582 Mode Manual}, for a complete description. Emacs comes with several
583 predefined styles, including @code{gnu}, @code{k&r}, @code{bsd},
584 @code{stroustrup}, @code{linux}, @code{python}, @code{java},
585 @code{whitesmith}, @code{ellemtel}, and @code{awk}. Some of these
586 styles are primarily intended for one language, but any of them can be
587 used with any of the languages supported by these modes. To find out
588 what a style looks like, select it and reindent some code, e.g., by
589 typing @key{C-M-q} at the start of a function definition.
590
591 @kindex C-c . @r{(C mode)}
592 @findex c-set-style
593 To choose a style for the current buffer, use the command @kbd{C-c
594 .}. Specify a style name as an argument (case is not significant).
595 This command affects the current buffer only, and it affects only
596 future invocations of the indentation commands; it does not reindent
597 the code already in the buffer. To reindent the whole buffer in the
598 new style, you can type @kbd{C-x h C-M-\}.
599
600 @vindex c-default-style
601 You can also set the variable @code{c-default-style} to specify the
602 default style for various major modes. Its value should be either the
603 style's name (a string) or an alist, in which each element specifies
604 one major mode and which indentation style to use for it. For
605 example,
606
607 @example
608 (setq c-default-style
609 '((java-mode . "java") (awk-mode . "awk") (other . "gnu")))
610 @end example
611
612 @noindent
613 specifies explicit choices for Java and AWK modes, and the default
614 @samp{gnu} style for the other C-like modes. (These settings are
615 actually the defaults.) This variable takes effect when you select
616 one of the C-like major modes; thus, if you specify a new default
617 style for Java mode, you can make it take effect in an existing Java
618 mode buffer by typing @kbd{M-x java-mode} there.
619
620 The @code{gnu} style specifies the formatting recommended by the GNU
621 Project for C; it is the default, so as to encourage use of our
622 recommended style.
623
624 @xref{Indentation Engine Basics,,, ccmode, the CC Mode Manual}, and
625 @ref{Customizing Indentation,,, ccmode, the CC Mode Manual}, for more
626 information on customizing indentation for C and related modes,
627 including how to override parts of an existing style and how to define
628 your own styles.
629
630 @node Parentheses
631 @section Commands for Editing with Parentheses
632
633 @findex check-parens
634 @cindex unbalanced parentheses and quotes
635 This section describes the commands and features that take advantage
636 of the parenthesis structure in a program, or help you keep it
637 balanced.
638
639 When talking about these facilities, the term ``parenthesis'' also
640 includes braces, brackets, or whatever delimiters are defined to match
641 in pairs. The major mode controls which delimiters are significant,
642 through the syntax table (@pxref{Syntax}). In Lisp, only parentheses
643 count; in C, these commands apply to braces and brackets too.
644
645 You can use @kbd{M-x check-parens} to find any unbalanced
646 parentheses and unbalanced string quotes in the buffer.
647
648 @menu
649 * Expressions:: Expressions with balanced parentheses.
650 * Moving by Parens:: Commands for moving up, down and across
651 in the structure of parentheses.
652 * Matching:: Insertion of a close-delimiter flashes matching open.
653 @end menu
654
655 @node Expressions
656 @subsection Expressions with Balanced Parentheses
657
658 @cindex sexp
659 @cindex expression
660 @cindex balanced expression
661 These commands deal with balanced expressions, also called
662 @dfn{sexps}@footnote{The word ``sexp'' is used to refer to an
663 expression in Lisp.}.
664
665 @table @kbd
666 @item C-M-f
667 Move forward over a balanced expression (@code{forward-sexp}).
668 @item C-M-b
669 Move backward over a balanced expression (@code{backward-sexp}).
670 @item C-M-k
671 Kill balanced expression forward (@code{kill-sexp}).
672 @item C-M-t
673 Transpose expressions (@code{transpose-sexps}).
674 @item C-M-@@
675 @itemx C-M-@key{SPC}
676 Put mark after following expression (@code{mark-sexp}).
677 @end table
678
679 Each programming language major mode customizes the definition of
680 balanced expressions to suit that language. Balanced expressions
681 typically include symbols, numbers, and string constants, as well as
682 any pair of matching delimiters and their contents. Some languages
683 have obscure forms of expression syntax that nobody has bothered to
684 implement in Emacs.
685
686 @cindex Control-Meta
687 By convention, the keys for these commands are all Control-Meta
688 characters. They usually act on expressions just as the corresponding
689 Meta characters act on words. For instance, the command @kbd{C-M-b}
690 moves backward over a balanced expression, just as @kbd{M-b} moves
691 back over a word.
692
693 @kindex C-M-f
694 @kindex C-M-b
695 @findex forward-sexp
696 @findex backward-sexp
697 To move forward over a balanced expression, use @kbd{C-M-f}
698 (@code{forward-sexp}). If the first significant character after point
699 is an opening delimiter (@samp{(} in Lisp; @samp{(}, @samp{[} or
700 @samp{@{} in C), @kbd{C-M-f} moves past the matching closing
701 delimiter. If the character begins a symbol, string, or number,
702 @kbd{C-M-f} moves over that.
703
704 The command @kbd{C-M-b} (@code{backward-sexp}) moves backward over a
705 balanced expression. The detailed rules are like those above for
706 @kbd{C-M-f}, but with directions reversed. If there are prefix
707 characters (single-quote, backquote and comma, in Lisp) preceding the
708 expression, @kbd{C-M-b} moves back over them as well. The balanced
709 expression commands move across comments as if they were whitespace,
710 in most modes.
711
712 @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation the
713 specified number of times; with a negative argument, it moves in the
714 opposite direction.
715
716 @cindex killing expressions
717 @kindex C-M-k
718 @findex kill-sexp
719 Killing a whole balanced expression can be done with @kbd{C-M-k}
720 (@code{kill-sexp}). @kbd{C-M-k} kills the characters that @kbd{C-M-f}
721 would move over.
722
723 @cindex transposition of expressions
724 @kindex C-M-t
725 @findex transpose-sexps
726 A somewhat random-sounding command which is nevertheless handy is
727 @kbd{C-M-t} (@code{transpose-sexps}), which drags the previous
728 balanced expression across the next one. An argument serves as a
729 repeat count, moving the previous expression over that many following
730 ones. A negative argument drags the previous balanced expression
731 backwards across those before it (thus canceling out the effect of
732 @kbd{C-M-t} with a positive argument). An argument of zero, rather
733 than doing nothing, transposes the balanced expressions ending at or
734 after point and the mark.
735
736 @kindex C-M-@@
737 @kindex C-M-@key{SPC}
738 @findex mark-sexp
739 To set the region around the next balanced expression in the buffer,
740 use @kbd{C-M-@@} (@code{mark-sexp}), which sets mark at the same place
741 that @kbd{C-M-f} would move to. @kbd{C-M-@@} takes arguments like
742 @kbd{C-M-f}. In particular, a negative argument is useful for putting
743 the mark at the beginning of the previous balanced expression. The
744 alias @kbd{C-M-@key{SPC}} is equivalent to @kbd{C-M-@@}. When you
745 repeat this command, or use it in Transient Mark mode when the mark is
746 active, it extends the region by one sexp each time.
747
748 In languages that use infix operators, such as C, it is not possible
749 to recognize all balanced expressions as such because there can be
750 multiple possibilities at a given position. For example, C mode does
751 not treat @samp{foo + bar} as a single expression, even though it
752 @emph{is} one C expression; instead, it recognizes @samp{foo} as one
753 expression and @samp{bar} as another, with the @samp{+} as punctuation
754 between them. Both @samp{foo + bar} and @samp{foo} are legitimate
755 choices for ``the expression following point'' when point is at the
756 @samp{f}, so the expression commands must perforce choose one or the
757 other to operate on. Note that @samp{(foo + bar)} is recognized as a
758 single expression in C mode, because of the parentheses.
759
760 @node Moving by Parens
761 @subsection Moving in the Parenthesis Structure
762
763 @cindex parenthetical groupings
764 @cindex parentheses, moving across
765 @cindex matching parenthesis and braces, moving to
766 @cindex braces, moving across
767 @cindex list commands
768 The Emacs commands for handling parenthetical groupings see nothing
769 except parentheses (or whatever characters must balance in the
770 language you are working with), and the escape characters that might
771 be used to quote those. They are mainly intended for editing
772 programs, but can be useful for editing any text that has parentheses.
773 They are sometimes called ``list'' commands because in Lisp these
774 groupings are lists.
775
776 @table @kbd
777 @item C-M-n
778 Move forward over a parenthetical group (@code{forward-list}).
779 @item C-M-p
780 Move backward over a parenthetical group (@code{backward-list}).
781 @item C-M-u
782 Move up in parenthesis structure (@code{backward-up-list}).
783 @item C-M-d
784 Move down in parenthesis structure (@code{down-list}).
785 @end table
786
787 @kindex C-M-n
788 @kindex C-M-p
789 @findex forward-list
790 @findex backward-list
791 The ``list'' commands @kbd{C-M-n} (@code{forward-list}) and
792 @kbd{C-M-p} (@code{backward-list}) move over one (or @var{n})
793 parenthetical groupings, skipping blithely over any amount of text
794 that doesn't include meaningful parentheses (symbols, strings, etc.).
795
796 @kindex C-M-u
797 @kindex C-M-d
798 @findex backward-up-list
799 @findex down-list
800 @kbd{C-M-n} and @kbd{C-M-p} try to stay at the same level in the
801 parenthesis structure. To move @emph{up} one (or @var{n}) levels, use
802 @kbd{C-M-u} (@code{backward-up-list}). @kbd{C-M-u} moves backward up
803 past one unmatched opening delimiter. A positive argument serves as a
804 repeat count; a negative argument reverses the direction of motion, so
805 that the command moves forward and up one or more levels.
806
807 To move @emph{down} in the parenthesis structure, use @kbd{C-M-d}
808 (@code{down-list}). In Lisp mode, where @samp{(} is the only opening
809 delimiter, this is nearly the same as searching for a @samp{(}. An
810 argument specifies the number of levels to go down.
811
812 @node Matching
813 @subsection Automatic Display Of Matching Parentheses
814 @cindex matching parentheses
815 @cindex parentheses, displaying matches
816
817 The Emacs parenthesis-matching feature is designed to show
818 automatically how parentheses (and other matching delimiters) match in
819 the text. Whenever you type a self-inserting character that is a
820 closing delimiter, the cursor moves momentarily to the location of the
821 matching opening delimiter, provided that is on the screen. If it is
822 not on the screen, Emacs displays some of the text near it in the echo
823 area. Either way, you can tell which grouping you are closing off.
824
825 If the opening delimiter and closing delimiter are mismatched---such
826 as in @samp{[x)}---a warning message is displayed in the echo area.
827
828 @vindex blink-matching-paren
829 @vindex blink-matching-paren-distance
830 @vindex blink-matching-delay
831 Three variables control parenthesis match display:
832
833 @code{blink-matching-paren} turns the feature on or off: @code{nil}
834 disables it, but the default is @code{t} to enable match display.
835
836 @code{blink-matching-delay} says how many seconds to leave the
837 cursor on the matching opening delimiter, before bringing it back to
838 the real location of point; the default is 1, but on some systems it
839 is useful to specify a fraction of a second.
840
841 @code{blink-matching-paren-distance} specifies how many characters
842 back to search to find the matching opening delimiter. If the match
843 is not found in that distance, scanning stops, and nothing is displayed.
844 This is to prevent the scan for the matching delimiter from wasting
845 lots of time when there is no match. The default is 25600.
846
847 @cindex Show Paren mode
848 @cindex highlighting matching parentheses
849 @findex show-paren-mode
850 Show Paren mode provides a more powerful kind of automatic matching.
851 Whenever point is after a closing delimiter, that delimiter and its
852 matching opening delimiter are both highlighted; otherwise, if point
853 is before an opening delimiter, the matching closing delimiter is
854 highlighted. (There is no need to highlight the opening delimiter in
855 that case, because the cursor appears on top of that character.) Use
856 the command @kbd{M-x show-paren-mode} to enable or disable this mode.
857
858 By default, @code{show-paren-mode} uses colors to highlight the
859 parentheses. However, if your display doesn't support colors, you can
860 customize the faces @code{show-paren-match-face} and
861 @code{show-paren-mismatch-face} to use other attributes, such as bold or
862 underline. @xref{Face Customization}.
863
864 @node Comments
865 @section Manipulating Comments
866 @cindex comments
867
868 Because comments are such an important part of programming, Emacs
869 provides special commands for editing and inserting comments. It can
870 also do spell checking on comments with Flyspell Prog mode
871 (@pxref{Spelling}).
872
873 @menu
874 * Comment Commands:: Inserting, killing, and indenting comments.
875 * Multi-Line Comments:: Commands for adding and editing multi-line comments.
876 * Options for Comments::Customizing the comment features.
877 @end menu
878
879 @node Comment Commands
880 @subsection Comment Commands
881 @cindex indentation for comments
882
883 The comment commands in this table insert, kill and align comments.
884 They are described in this section and following sections.
885
886 @table @asis
887 @item @kbd{M-;}
888 Insert or realign comment on current line; alternatively, comment or
889 uncomment the region (@code{comment-dwim}).
890 @item @kbd{C-u M-;}
891 Kill comment on current line (@code{comment-kill}).
892 @item @kbd{C-x ;}
893 Set comment column (@code{comment-set-column}).
894 @item @kbd{C-M-j}
895 @itemx @kbd{M-j}
896 Like @key{RET} followed by inserting and aligning a comment
897 (@code{comment-indent-new-line}). @xref{Multi-Line Comments}.
898 @item @kbd{M-x comment-region}
899 @itemx @kbd{C-c C-c} (in C-like modes)
900 Add or remove comment delimiters on all the lines in the region.
901 @end table
902
903 @kindex M-;
904 @findex comment-dwim
905 The command to create or align a comment is @kbd{M-;}
906 (@code{comment-dwim}). The word ``dwim'' is an acronym for ``Do What
907 I Mean''; it indicates that this command can be used for many
908 different jobs relating to comments, depending on the situation where
909 you use it.
910
911 If there is no comment already on the line, @kbd{M-;} inserts a new
912 comment, aligned at a specific column called the @dfn{comment column}.
913 The new comment begins with the string Emacs thinks comments should
914 start with (the value of @code{comment-start}; see below). Point is
915 after that string, so you can insert the text of the comment right
916 away. If the major mode has specified a string to terminate comments,
917 @kbd{M-;} inserts that too, to keep the syntax valid.
918
919 If the text of the line extends past the comment column, then the
920 comment start string is indented to a suitable boundary (usually, at
921 least one space is inserted).
922
923 You can also use @kbd{M-;} to align an existing comment. If a line
924 already contains the comment-start string, @kbd{M-;} reindents it to
925 the conventional alignment and moves point after it. (Exception:
926 comments starting in column 0 are not moved.) Even when an existing
927 comment is properly aligned, @kbd{M-;} is still useful for moving
928 directly to the start of the text inside the comment.
929
930 @findex comment-kill
931 @kindex C-u M-;
932 @kbd{C-u M-;} kills any comment on the current line, along with the
933 whitespace before it. To reinsert the comment on another line, move
934 to the end of that line, do @kbd{C-y}, and then do @kbd{M-;} to
935 realign it.
936
937 Note that @kbd{C-u M-;} is not a distinct key; it is @kbd{M-;}
938 (@code{comment-dwim}) with a prefix argument. That command is
939 programmed so that when it receives a prefix argument it calls
940 @code{comment-kill}. However, @code{comment-kill} is a valid command
941 in its own right, and you can bind it directly to a key if you wish.
942
943 @kbd{M-;} does two other jobs when used with an active region in
944 Transient Mark mode (@pxref{Transient Mark}). Then it either adds or
945 removes comment delimiters on each line of the region. (If every line
946 is a comment, it removes comment delimiters from each; otherwise, it
947 adds comment delimiters to each.) If you are not using Transient Mark
948 mode, then you should use the commands @code{comment-region} and
949 @code{uncomment-region} to do these jobs (@pxref{Multi-Line Comments}).
950 A prefix argument used in these circumstances specifies how many
951 comment delimiters to add or how many to delete.
952
953 Some major modes have special rules for indenting certain kinds of
954 comments in certain contexts. For example, in Lisp code, comments which
955 start with two semicolons are indented as if they were lines of code,
956 instead of at the comment column. Comments which start with three
957 semicolons are supposed to start at the left margin. Emacs understands
958 these conventions by indenting a double-semicolon comment using @key{TAB},
959 and by not changing the indentation of a triple-semicolon comment at all.
960
961 @example
962 ;; This function is just an example
963 ;;; Here either two or three semicolons are appropriate.
964 (defun foo (x)
965 ;;; And now, the first part of the function:
966 ;; The following line adds one.
967 (1+ x)) ; This line adds one.
968 @end example
969
970 For C-like buffers, you can configure the exact effect of @kbd{M-;}
971 more flexibly than for most buffers by setting the user options
972 @code{c-indent-comment-alist} and
973 @code{c-indent-comments-syntactically-p}. For example, on a line
974 ending in a closing brace, @kbd{M-;} puts the comment one space after
975 the brace rather than at @code{comment-column}. For full details see
976 @ref{Comment Commands,,, ccmode, The CC Mode Manual}.
977
978 @node Multi-Line Comments
979 @subsection Multiple Lines of Comments
980
981 @kindex C-M-j
982 @kindex M-j
983 @cindex blank lines in programs
984 @findex comment-indent-new-line
985
986 If you are typing a comment and wish to continue it on another line,
987 you can use the command @kbd{C-M-j} or @kbd{M-j}
988 (@code{comment-indent-new-line}). This terminates the comment you are
989 typing, creates a new blank line afterward, and begins a new comment
990 indented under the old one. Or, if the language syntax permits
991 comments to extend beyond ends of lines, it may instead continue the
992 existing comment on the new blank line---this is controlled by the
993 setting of @code{comment-multi-line} (@pxref{Options for Comments}).
994 If point is not at the end of the line when you type the command, the
995 text on the rest of the line becomes part of the new comment line.
996 When Auto Fill mode is on, going past the fill column while typing a
997 comment causes the comment to be continued in just this fashion.
998
999 @kindex C-c C-c (C mode)
1000 @findex comment-region
1001 To turn existing lines into comment lines, use the @kbd{M-x
1002 comment-region} command (or type @kbd{C-c C-c} in C-like buffers). It
1003 adds comment delimiters to the lines that start in the region, thus
1004 commenting them out. With a negative argument, it does the
1005 opposite---it deletes comment delimiters from the lines in the region.
1006
1007 With a positive argument, @code{comment-region} duplicates the last
1008 character of the comment start sequence it adds; the argument specifies
1009 how many copies of the character to insert. Thus, in Lisp mode,
1010 @kbd{C-u 2 M-x comment-region} adds @samp{;;} to each line. Duplicating
1011 the comment delimiter is a way of calling attention to the comment. It
1012 can also affect how the comment is indented. In Lisp, for proper
1013 indentation, you should use an argument of two or three, if between defuns;
1014 if within a defun, it must be three.
1015
1016 You can configure C Mode such that when you type a @samp{/} at the
1017 start of a line in a multi-line block comment, this closes the
1018 comment. Enable the @code{comment-close-slash} clean-up for this.
1019 @xref{Clean-ups,,, ccmode, The CC Mode Manual}.
1020
1021 @node Options for Comments
1022 @subsection Options Controlling Comments
1023
1024 @vindex comment-column
1025 @kindex C-x ;
1026 @findex comment-set-column
1027 The @dfn{comment column}, the column at which Emacs tries to place
1028 comments, is stored in the variable @code{comment-column}. You can
1029 set it to a number explicitly. Alternatively, the command @kbd{C-x ;}
1030 (@code{comment-set-column}) sets the comment column to the column
1031 point is at. @kbd{C-u C-x ;} sets the comment column to match the
1032 last comment before point in the buffer, and then does a @kbd{M-;} to
1033 align the current line's comment under the previous one.
1034
1035 The variable @code{comment-column} is per-buffer: setting the variable
1036 in the normal fashion affects only the current buffer, but there is a
1037 default value which you can change with @code{setq-default}.
1038 @xref{Locals}. Many major modes initialize this variable for the
1039 current buffer.
1040
1041 @vindex comment-start-skip
1042 The comment commands recognize comments based on the regular
1043 expression that is the value of the variable @code{comment-start-skip}.
1044 Make sure this regexp does not match the null string. It may match more
1045 than the comment starting delimiter in the strictest sense of the word;
1046 for example, in C mode the value of the variable is
1047 @c This stops M-q from breaking the line inside that @code.
1048 @code{@w{"/\\*+ *\\|//+ *"}}, which matches extra stars and spaces
1049 after the @samp{/*} itself, and accepts C++ style comments also.
1050 (Note that @samp{\\} is needed in Lisp syntax to include a @samp{\} in
1051 the string, which is needed to deny the first star its special meaning
1052 in regexp syntax. @xref{Regexp Backslash}.)
1053
1054 @vindex comment-start
1055 @vindex comment-end
1056 When a comment command makes a new comment, it inserts the value of
1057 @code{comment-start} to begin it. The value of @code{comment-end} is
1058 inserted after point, so that it will follow the text that you will
1059 insert into the comment. When @code{comment-end} is non-empty, it
1060 should start with a space. For example, in C mode,
1061 @code{comment-start} has the value @w{@code{"/* "}} and
1062 @code{comment-end} has the value @w{@code{" */"}}.
1063
1064 @vindex comment-padding
1065 The variable @code{comment-padding} specifies how many spaces
1066 @code{comment-region} should insert on each line between the comment
1067 delimiter and the line's original text. The default is 1, to insert
1068 one space. @code{nil} means 0. Alternatively, @code{comment-padding}
1069 can hold the actual string to insert.
1070
1071 @vindex comment-multi-line
1072 The variable @code{comment-multi-line} controls how @kbd{C-M-j}
1073 (@code{indent-new-comment-line}) behaves when used inside a comment.
1074 Specifically, when @code{comment-multi-line} is @code{nil}, the
1075 command inserts a comment terminator, begins a new line, and finally
1076 inserts a comment starter. Otherwise it does not insert the
1077 terminator and starter, so it effectively continues the current
1078 comment across multiple lines. In languages that allow multi-line
1079 comments, the choice of value for this variable is a matter of taste.
1080 The default for this variable depends on the major mode.
1081
1082 @vindex comment-indent-function
1083 The variable @code{comment-indent-function} should contain a function
1084 that will be called to compute the indentation for a newly inserted
1085 comment or for aligning an existing comment. It is set differently by
1086 various major modes. The function is called with no arguments, but with
1087 point at the beginning of the comment, or at the end of a line if a new
1088 comment is to be inserted. It should return the column in which the
1089 comment ought to start. For example, in Lisp mode, the indent hook
1090 function bases its decision on how many semicolons begin an existing
1091 comment, and on the code in the preceding lines.
1092
1093 @node Documentation
1094 @section Documentation Lookup
1095
1096 Emacs provides several features you can use to look up the
1097 documentation of functions, variables and commands that you plan to
1098 use in your program.
1099
1100 @menu
1101 * Info Lookup:: Looking up library functions and commands
1102 in Info files.
1103 * Man Page:: Looking up man pages of library functions and commands.
1104 * Lisp Doc:: Looking up Emacs Lisp functions, etc.
1105 @end menu
1106
1107 @node Info Lookup
1108 @subsection Info Documentation Lookup
1109
1110 @findex info-lookup-symbol
1111 @findex info-lookup-file
1112 @kindex C-h S
1113 For C, Lisp, and other languages that have documentation in Info,
1114 you can use @kbd{C-h S} (@code{info-lookup-symbol}) to view the Info
1115 documentation for a symbol used in the program. You specify the
1116 symbol with the minibuffer; the default is the symbol appearing in the
1117 buffer at point. For example, in C mode this looks for the symbol in
1118 the C Library Manual.
1119
1120 The major mode determines where to look for documentation for the
1121 symbol---which Info files to look in, and which indices to search.
1122 You can also use @kbd{M-x info-lookup-file} to look for documentation
1123 for a file name.
1124
1125 This feature currently supports the modes AWK, Autoconf, Bison, C,
1126 Emacs Lisp, LaTeX, M4, Makefile, Octave, Perl, Scheme, and Texinfo,
1127 provided you have installed the relevant Info files, which are
1128 typically available with the appropriate GNU package.
1129
1130 @node Man Page
1131 @subsection Man Page Lookup
1132
1133 @cindex manual page
1134 On Unix, the main form of on-line documentation was the @dfn{manual
1135 page} or @dfn{man page}. In the GNU operating system, we hope to
1136 replace man pages with better-organized manuals that you can browse
1137 with Info (@pxref{Misc Help}). This process is not finished, so it is
1138 still useful to read manual pages.
1139
1140 @findex manual-entry
1141 You can read the man page for an operating system command, library
1142 function, or system call, with the @kbd{M-x man} command. It
1143 runs the @code{man} program to format the man page; if the system
1144 permits, it runs @code{man} asynchronously, so that you can keep on
1145 editing while the page is being formatted. (On MS-DOS and MS-Windows
1146 3, you cannot edit while Emacs waits for @code{man} to finish.) The
1147 result goes in a buffer named @samp{*Man @var{topic}*}. These buffers
1148 use a special major mode, Man mode, that facilitates scrolling and
1149 jumping to other manual pages. For details, type @kbd{C-h m} while in
1150 a man page buffer.
1151
1152 @cindex sections of manual pages
1153 Each man page belongs to one of ten or more @dfn{sections}, each
1154 named by a digit or by a digit and a letter. Sometimes there are
1155 multiple man pages with the same name in different sections. To read
1156 a man page from a specific section, type
1157 @samp{@var{topic}(@var{section})} or @samp{@var{section} @var{topic}}
1158 when @kbd{M-x manual-entry} prompts for the topic. For example, to
1159 read the man page for the C library function @code{chmod} (as opposed
1160 to a command of the same name), type @kbd{M-x manual-entry @key{RET}
1161 chmod(2) @key{RET}} (@code{chmod} is a system call, so it is in
1162 section @samp{2}).
1163
1164 @vindex Man-switches
1165 If you do not specify a section, the results depend on how the
1166 @code{man} program works on your system. Some of them display only
1167 the first man page they find. Others display all man pages that have
1168 the specified name, so you can move between them with the @kbd{M-n}
1169 and @kbd{M-p} keys@footnote{On some systems, the @code{man} program
1170 accepts a @samp{-a} command-line option which tells it to display all
1171 the man pages for the specified topic. If you want this behavior, you
1172 can add this option to the value of the variable @code{Man-switches}.}.
1173 The mode line shows how many manual pages are present in the Man buffer.
1174
1175 @vindex Man-fontify-manpage-flag
1176 By default, Emacs highlights the text in man pages. For a long man
1177 page, highlighting can take substantial time. You can turn off
1178 highlighting of man pages by setting the variable
1179 @code{Man-fontify-manpage-flag} to @code{nil}.
1180
1181 @findex Man-fontify-manpage
1182 If you insert the text of a man page into an Emacs buffer in some
1183 other fashion, you can use the command @kbd{M-x Man-fontify-manpage} to
1184 perform the same conversions that @kbd{M-x manual-entry} does.
1185
1186 @findex woman
1187 @cindex manual pages, on MS-DOS/MS-Windows
1188 An alternative way of reading manual pages is the @kbd{M-x woman}
1189 command@footnote{The name of the command, @code{woman}, is an acronym
1190 for ``w/o (without) man,'' since it doesn't use the @code{man}
1191 program.}. Unlike @kbd{M-x man}, it does not run any external
1192 programs to format and display the man pages; instead it does the job
1193 in Emacs Lisp, so it works on systems such as MS-Windows, where the
1194 @code{man} program (and other programs it uses) are not generally
1195 available.
1196
1197 @kbd{M-x woman} prompts for a name of a manual page, and provides
1198 completion based on the list of manual pages that are installed on
1199 your machine; the list of available manual pages is computed
1200 automatically the first time you invoke @code{woman}. The word at
1201 point in the current buffer is used to suggest the default for the
1202 name the manual page.
1203
1204 With a numeric argument, @kbd{M-x woman} recomputes the list of the
1205 manual pages used for completion. This is useful if you add or delete
1206 manual pages.
1207
1208 If you type a name of a manual page and @kbd{M-x woman} finds that
1209 several manual pages by the same name exist in different sections, it
1210 pops up a window with possible candidates asking you to choose one of
1211 them.
1212
1213 @vindex woman-manpath
1214 By default, @kbd{M-x woman} looks for manual pages in the
1215 directories specified in the @code{MANPATH} environment variable. (If
1216 @code{MANPATH} is not set, @code{woman} uses a suitable default value,
1217 which can be customized.) More precisely, @code{woman} looks for
1218 subdirectories that match the shell wildcard pattern @file{man*} in each one
1219 of these directories, and tries to find the manual pages in those
1220 subdirectories. When first invoked, @kbd{M-x woman} converts the
1221 value of @code{MANPATH} to a list of directory names and stores that
1222 list in the @code{woman-manpath} variable. Changing the value of this
1223 variable is another way to control the list of directories used.
1224
1225 @vindex woman-path
1226 You can also augment the list of directories searched by
1227 @code{woman} by setting the value of the @code{woman-path} variable.
1228 This variable should hold a list of specific directories which
1229 @code{woman} should search, in addition to those in
1230 @code{woman-manpath}. Unlike @code{woman-manpath}, the directories in
1231 @code{woman-path} are searched for the manual pages, not for
1232 @file{man*} subdirectories.
1233
1234 @findex woman-find-file
1235 Occasionally, you might need to display manual pages that are not in
1236 any of the directories listed by @code{woman-manpath} and
1237 @code{woman-path}. The @kbd{M-x woman-find-file} command prompts for a
1238 name of a manual page file, with completion, and then formats and
1239 displays that file like @kbd{M-x woman} does.
1240
1241 @vindex woman-dired-keys
1242 The first time you invoke @kbd{M-x woman}, it defines the Dired
1243 @kbd{W} key to run the @code{woman-find-file} command on the current
1244 line's file. You can disable this by setting the variable
1245 @code{woman-dired-keys} to @code{nil}. @xref{Dired}. In addition,
1246 the Tar-mode @kbd{w} key is define to invoke @code{woman-find-file} on
1247 the current line's archive member.
1248
1249 For more information about setting up and using @kbd{M-x woman}, see
1250 @ref{Top, WoMan, Browse UN*X Manual Pages WithOut Man, woman, The WoMan
1251 Manual}.
1252
1253 @node Lisp Doc
1254 @subsection Emacs Lisp Documentation Lookup
1255
1256 As you edit Lisp code to be run in Emacs, you can use the commands
1257 @kbd{C-h f} (@code{describe-function}) and @kbd{C-h v}
1258 (@code{describe-variable}) to view documentation of functions and
1259 variables that you want to use. These commands use the minibuffer to
1260 read the name of a function or variable to document, and display the
1261 documentation in a window. Their default arguments are based on the
1262 code in the neighborhood of point. For @kbd{C-h f}, the default is
1263 the function called in the innermost list containing point. @kbd{C-h
1264 v} uses the symbol name around or adjacent to point as its default.
1265
1266 @cindex Eldoc mode
1267 @findex eldoc-mode
1268 A more automatic but less powerful method is Eldoc mode. This minor
1269 mode constantly displays in the echo area the argument list for the
1270 function being called at point. (In other words, it finds the
1271 function call that point is contained in, and displays the argument
1272 list of that function.) If point is over a documented variable, it
1273 shows the first line of the variable's docstring. Eldoc mode applies
1274 in Emacs Lisp and Lisp Interaction modes, and perhaps a few others
1275 that provide special support for looking up doc strings. Use the
1276 command @kbd{M-x eldoc-mode} to enable or disable this feature.
1277
1278 @node Hideshow
1279 @section Hideshow minor mode
1280
1281 @findex hs-minor-mode
1282 Hideshow minor mode provides selective display of portions of a
1283 program, known as @dfn{blocks}. You can use @kbd{M-x hs-minor-mode}
1284 to enable or disable this mode, or add @code{hs-minor-mode} to the
1285 mode hook for certain major modes in order to enable it automatically
1286 for those modes.
1287
1288 Just what constitutes a block depends on the major mode. In C mode
1289 or C++ mode, they are delimited by braces, while in Lisp mode and
1290 similar modes they are delimited by parentheses. Multi-line comments
1291 also count as blocks.
1292
1293 @findex hs-hide-all
1294 @findex hs-hide-block
1295 @findex hs-show-all
1296 @findex hs-show-block
1297 @findex hs-show-region
1298 @findex hs-hide-level
1299 @findex hs-minor-mode
1300 @kindex C-c @@ C-h
1301 @kindex C-c @@ C-s
1302 @kindex C-c @@ C-M-h
1303 @kindex C-c @@ C-M-s
1304 @kindex C-c @@ C-r
1305 @kindex C-c @@ C-l
1306 @kindex S-Mouse-2
1307 @table @kbd
1308 @item C-c @@ C-h
1309 Hide the current block (@code{hs-hide-block}).
1310 @item C-c @@ C-s
1311 Show the current block (@code{hs-show-block}).
1312 @item C-c @@ C-c
1313 Either hide or show the current block (@code{hs-toggle-hiding}).
1314 @item S-Mouse-2
1315 Either hide or show the block you click on (@code{hs-mouse-toggle-hiding}).
1316 @item C-c @@ C-M-h
1317 Hide all top-level blocks (@code{hs-hide-all}).
1318 @item C-c @@ C-M-s
1319 Show everything in the buffer (@code{hs-show-all}).
1320 @item C-c @@ C-l
1321 Hide all blocks @var{n} levels below this block
1322 (@code{hs-hide-level}).
1323 @end table
1324
1325 @vindex hs-hide-comments-when-hiding-all
1326 @vindex hs-isearch-open
1327 @vindex hs-special-modes-alist
1328 These variables exist for customizing Hideshow mode.
1329
1330 @table @code
1331 @item hs-hide-comments-when-hiding-all
1332 Non-@code{nil} says that @kbd{hs-hide-all} should hide comments too.
1333
1334 @item hs-isearch-open
1335 Specifies what kind of hidden blocks to open in Isearch mode.
1336 The value should be one of these four symbols:
1337
1338 @table @code
1339 @item code
1340 Open only code blocks.
1341 @item comment
1342 Open only comments.
1343 @item t
1344 Open both code blocks and comments.
1345 @item nil
1346 Open neither code blocks nor comments.
1347 @end table
1348
1349 @item hs-special-modes-alist
1350 A list of elements, each specifying how to initialize Hideshow
1351 variables for one major mode. See the variable's documentation string
1352 for more information.
1353 @end table
1354
1355 @node Symbol Completion
1356 @section Completion for Symbol Names
1357 @cindex completion (symbol names)
1358
1359 In Emacs, completion is something you normally do in the minibuffer.
1360 But one kind of completion is available in all buffers: completion for
1361 symbol names.
1362
1363 @kindex M-TAB
1364 The character @kbd{M-@key{TAB}} runs a command to complete the
1365 partial symbol before point against the set of meaningful symbol
1366 names. This command inserts at point any additional characters that
1367 it can determine from the partial name. (If your window manager
1368 defines @kbd{M-@key{TAB}} to switch windows, you can type
1369 @kbd{@key{ESC} @key{TAB}} or @kbd{C-M-i}.)
1370
1371 If the partial name in the buffer has multiple possible completions
1372 that differ in the very next character, so that it is impossible to
1373 complete even one more character, @kbd{M-@key{TAB}} displays a list of
1374 all possible completions in another window.
1375
1376 @cindex tags-based completion
1377 @cindex Info index completion
1378 @findex complete-symbol
1379 In most programming language major modes, @kbd{M-@key{TAB}} runs the
1380 command @code{complete-symbol}, which provides two kinds of completion.
1381 Normally it does completion based on a tags table (@pxref{Tags}); with a
1382 numeric argument (regardless of the value), it does completion based on
1383 the names listed in the Info file indexes for your language. Thus, to
1384 complete the name of a symbol defined in your own program, use
1385 @kbd{M-@key{TAB}} with no argument; to complete the name of a standard
1386 library function, use @kbd{C-u M-@key{TAB}}. Of course, Info-based
1387 completion works only if there is an Info file for the standard library
1388 functions of your language, and only if it is installed at your site.
1389
1390 @cindex Lisp symbol completion
1391 @cindex completion (Lisp symbols)
1392 @findex lisp-complete-symbol
1393 In Emacs-Lisp mode, the name space for completion normally consists of
1394 nontrivial symbols present in Emacs---those that have function
1395 definitions, values or properties. However, if there is an
1396 open-parenthesis immediately before the beginning of the partial symbol,
1397 only symbols with function definitions are considered as completions.
1398 The command which implements this is @code{lisp-complete-symbol}.
1399
1400 In Text mode and related modes, @kbd{M-@key{TAB}} completes words
1401 based on the spell-checker's dictionary. @xref{Spelling}.
1402
1403 @node Glasses
1404 @section Glasses minor mode
1405 @cindex Glasses mode
1406 @cindex identifiers, making long ones readable
1407 @cindex StudlyCaps, making them readable
1408 @findex glasses-mode
1409
1410 Glasses minor mode makes @samp{unreadableIdentifiersLikeThis}
1411 readable by altering the way they display. It knows two different
1412 ways to do this: by displaying underscores between a lower-case letter
1413 and the following capital letter, and by emboldening the capital
1414 letters. It does not alter the buffer text, only the way they
1415 display, so you can use it even on read-only buffers. You can use the
1416 command @kbd{M-x glasses-mode} to enable or disable the mode in the
1417 current buffer; you can also add @code{glasses-mode} to the mode hook
1418 of the programming language major modes in which you normally want
1419 to use Glasses mode.
1420
1421 @node Misc for Programs
1422 @section Other Features Useful for Editing Programs
1423
1424 A number of Emacs commands that aren't designed specifically for
1425 editing programs are useful for that nonetheless.
1426
1427 The Emacs commands that operate on words, sentences and paragraphs
1428 are useful for editing code. Most symbols names contain words
1429 (@pxref{Words}); sentences can be found in strings and comments
1430 (@pxref{Sentences}). Paragraphs in the strict sense can be found in
1431 program code (in long comments), but the paragraph commands are useful
1432 in other places too, because programming language major modes define
1433 paragraphs to begin and end at blank lines (@pxref{Paragraphs}).
1434 Judicious use of blank lines to make the program clearer will also
1435 provide useful chunks of text for the paragraph commands to work on.
1436 Auto Fill mode, if enabled in a programming language major mode,
1437 indents the new lines which it creates.
1438
1439 The selective display feature is useful for looking at the overall
1440 structure of a function (@pxref{Selective Display}). This feature
1441 hides the lines that are indented more than a specified amount.
1442 Programming modes often support Outline minor mode (@pxref{Outline
1443 Mode}). The Foldout package provides folding-editor features
1444 (@pxref{Foldout}).
1445
1446 The ``automatic typing'' features may be useful for writing programs.
1447 @xref{Top,,Autotyping, autotype, Autotyping}.
1448
1449 @node C Modes
1450 @section C and Related Modes
1451 @cindex C mode
1452 @cindex Java mode
1453 @cindex Pike mode
1454 @cindex IDL mode
1455 @cindex CORBA IDL mode
1456 @cindex Objective C mode
1457 @cindex C++ mode
1458 @cindex AWK mode
1459 @cindex mode, Java
1460 @cindex mode, C
1461 @cindex mode, C++
1462 @cindex mode, Objective C
1463 @cindex mode, CORBA IDL
1464 @cindex mode, Pike
1465 @cindex mode, AWK
1466
1467 This section gives a brief description of the special features
1468 available in C, C++, Objective-C, Java, CORBA IDL, Pike and AWK modes.
1469 (These are called ``C mode and related modes.'') @xref{Top, , CC Mode,
1470 ccmode, CC Mode}, for a more extensive description of these modes
1471 and their special features.
1472
1473 @menu
1474 * Motion in C:: Commands to move by C statements, etc.
1475 * Electric C:: Colon and other chars can automatically reindent.
1476 * Hungry Delete:: A more powerful DEL command.
1477 * Other C Commands:: Filling comments, viewing expansion of macros,
1478 and other neat features.
1479 @end menu
1480
1481 @node Motion in C
1482 @subsection C Mode Motion Commands
1483
1484 This section describes commands for moving point, in C mode and
1485 related modes.
1486
1487 @table @code
1488 @item M-x c-beginning-of-defun
1489 @itemx M-x c-end-of-defun
1490 @findex c-beginning-of-defun
1491 @findex c-end-of-defun
1492 Move point to the beginning or end of the current function or
1493 top-level definition. These are found by searching for the least
1494 enclosing braces. (By contrast, @code{beginning-of-defun} and
1495 @code{end-of-defun} search for braces in column zero.) If you are
1496 editing code where the opening brace of a function isn't placed in
1497 column zero, you may wish to bind @code{C-M-a} and @code{C-M-e} to
1498 these commands. @xref{Moving by Defuns}.
1499
1500 @item C-c C-u
1501 @kindex C-c C-u @r{(C mode)}
1502 @findex c-up-conditional
1503 Move point back to the containing preprocessor conditional, leaving the
1504 mark behind. A prefix argument acts as a repeat count. With a negative
1505 argument, move point forward to the end of the containing
1506 preprocessor conditional.
1507
1508 @samp{#elif} is equivalent to @samp{#else} followed by @samp{#if}, so
1509 the function will stop at a @samp{#elif} when going backward, but not
1510 when going forward.
1511
1512 @item C-c C-p
1513 @kindex C-c C-p @r{(C mode)}
1514 @findex c-backward-conditional
1515 Move point back over a preprocessor conditional, leaving the mark
1516 behind. A prefix argument acts as a repeat count. With a negative
1517 argument, move forward.
1518
1519 @item C-c C-n
1520 @kindex C-c C-n @r{(C mode)}
1521 @findex c-forward-conditional
1522 Move point forward across a preprocessor conditional, leaving the mark
1523 behind. A prefix argument acts as a repeat count. With a negative
1524 argument, move backward.
1525
1526 @item M-a
1527 @kindex M-a (C mode)
1528 @findex c-beginning-of-statement
1529 Move point to the beginning of the innermost C statement
1530 (@code{c-beginning-of-statement}). If point is already at the beginning
1531 of a statement, move to the beginning of the preceding statement. With
1532 prefix argument @var{n}, move back @var{n} @minus{} 1 statements.
1533
1534 In comments or in strings which span more than one line, this command
1535 moves by sentences instead of statements.
1536
1537 @item M-e
1538 @kindex M-e (C mode)
1539 @findex c-end-of-statement
1540 Move point to the end of the innermost C statement or sentence; like
1541 @kbd{M-a} except that it moves in the other direction
1542 (@code{c-end-of-statement}).
1543
1544 @item M-x c-backward-into-nomenclature
1545 @findex c-backward-into-nomenclature
1546 Move point backward to beginning of a C++ nomenclature section or
1547 word. With prefix argument @var{n}, move @var{n} times. If @var{n}
1548 is negative, move forward. C++ nomenclature means a symbol name in
1549 the style of NamingSymbolsWithMixedCaseAndNoUnderlines; each capital
1550 letter begins a section or word. Rather than this command, you might
1551 well prefer the newer ``Subword Mode'', which does the same thing
1552 better. @xref{Other C Commands}.
1553
1554 In the GNU project, we recommend using underscores to separate words
1555 within an identifier in C or C++, rather than using case distinctions.
1556
1557 @item M-x c-forward-into-nomenclature
1558 @findex c-forward-into-nomenclature
1559 Move point forward to end of a C++ nomenclature section or word.
1560 With prefix argument @var{n}, move @var{n} times.
1561 @end table
1562
1563 @node Electric C
1564 @subsection Electric C Characters
1565
1566 In C mode and related modes, certain printing characters are
1567 @dfn{electric}---in addition to inserting themselves, they also
1568 reindent the current line, and optionally also insert newlines. The
1569 ``electric'' characters are @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#},
1570 @kbd{;}, @kbd{,}, @kbd{<}, @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and
1571 @kbd{)}. @xref{Electric Keys,,, ccmode, The CC Mode Manual}.
1572
1573 You might find electric indentation inconvenient if you are editing
1574 chaotically indented code. If you are new to CC Mode, you might find
1575 it disconcerting. You can toggle electric action with the command
1576 @kbd{C-c C-l}; when it is enabled, @samp{/l} appears in the mode line
1577 after the mode name:
1578
1579 @table @kbd
1580 @item C-c C-l
1581 @kindex C-c C-l @r{(C mode)}
1582 @findex c-toggle-electric-state
1583 Toggle electric action (@code{c-toggle-electric-state}). With a
1584 prefix argument, this command enables electric action if the argument
1585 is positive, disables it if it is negative.
1586 @end table
1587
1588 Electric characters insert newlines only when, in addition to the
1589 electric state, the @dfn{auto-newline} feature is enabled (indicated
1590 by @samp{/la} in the mode line after the mode name). You can turn
1591 this feature on or off with the command @kbd{C-c C-a}:
1592
1593 @table @kbd
1594 @item C-c C-a
1595 @kindex C-c C-a @r{(C mode)}
1596 @findex c-toggle-auto-newline
1597 Toggle the auto-newline feature (@code{c-toggle-auto-newline}). With a
1598 prefix argument, this command turns the auto-newline feature on if the
1599 argument is positive, and off if it is negative.
1600 @end table
1601
1602 Usually the CC Mode style system (@pxref{Styles,,, ccmode, The CC
1603 Mode Manual}) configures the exact circumstances in which Emacs
1604 inserts auto-newlines, but you can configure this directly instead.
1605 Full details are at @ref{Custom Auto-newlines,,, ccmode, The CC Mode
1606 Manual}, but there is a short summary below.
1607
1608 The colon character is electric because that is appropriate for a
1609 single colon. But when you want to insert a double colon in C++, the
1610 electric behavior of colon is inconvenient. You can insert a double
1611 colon with no reindentation or newlines by typing @kbd{C-c :}:
1612
1613 @table @kbd
1614 @item C-c :
1615 @ifinfo
1616 @c This uses ``colon'' instead of a literal `:' because Info cannot
1617 @c cope with a `:' in a menu
1618 @kindex C-c @key{colon} @r{(C mode)}
1619 @end ifinfo
1620 @ifnotinfo
1621 @kindex C-c : @r{(C mode)}
1622 @end ifnotinfo
1623 @findex c-scope-operator
1624 Insert a double colon scope operator at point, without reindenting the
1625 line or adding any newlines (@code{c-scope-operator}).
1626 @end table
1627
1628 @vindex c-electric-pound-behavior
1629 The electric @kbd{#} key reindents the line if it appears to be the
1630 beginning of a preprocessor directive. This happens when the value of
1631 @code{c-electric-pound-behavior} is @code{(alignleft)}. You can turn
1632 this feature off by setting @code{c-electric-pound-behavior} to
1633 @code{nil}.
1634
1635 @vindex c-hanging-braces-alist
1636 The variable @code{c-hanging-braces-alist} controls the insertion of
1637 newlines before and after inserted braces. It is an association list
1638 with elements of the following form: @code{(@var{syntactic-symbol}
1639 . @var{nl-list})}. Most of the syntactic symbols that appear in
1640 @code{c-offsets-alist} are meaningful here as well.
1641
1642 The list @var{nl-list} may contain either of the symbols
1643 @code{before} or @code{after}, or both; or it may be @code{nil}. When a
1644 brace is inserted, the syntactic context it defines is looked up in
1645 @code{c-hanging-braces-alist}; if it is found, the @var{nl-list} is used
1646 to determine where newlines are inserted: either before the brace,
1647 after, or both. If not found, the default is to insert a newline both
1648 before and after braces.
1649
1650 @vindex c-hanging-colons-alist
1651 The variable @code{c-hanging-colons-alist} controls the insertion of
1652 newlines before and after inserted colons. It is an association list
1653 with elements of the following form: @code{(@var{syntactic-symbol}
1654 . @var{nl-list})}. The list @var{nl-list} may contain either of the
1655 symbols @code{before} or @code{after}, or both; or it may be @code{nil}.
1656
1657 When a colon is inserted, the syntactic symbol it defines is looked
1658 up in this list, and if found, the @var{nl-list} is used to determine
1659 where newlines are inserted: either before the brace, after, or both.
1660 If the syntactic symbol is not found in this list, no newlines are
1661 inserted.
1662
1663 @vindex c-cleanup-list
1664 Electric characters can also delete newlines automatically when the
1665 auto-newline feature is enabled. This feature makes auto-newline more
1666 acceptable, by deleting the newlines in the most common cases where
1667 you do not want them. Emacs can recognize several cases in which
1668 deleting a newline might be desirable; by setting the variable
1669 @code{c-cleanup-list}, you can specify @emph{which} of these cases
1670 that should happen. @xref{Clean-ups,,, ccmode, The CC Mode Manual}.
1671 The variable's value is a list of symbols, each describing one case
1672 for possible deletion of a newline. Here is a summary of the
1673 meaningful symbols and their meanings:
1674
1675 @table @code
1676 @item brace-catch-brace
1677 Clean up @samp{@} catch (@var{condition}) @{} constructs by placing the
1678 entire construct on a single line. The clean-up occurs when you type
1679 the @samp{@{}, if there is nothing between the braces aside from
1680 @code{catch} and @var{condition}.
1681
1682 @item brace-else-brace
1683 Clean up @samp{@} else @{} constructs by placing the entire construct on
1684 a single line. The clean-up occurs when you type the @samp{@{} after
1685 the @code{else}, but only if there is nothing but white space between
1686 the braces and the @code{else}.
1687
1688 @item brace-elseif-brace
1689 Clean up @samp{@} else if (@dots{}) @{} constructs by placing the entire
1690 construct on a single line. The clean-up occurs when you type the
1691 @samp{@{}, if there is nothing but white space between the @samp{@}} and
1692 @samp{@{} aside from the keywords and the @code{if}-condition.
1693
1694 @item empty-defun-braces
1695 Clean up empty defun braces by placing the braces on the same
1696 line. Clean-up occurs when you type the closing brace.
1697
1698 @item defun-close-semi
1699 Clean up the semicolon after a @code{struct} or similar type
1700 declaration, by placing the semicolon on the same line as the closing
1701 brace. Clean-up occurs when you type the semicolon.
1702
1703 @item list-close-comma
1704 Clean up commas following braces in array and aggregate
1705 initializers. Clean-up occurs when you type the comma.
1706
1707 @item one-line-defun
1708 Remove space and newlines from a defun if this would leave it short
1709 enough to fit on a single line. This is useful for AWK pattern/action
1710 pairs. ``Short enough'' means not longer than the value of the user
1711 option @code{c-max-one-liner-length}. Clean-up occurs when you type
1712 the closing brace.
1713
1714 @item scope-operator
1715 Clean up double colons which may designate a C++ scope operator, by
1716 placing the colons together. Clean-up occurs when you type the second
1717 colon, but only when the two colons are separated by nothing but
1718 whitespace.
1719 @end table
1720
1721 @node Hungry Delete
1722 @subsection Hungry Delete Feature in C
1723 @cindex hungry deletion (C Mode)
1724
1725 If you want to delete an entire block of whitespace at point, you
1726 can use @dfn{hungry deletion}. This deletes all the contiguous
1727 whitespace either before point or after point in a single operation.
1728 @dfn{Whitespace} here includes tabs and newlines, but not comments or
1729 preprocessor commands.
1730
1731 @table @kbd
1732 @item C-c C-@key{BS}
1733 @itemx C-c @key{BS}
1734 @findex c-hungry-backspace
1735 @kindex C-c C-@key{BS} (C Mode)
1736 @kindex C-c @key{BS} (C Mode)
1737 @code{c-hungry-backspace}---Delete the entire block of whitespace
1738 preceding point.
1739
1740 @item C-c C-d
1741 @itemx C-c C-@key{DEL}
1742 @itemx C-c @key{DEL}
1743 @findex c-hungry-delete-forward
1744 @kindex C-c C-d (C Mode)
1745 @kindex C-c C-@key{DEL} (C Mode)
1746 @kindex C-c @key{DEL} (C Mode)
1747 @code{c-hungry-delete-forward}---Delete the entire block of whitespace
1748 following point.
1749 @end table
1750
1751 As an alternative to the above commands, you can enable @dfn{hungry
1752 delete mode}. When this feature is enabled (indicated by @samp{/h} in
1753 the mode line after the mode name), a single @key{BS} command deletes
1754 all preceding whitespace, not just one space, and a single @kbd{C-c
1755 C-d} (but @emph{not} @key{delete}) deletes all following whitespace.
1756
1757 @table @kbd
1758 @item M-x c-toggle-hungry-state
1759 @findex c-toggle-hungry-state
1760 Toggle the hungry-delete feature
1761 (@code{c-toggle-hungry-state})@footnote{This command had the binding
1762 @kbd{C-c C-d} in earlier versions of Emacs. @kbd{C-c C-d} is now
1763 bound to @code{c-hungry-delete-forward}.}. With a prefix argument,
1764 this command turns the hungry-delete feature on if the argument is
1765 positive, and off if it is negative.
1766 @end table
1767
1768 @vindex c-hungry-delete-key
1769 The variable @code{c-hungry-delete-key} controls whether the
1770 hungry-delete feature is enabled.
1771
1772 @node Other C Commands
1773 @subsection Other Commands for C Mode
1774
1775 @table @kbd
1776 @item C-c C-w
1777 @itemx M-x c-subword-mode
1778 @findex c-subword-mode
1779 Enable (or disable) @dfn{subword mode} - Emacs's word commands then
1780 recognize upper case letters in @samp{StudlyCapsIdentifiers} as word
1781 boundaries. This is indicated by the flag @samp{/w} on the mode line
1782 after the mode name (e.g. @samp{C/law}). You can even use @kbd{M-x
1783 c-subword-mode} in non-CC Mode buffers.
1784
1785 @item M-x c-context-line-break
1786 @findex c-context-line-break
1787 This command inserts a line break and indents the new line in a manner
1788 appropriate to the context. In normal code, it does the work of
1789 @kbd{C-j} (@code{newline-and-indent}), in a C preprocessor line it
1790 additionally inserts a @samp{\} at the line break, and within comments
1791 it's like @kbd{M-j} (@code{c-indent-new-comment-line}).
1792
1793 @code{c-context-line-break} isn't bound to a key by default, but it
1794 needs a binding to be useful. The following code will bind it to
1795 @kbd{C-j}. We use @code{c-initialization-hook} here to make sure
1796 the keymap is loaded before we try to change it.
1797
1798 @example
1799 (defun my-bind-clb ()
1800 (define-key c-mode-base-map "\C-j" 'c-context-line-break))
1801 (add-hook 'c-initialization-hook 'my-bind-clb)
1802 @end example
1803
1804 @item C-M-h
1805 Put mark at the end of a function definition, and put point at the
1806 beginning (@code{c-mark-function}).
1807
1808 @item M-q
1809 @kindex M-q @r{(C mode)}
1810 @findex c-fill-paragraph
1811 Fill a paragraph, handling C and C++ comments (@code{c-fill-paragraph}).
1812 If any part of the current line is a comment or within a comment, this
1813 command fills the comment or the paragraph of it that point is in,
1814 preserving the comment indentation and comment delimiters.
1815
1816 @item C-c C-e
1817 @cindex macro expansion in C
1818 @cindex expansion of C macros
1819 @findex c-macro-expand
1820 @kindex C-c C-e @r{(C mode)}
1821 Run the C preprocessor on the text in the region, and show the result,
1822 which includes the expansion of all the macro calls
1823 (@code{c-macro-expand}). The buffer text before the region is also
1824 included in preprocessing, for the sake of macros defined there, but the
1825 output from this part isn't shown.
1826
1827 When you are debugging C code that uses macros, sometimes it is hard to
1828 figure out precisely how the macros expand. With this command, you
1829 don't have to figure it out; you can see the expansions.
1830
1831 @item C-c C-\
1832 @findex c-backslash-region
1833 @kindex C-c C-\ @r{(C mode)}
1834 Insert or align @samp{\} characters at the ends of the lines of the
1835 region (@code{c-backslash-region}). This is useful after writing or
1836 editing a C macro definition.
1837
1838 If a line already ends in @samp{\}, this command adjusts the amount of
1839 whitespace before it. Otherwise, it inserts a new @samp{\}. However,
1840 the last line in the region is treated specially; no @samp{\} is
1841 inserted on that line, and any @samp{\} there is deleted.
1842
1843 @item M-x cpp-highlight-buffer
1844 @cindex preprocessor highlighting
1845 @findex cpp-highlight-buffer
1846 Highlight parts of the text according to its preprocessor conditionals.
1847 This command displays another buffer named @samp{*CPP Edit*}, which
1848 serves as a graphic menu for selecting how to display particular kinds
1849 of conditionals and their contents. After changing various settings,
1850 click on @samp{[A]pply these settings} (or go to that buffer and type
1851 @kbd{a}) to rehighlight the C mode buffer accordingly.
1852
1853 @item C-c C-s
1854 @findex c-show-syntactic-information
1855 @kindex C-c C-s @r{(C mode)}
1856 Display the syntactic information about the current source line
1857 (@code{c-show-syntactic-information}). This information directs how
1858 the line is indented.
1859
1860 @item M-x cwarn-mode
1861 @itemx M-x global-cwarn-mode
1862 @findex cwarn-mode
1863 @findex global-cwarn-mode
1864 @vindex global-cwarn-mode
1865 @cindex CWarn mode
1866 @cindex suspicious constructions in C, C++
1867 CWarn minor mode highlights certain suspicious C and C++ constructions:
1868
1869 @itemize @bullet{}
1870 @item
1871 Assignments inside expressions.
1872 @item
1873 Semicolon following immediately after @samp{if}, @samp{for}, and @samp{while}
1874 (except after a @samp{do @dots{} while} statement);
1875 @item
1876 C++ functions with reference parameters.
1877 @end itemize
1878
1879 @noindent
1880 You can enable the mode for one buffer with the command @kbd{M-x
1881 cwarn-mode}, or for all suitable buffers with the command @kbd{M-x
1882 global-cwarn-mode} or by customizing the variable
1883 @code{global-cwarn-mode}. You must also enable Font Lock mode to make
1884 it work.
1885
1886 @item M-x hide-ifdef-mode
1887 @findex hide-ifdef-mode
1888 @cindex Hide-ifdef mode
1889 Hide-ifdef minor mode hides selected code within @samp{#if} and
1890 @samp{#ifdef} preprocessor blocks. See the documentation string of
1891 @code{hide-ifdef-mode} for more information.
1892
1893 @item M-x ff-find-related-file
1894 @cindex related files
1895 @findex ff-find-related-file
1896 @vindex ff-related-file-alist
1897 Find a file ``related'' in a special way to the file visited by the
1898 current buffer. Typically this will be the header file corresponding
1899 to a C/C++ source file, or vice versa. The variable
1900 @code{ff-related-file-alist} specifies how to compute related file
1901 names.
1902 @end table
1903
1904 @node Fortran
1905 @section Fortran Mode
1906 @cindex Fortran mode
1907 @cindex mode, Fortran
1908
1909 Fortran mode provides special motion commands for Fortran statements
1910 and subprograms, and indentation commands that understand Fortran
1911 conventions of nesting, line numbers and continuation statements.
1912 Fortran mode has support for Auto Fill mode that breaks long lines into
1913 proper Fortran continuation lines.
1914
1915 Special commands for comments are provided because Fortran comments
1916 are unlike those of other languages. Built-in abbrevs optionally save
1917 typing when you insert Fortran keywords.
1918
1919 Use @kbd{M-x fortran-mode} to switch to this major mode. This command
1920 runs the hook @code{fortran-mode-hook} (@pxref{Hooks}).
1921
1922 @cindex Fortran77 and Fortran90
1923 @findex f90-mode
1924 @findex fortran-mode
1925 Fortran mode is meant for editing Fortran77 ``fixed format'' (and also
1926 ``tab format'') source code. For editing the modern Fortran90 or
1927 Fortran95 ``free format'' source code, use F90 mode (@code{f90-mode}).
1928 Emacs normally uses Fortran mode for files with extension @samp{.f},
1929 @samp{.F} or @samp{.for}, and F90 mode for the extension @samp{.f90} and
1930 @samp{.f95}. GNU Fortran supports both kinds of format.
1931
1932 @menu
1933 * Motion: Fortran Motion. Moving point by statements or subprograms.
1934 * Indent: Fortran Indent. Indentation commands for Fortran.
1935 * Comments: Fortran Comments. Inserting and aligning comments.
1936 * Autofill: Fortran Autofill. Auto fill support for Fortran.
1937 * Columns: Fortran Columns. Measuring columns for valid Fortran.
1938 * Abbrev: Fortran Abbrev. Built-in abbrevs for Fortran keywords.
1939 @end menu
1940
1941 @node Fortran Motion
1942 @subsection Motion Commands
1943
1944 In addition to the normal commands for moving by and operating on
1945 ``defuns'' (Fortran subprograms---functions and subroutines, as well as
1946 modules for F90 mode), Fortran mode provides special commands to move by
1947 statements and other program units.
1948
1949 @table @kbd
1950 @kindex C-c C-n @r{(Fortran mode)}
1951 @findex fortran-next-statement
1952 @findex f90-next-statement
1953 @item C-c C-n
1954 Move to the beginning of the next statement
1955 (@code{fortran-next-statement}/@code{f90-next-statement}).
1956
1957 @kindex C-c C-p @r{(Fortran mode)}
1958 @findex fortran-previous-statement
1959 @findex f90-previous-statement
1960 @item C-c C-p
1961 Move to the beginning of the previous statement
1962 (@code{fortran-previous-statement}/@code{f90-previous-statement}).
1963 If there is no previous statement (i.e. if called from the first
1964 statement in the buffer), move to the start of the buffer.
1965
1966 @kindex C-c C-e @r{(F90 mode)}
1967 @findex f90-next-block
1968 @item C-c C-e
1969 Move point forward to the start of the next code block
1970 (@code{f90-next-block}). A code block is a subroutine,
1971 @code{if}--@code{endif} statement, and so forth. This command exists
1972 for F90 mode only, not Fortran mode. With a numeric argument, this
1973 moves forward that many blocks.
1974
1975 @kindex C-c C-a @r{(F90 mode)}
1976 @findex f90-previous-block
1977 @item C-c C-a
1978 Move point backward to the previous code block
1979 (@code{f90-previous-block}). This is like @code{f90-next-block}, but
1980 moves backwards.
1981
1982 @kindex C-M-n @r{(Fortran mode)}
1983 @findex fortran-end-of-block
1984 @findex f90-end-of-block
1985 @item C-M-n
1986 Move to the end of the current code block
1987 (@code{fortran-end-of-block}/@code{f90-end-of-block}). With a numeric
1988 agument, move forward that number of blocks. The mark is set before
1989 moving point. The F90 mode version of this command checks for
1990 consistency of block types and labels (if present), but it does not
1991 check the outermost block since that may be incomplete.
1992
1993 @kindex C-M-p @r{(Fortran mode)}
1994 @findex fortran-beginning-of-block
1995 @findex f90-beginning-of-block
1996 @item C-M-p
1997 Move to the start of the current code block
1998 (@code{fortran-beginning-of-block}/@code{f90-beginning-of-block}). This
1999 is like @code{fortran-end-of-block}, but moves backwards.
2000 @end table
2001
2002 @node Fortran Indent
2003 @subsection Fortran Indentation
2004
2005 Special commands and features are needed for indenting Fortran code in
2006 order to make sure various syntactic entities (line numbers, comment line
2007 indicators and continuation line flags) appear in the columns that are
2008 required for standard, fixed (or tab) format Fortran.
2009
2010 @menu
2011 * Commands: ForIndent Commands. Commands for indenting and filling Fortran.
2012 * Contline: ForIndent Cont. How continuation lines indent.
2013 * Numbers: ForIndent Num. How line numbers auto-indent.
2014 * Conv: ForIndent Conv. Conventions you must obey to avoid trouble.
2015 * Vars: ForIndent Vars. Variables controlling Fortran indent style.
2016 @end menu
2017
2018 @node ForIndent Commands
2019 @subsubsection Fortran Indentation and Filling Commands
2020
2021 @table @kbd
2022 @item C-M-j
2023 Break the current line at point and set up a continuation line
2024 (@code{fortran-split-line}).
2025 @item M-^
2026 Join this line to the previous line (@code{fortran-join-line}).
2027 @item C-M-q
2028 Indent all the lines of the subprogram point is in
2029 (@code{fortran-indent-subprogram}).
2030 @item M-q
2031 Fill a comment block or statement.
2032 @end table
2033
2034 @kindex C-M-q @r{(Fortran mode)}
2035 @findex fortran-indent-subprogram
2036 The key @kbd{C-M-q} runs @code{fortran-indent-subprogram}, a command
2037 to reindent all the lines of the Fortran subprogram (function or
2038 subroutine) containing point.
2039
2040 @kindex C-M-j @r{(Fortran mode)}
2041 @findex fortran-split-line
2042 The key @kbd{C-M-j} runs @code{fortran-split-line}, which splits
2043 a line in the appropriate fashion for Fortran. In a non-comment line,
2044 the second half becomes a continuation line and is indented
2045 accordingly. In a comment line, both halves become separate comment
2046 lines.
2047
2048 @kindex M-^ @r{(Fortran mode)}
2049 @kindex C-c C-d @r{(Fortran mode)}
2050 @findex fortran-join-line
2051 @kbd{M-^} or @kbd{C-c C-d} runs the command @code{fortran-join-line},
2052 which joins a continuation line back to the previous line, roughly as
2053 the inverse of @code{fortran-split-line}. The point must be on a
2054 continuation line when this command is invoked.
2055
2056 @kindex M-q @r{(Fortran mode)}
2057 @kbd{M-q} in Fortran mode fills the comment block or statement that
2058 point is in. This removes any excess statement continuations.
2059
2060 @node ForIndent Cont
2061 @subsubsection Continuation Lines
2062 @cindex Fortran continuation lines
2063
2064 @vindex fortran-continuation-string
2065 Most Fortran77 compilers allow two ways of writing continuation lines.
2066 If the first non-space character on a line is in column 5, then that
2067 line is a continuation of the previous line. We call this @dfn{fixed
2068 format}. (In GNU Emacs we always count columns from 0; but note that
2069 the Fortran standard counts from 1.) The variable
2070 @code{fortran-continuation-string} specifies what character to put in
2071 column 5. A line that starts with a tab character followed by any digit
2072 except @samp{0} is also a continuation line. We call this style of
2073 continuation @dfn{tab format}. (Fortran90 introduced ``free format'',
2074 with another style of continuation lines).
2075
2076 @vindex indent-tabs-mode @r{(Fortran mode)}
2077 @vindex fortran-analyze-depth
2078 @vindex fortran-tab-mode-default
2079 Fortran mode can use either style of continuation line. When you
2080 enter Fortran mode, it tries to deduce the proper continuation style
2081 automatically from the buffer contents. It does this by scanning up to
2082 @code{fortran-analyze-depth} (default 100) lines from the start of the
2083 buffer. The first line that begins with either a tab character or six
2084 spaces determines the choice. If the scan fails (for example, if the
2085 buffer is new and therefore empty), the value of
2086 @code{fortran-tab-mode-default} (@code{nil} for fixed format, and
2087 non-@code{nil} for tab format) is used. @samp{/t} in the mode line
2088 indicates tab format is selected. Fortran mode sets the value of
2089 @code{indent-tabs-mode} accordingly (@pxref{Just Spaces}).
2090
2091 If the text on a line starts with the Fortran continuation marker
2092 @samp{$}, or if it begins with any non-whitespace character in column
2093 5, Fortran mode treats it as a continuation line. When you indent a
2094 continuation line with @key{TAB}, it converts the line to the current
2095 continuation style. When you split a Fortran statement with
2096 @kbd{C-M-j}, the continuation marker on the newline is created according
2097 to the continuation style.
2098
2099 The setting of continuation style affects several other aspects of
2100 editing in Fortran mode. In fixed format mode, the minimum column
2101 number for the body of a statement is 6. Lines inside of Fortran
2102 blocks that are indented to larger column numbers always use only the
2103 space character for whitespace. In tab format mode, the minimum
2104 column number for the statement body is 8, and the whitespace before
2105 column 8 must always consist of one tab character.
2106
2107 @node ForIndent Num
2108 @subsubsection Line Numbers
2109
2110 If a number is the first non-whitespace in the line, Fortran
2111 indentation assumes it is a line number and moves it to columns 0
2112 through 4. (Columns always count from 0 in GNU Emacs.)
2113
2114 @vindex fortran-line-number-indent
2115 Line numbers of four digits or less are normally indented one space.
2116 The variable @code{fortran-line-number-indent} controls this; it
2117 specifies the maximum indentation a line number can have. The default
2118 value of the variable is 1. Fortran mode tries to prevent line number
2119 digits passing column 4, reducing the indentation below the specified
2120 maximum if necessary. If @code{fortran-line-number-indent} has the
2121 value 5, line numbers are right-justified to end in column 4.
2122
2123 @vindex fortran-electric-line-number
2124 Simply inserting a line number is enough to indent it according to
2125 these rules. As each digit is inserted, the indentation is recomputed.
2126 To turn off this feature, set the variable
2127 @code{fortran-electric-line-number} to @code{nil}.
2128
2129
2130 @node ForIndent Conv
2131 @subsubsection Syntactic Conventions
2132
2133 Fortran mode assumes that you follow certain conventions that simplify
2134 the task of understanding a Fortran program well enough to indent it
2135 properly:
2136
2137 @itemize @bullet
2138 @item
2139 Two nested @samp{do} loops never share a @samp{continue} statement.
2140
2141 @item
2142 Fortran keywords such as @samp{if}, @samp{else}, @samp{then}, @samp{do}
2143 and others are written without embedded whitespace or line breaks.
2144
2145 Fortran compilers generally ignore whitespace outside of string
2146 constants, but Fortran mode does not recognize these keywords if they
2147 are not contiguous. Constructs such as @samp{else if} or @samp{end do}
2148 are acceptable, but the second word should be on the same line as the
2149 first and not on a continuation line.
2150 @end itemize
2151
2152 @noindent
2153 If you fail to follow these conventions, the indentation commands may
2154 indent some lines unaesthetically. However, a correct Fortran program
2155 retains its meaning when reindented even if the conventions are not
2156 followed.
2157
2158 @node ForIndent Vars
2159 @subsubsection Variables for Fortran Indentation
2160
2161 @vindex fortran-do-indent
2162 @vindex fortran-if-indent
2163 @vindex fortran-structure-indent
2164 @vindex fortran-continuation-indent
2165 @vindex fortran-check-all-num@dots{}
2166 @vindex fortran-minimum-statement-indent@dots{}
2167 Several additional variables control how Fortran indentation works:
2168
2169 @table @code
2170 @item fortran-do-indent
2171 Extra indentation within each level of @samp{do} statement (default 3).
2172
2173 @item fortran-if-indent
2174 Extra indentation within each level of @samp{if}, @samp{select case}, or
2175 @samp{where} statements (default 3).
2176
2177 @item fortran-structure-indent
2178 Extra indentation within each level of @samp{structure}, @samp{union},
2179 @samp{map}, or @samp{interface} statements (default 3).
2180
2181 @item fortran-continuation-indent
2182 Extra indentation for bodies of continuation lines (default 5).
2183
2184 @item fortran-check-all-num-for-matching-do
2185 In Fortran77, a numbered @samp{do} statement is ended by any statement
2186 with a matching line number. It is common (but not compulsory) to use a
2187 @samp{continue} statement for this purpose. If this variable has a
2188 non-@code{nil} value, indenting any numbered statement must check for a
2189 @samp{do} that ends there. If you always end @samp{do} statements with
2190 a @samp{continue} line (or if you use the more modern @samp{enddo}),
2191 then you can speed up indentation by setting this variable to
2192 @code{nil}. The default is @code{nil}.
2193
2194 @item fortran-blink-matching-if
2195 If this is @code{t}, indenting an @samp{endif} (or @samp{enddo}
2196 statement moves the cursor momentarily to the matching @samp{if} (or
2197 @samp{do}) statement to show where it is. The default is @code{nil}.
2198
2199 @item fortran-minimum-statement-indent-fixed
2200 Minimum indentation for Fortran statements when using fixed format
2201 continuation line style. Statement bodies are never indented less than
2202 this much. The default is 6.
2203
2204 @item fortran-minimum-statement-indent-tab
2205 Minimum indentation for Fortran statements for tab format continuation line
2206 style. Statement bodies are never indented less than this much. The
2207 default is 8.
2208 @end table
2209
2210 The variables controlling the indentation of comments are described in
2211 the following section.
2212
2213 @node Fortran Comments
2214 @subsection Fortran Comments
2215
2216 The usual Emacs comment commands assume that a comment can follow a
2217 line of code. In Fortran77, the standard comment syntax requires an
2218 entire line to be just a comment. Therefore, Fortran mode replaces the
2219 standard Emacs comment commands and defines some new variables.
2220
2221 @vindex fortran-comment-line-start
2222 Fortran mode can also handle the Fortran90 comment syntax where comments
2223 start with @samp{!} and can follow other text. Because only some Fortran77
2224 compilers accept this syntax, Fortran mode will not insert such comments
2225 unless you have said in advance to do so. To do this, set the variable
2226 @code{fortran-comment-line-start} to @samp{"!"}.
2227
2228 @table @kbd
2229 @item M-;
2230 Align comment or insert new comment (@code{fortran-indent-comment}).
2231
2232 @item C-x ;
2233 Applies to nonstandard @samp{!} comments only.
2234
2235 @item C-c ;
2236 Turn all lines of the region into comments, or (with argument) turn them back
2237 into real code (@code{fortran-comment-region}).
2238 @end table
2239
2240 @findex fortran-indent-comment
2241 @kbd{M-;} in Fortran mode is redefined as the command
2242 @code{fortran-indent-comment}. Like the usual @kbd{M-;} command, this
2243 recognizes any kind of existing comment and aligns its text appropriately;
2244 if there is no existing comment, a comment is inserted and aligned. But
2245 inserting and aligning comments are not the same in Fortran mode as in
2246 other modes.
2247
2248 When a new comment must be inserted, if the current line is blank, a
2249 full-line comment is inserted. On a non-blank line, a nonstandard @samp{!}
2250 comment is inserted if you have said you want to use them. Otherwise a
2251 full-line comment is inserted on a new line before the current line.
2252
2253 Nonstandard @samp{!} comments are aligned like comments in other
2254 languages, but full-line comments are different. In a standard full-line
2255 comment, the comment delimiter itself must always appear in column zero.
2256 What can be aligned is the text within the comment. You can choose from
2257 three styles of alignment by setting the variable
2258 @code{fortran-comment-indent-style} to one of these values:
2259
2260 @vindex fortran-comment-indent-style
2261 @vindex fortran-comment-line-extra-indent
2262 @table @code
2263 @item fixed
2264 Align the text at a fixed column, which is the sum of
2265 @code{fortran-comment-line-extra-indent} and the minimum statement
2266 indentation. This is the default.
2267
2268 The minimum statement indentation is
2269 @code{fortran-minimum-statement-indent-fixed} for fixed format
2270 continuation line style and @code{fortran-minimum-statement-indent-tab}
2271 for tab format style.
2272
2273 @item relative
2274 Align the text as if it were a line of code, but with an additional
2275 @code{fortran-comment-line-extra-indent} columns of indentation.
2276
2277 @item nil
2278 Don't move text in full-line comments automatically.
2279 @end table
2280
2281 @vindex fortran-comment-indent-char
2282 In addition, you can specify the character to be used to indent within
2283 full-line comments by setting the variable
2284 @code{fortran-comment-indent-char} to the single-character string you want
2285 to use.
2286
2287 @vindex fortran-directive-re
2288 Compiler directive lines, or preprocessor lines, have much the same
2289 appearance as comment lines. It is important, though, that such lines
2290 never be indented at all, no matter what the value of
2291 @code{fortran-comment-indent-style}. The variable
2292 @code{fortran-directive-re} is a regular expression that specifies which
2293 lines are directives. Matching lines are never indented, and receive
2294 distinctive font-locking.
2295
2296 The normal Emacs comment command @kbd{C-x ;} has not been redefined. If
2297 you use @samp{!} comments, this command can be used with them. Otherwise
2298 it is useless in Fortran mode.
2299
2300 @kindex C-c ; @r{(Fortran mode)}
2301 @findex fortran-comment-region
2302 @vindex fortran-comment-region
2303 The command @kbd{C-c ;} (@code{fortran-comment-region}) turns all the
2304 lines of the region into comments by inserting the string @samp{C$$$} at
2305 the front of each one. With a numeric argument, it turns the region
2306 back into live code by deleting @samp{C$$$} from the front of each line
2307 in it. The string used for these comments can be controlled by setting
2308 the variable @code{fortran-comment-region}. Note that here we have an
2309 example of a command and a variable with the same name; these two uses
2310 of the name never conflict because in Lisp and in Emacs it is always
2311 clear from the context which one is meant.
2312
2313 @node Fortran Autofill
2314 @subsection Auto Fill in Fortran Mode
2315
2316 Fortran mode has specialized support for Auto Fill mode, which is a
2317 minor mode that automatically splits statements as you insert them when
2318 they become too wide. Splitting a statement involves making
2319 continuation lines using @code{fortran-continuation-string}
2320 (@pxref{ForIndent Cont}). This splitting happens when you type
2321 @key{SPC}, @key{RET}, or @key{TAB}, and also in the Fortran indentation
2322 commands. You activate Auto Fill in Fortran mode in the normal way
2323 (@pxref{Auto Fill}).
2324
2325 @vindex fortran-break-before-delimiters
2326 Auto Fill breaks lines at spaces or delimiters when the lines get
2327 longer than the desired width (the value of @code{fill-column}). The
2328 delimiters (besides whitespace) that Auto Fill can break at are
2329 @samp{+}, @samp{-}, @samp{/}, @samp{*}, @samp{=}, @samp{<}, @samp{>},
2330 and @samp{,}. The line break comes after the delimiter if the
2331 variable @code{fortran-break-before-delimiters} is @code{nil}.
2332 Otherwise (and by default), the break comes before the delimiter.
2333
2334 To enable Auto Fill in all Fortran buffers, add
2335 @code{turn-on-auto-fill} to @code{fortran-mode-hook}. @xref{Hooks}.
2336
2337 @node Fortran Columns
2338 @subsection Checking Columns in Fortran
2339
2340 @table @kbd
2341 @item C-c C-r
2342 Display a ``column ruler'' momentarily above the current line
2343 (@code{fortran-column-ruler}).
2344 @item C-c C-w
2345 Split the current window horizontally temporarily so that it is 72
2346 columns wide (@code{fortran-window-create-momentarily}). This may
2347 help you avoid making lines longer than the 72-character limit that
2348 some Fortran compilers impose.
2349 @item C-u C-c C-w
2350 Split the current window horizontally so that it is 72 columns wide
2351 (@code{fortran-window-create}). You can then continue editing.
2352 @item M-x fortran-strip-sequence-nos
2353 Delete all text in column 72 and beyond.
2354 @end table
2355
2356 @kindex C-c C-r @r{(Fortran mode)}
2357 @findex fortran-column-ruler
2358 The command @kbd{C-c C-r} (@code{fortran-column-ruler}) shows a column
2359 ruler momentarily above the current line. The comment ruler is two lines
2360 of text that show you the locations of columns with special significance in
2361 Fortran programs. Square brackets show the limits of the columns for line
2362 numbers, and curly brackets show the limits of the columns for the
2363 statement body. Column numbers appear above them.
2364
2365 Note that the column numbers count from zero, as always in GNU Emacs.
2366 As a result, the numbers may be one less than those you are familiar
2367 with; but the positions they indicate in the line are standard for
2368 Fortran.
2369
2370 @vindex fortran-column-ruler-fixed
2371 @vindex fortran-column-ruler-tabs
2372 The text used to display the column ruler depends on the value of the
2373 variable @code{indent-tabs-mode}. If @code{indent-tabs-mode} is
2374 @code{nil}, then the value of the variable
2375 @code{fortran-column-ruler-fixed} is used as the column ruler.
2376 Otherwise, the value of the variable @code{fortran-column-ruler-tab} is
2377 displayed. By changing these variables, you can change the column ruler
2378 display.
2379
2380 @kindex C-c C-w @r{(Fortran mode)}
2381 @findex fortran-window-create-momentarily
2382 @kbd{C-c C-w} (@code{fortran-window-create-momentarily}) temporarily
2383 splits the current window horizontally, making a window 72 columns
2384 wide, so you can see any lines that are too long. Type a space to
2385 restore the normal width.
2386
2387 @kindex C-u C-c C-w @r{(Fortran mode)}
2388 @findex fortran-window-create
2389 You can also split the window horizontally and continue editing with
2390 the split in place. To do this, use @kbd{C-u C-c C-w} (@code{M-x
2391 fortran-window-create}). By editing in this window you can
2392 immediately see when you make a line too wide to be correct Fortran.
2393
2394 @findex fortran-strip-sequence-nos
2395 The command @kbd{M-x fortran-strip-sequence-nos} deletes all text in
2396 column 72 and beyond, on all lines in the current buffer. This is the
2397 easiest way to get rid of old sequence numbers.
2398
2399 @node Fortran Abbrev
2400 @subsection Fortran Keyword Abbrevs
2401
2402 Fortran mode provides many built-in abbrevs for common keywords and
2403 declarations. These are the same sort of abbrev that you can define
2404 yourself. To use them, you must turn on Abbrev mode. @xref{Abbrevs}.
2405
2406 The built-in abbrevs are unusual in one way: they all start with a
2407 semicolon. You cannot normally use semicolon in an abbrev, but Fortran
2408 mode makes this possible by changing the syntax of semicolon to ``word
2409 constituent.''
2410
2411 For example, one built-in Fortran abbrev is @samp{;c} for
2412 @samp{continue}. If you insert @samp{;c} and then insert a punctuation
2413 character such as a space or a newline, the @samp{;c} expands automatically
2414 to @samp{continue}, provided Abbrev mode is enabled.@refill
2415
2416 Type @samp{;?} or @samp{;C-h} to display a list of all the built-in
2417 Fortran abbrevs and what they stand for.
2418
2419 @node Asm Mode
2420 @section Asm Mode
2421
2422 @cindex Asm mode
2423 @cindex assembler mode
2424 Asm mode is a major mode for editing files of assembler code. It
2425 defines these commands:
2426
2427 @table @kbd
2428 @item @key{TAB}
2429 @code{tab-to-tab-stop}.
2430 @item C-j
2431 Insert a newline and then indent using @code{tab-to-tab-stop}.
2432 @item :
2433 Insert a colon and then remove the indentation from before the label
2434 preceding colon. Then do @code{tab-to-tab-stop}.
2435 @item ;
2436 Insert or align a comment.
2437 @end table
2438
2439 The variable @code{asm-comment-char} specifies which character
2440 starts comments in assembler syntax.
2441
2442 @ignore
2443 arch-tag: c7ee7409-40a4-45c7-bfb7-ae7f2c74d0c0
2444 @end ignore