]> code.delx.au - gnu-emacs/blob - doc/emacs/programs.texi
Document 'comment-line'
[gnu-emacs] / doc / emacs / programs.texi
1 @c -*- coding: utf-8 -*-
2 @c This is part of the Emacs manual.
3 @c Copyright (C) 1985-1987, 1993-1995, 1997, 1999-2015 Free Software
4 @c Foundation, Inc.
5 @c See file emacs.texi for copying conditions.
6 @node Programs
7 @chapter Editing Programs
8 @cindex Lisp editing
9 @cindex C editing
10 @cindex program editing
11
12 This chapter describes Emacs features for facilitating editing
13 programs. Some of the things these features can do are:
14
15 @itemize @bullet
16 @item
17 Find or move over top-level definitions (@pxref{Defuns}).
18 @item
19 Apply the usual indentation conventions of the language
20 (@pxref{Program Indent}).
21 @item
22 Balance parentheses (@pxref{Parentheses}).
23 @item
24 Insert, kill or align comments (@pxref{Comments}).
25 @item
26 Highlight program syntax (@pxref{Font Lock}).
27 @end itemize
28
29 @menu
30 * Program Modes:: Major modes for editing programs.
31 * Defuns:: Commands to operate on major top-level parts
32 of a program.
33 * Program Indent:: Adjusting indentation to show the nesting.
34 * Parentheses:: Commands that operate on parentheses.
35 * Comments:: Inserting, killing, and aligning comments.
36 * Documentation:: Getting documentation of functions you plan to call.
37 * Hideshow:: Displaying blocks selectively.
38 * Symbol Completion:: Completion on symbol names of your program or language.
39 * MixedCase Words:: Dealing with identifiersLikeThis.
40 * Semantic:: Suite of editing tools based on source code parsing.
41 * Misc for Programs:: Other Emacs features useful for editing programs.
42 * C Modes:: Special commands of C, C++, Objective-C, Java,
43 IDL, Pike and AWK modes.
44 * Asm Mode:: Asm mode and its special features.
45 @ifnottex
46 * Fortran:: Fortran mode and its special features.
47 @end ifnottex
48 @end menu
49
50 @node Program Modes
51 @section Major Modes for Programming Languages
52 @cindex modes for programming languages
53
54 Emacs has specialized major modes (@pxref{Major Modes}) for many
55 programming languages. A programming language mode typically
56 specifies the syntax of expressions, the customary rules for
57 indentation, how to do syntax highlighting for the language, and how
58 to find the beginning or end of a function definition. It often has
59 features for compiling and debugging programs as well. The major mode
60 for each language is named after the language; for instance, the major
61 mode for the C programming language is @code{c-mode}.
62
63 @cindex Perl mode
64 @cindex Icon mode
65 @cindex Makefile mode
66 @cindex Tcl mode
67 @cindex CPerl mode
68 @cindex DSSSL mode
69 @cindex Octave mode
70 @cindex Metafont mode
71 @cindex Modula2 mode
72 @cindex Prolog mode
73 @cindex Python mode
74 @cindex Ruby mode
75 @cindex Simula mode
76 @cindex VHDL mode
77 @cindex M4 mode
78 @cindex Shell-script mode
79 @cindex OPascal mode
80 @cindex PostScript mode
81 @cindex Conf mode
82 @cindex DNS mode
83 @cindex Javascript mode
84 Emacs has programming language modes for Lisp, Scheme, the
85 Scheme-based DSSSL expression language, Ada, ASM, AWK, C, C++,
86 Fortran, Icon, IDL (CORBA), IDLWAVE, Java, Javascript, Metafont
87 (@TeX{}'s companion for font creation), Modula2, Object Pascal, Objective-C,
88 Octave, Pascal, Perl, Pike, PostScript, Prolog, Python, Ruby, Simula, Tcl,
89 and VHDL@. An alternative mode for Perl is called CPerl mode. Modes are
90 also available for the scripting languages of the common GNU and Unix
91 shells, and MS-DOS/MS-Windows @samp{BAT} files, and for makefiles,
92 DNS master files, and various sorts of configuration files.
93
94 Ideally, Emacs should have a major mode for each programming
95 language that you might want to edit. If it doesn't have a mode for
96 your favorite language, the mode might be implemented in a package not
97 distributed with Emacs (@pxref{Packages}); or you can contribute one.
98
99 @kindex DEL @r{(programming modes)}
100 @findex backward-delete-char-untabify
101 In most programming languages, indentation should vary from line to
102 line to illustrate the structure of the program. Therefore, in most
103 programming language modes, typing @key{TAB} updates the indentation
104 of the current line (@pxref{Program Indent}). Furthermore, @key{DEL}
105 is usually bound to @code{backward-delete-char-untabify}, which
106 deletes backward treating each tab as if it were the equivalent number
107 of spaces, so that you can delete one column of indentation without
108 worrying whether the whitespace consists of spaces or tabs.
109
110 @cindex mode hook
111 @vindex c-mode-hook
112 @vindex lisp-mode-hook
113 @vindex emacs-lisp-mode-hook
114 @vindex lisp-interaction-mode-hook
115 @vindex scheme-mode-hook
116 Entering a programming language mode runs the custom Lisp functions
117 specified in the hook variable @code{prog-mode-hook}, followed by
118 those specified in the mode's own mode hook (@pxref{Major Modes}).
119 For instance, entering C mode runs the hooks @code{prog-mode-hook} and
120 @code{c-mode-hook}. @xref{Hooks}, for information about hooks.
121
122 @ifnottex
123 Separate manuals are available for the modes for Ada (@pxref{Top,,
124 Ada Mode, ada-mode, Ada Mode}), C/C++/Objective C/Java/Corba
125 IDL/Pike/AWK (@pxref{Top, , CC Mode, ccmode, CC Mode}), and IDLWAVE
126 (@pxref{Top,, IDLWAVE, idlwave, IDLWAVE User Manual}).
127 @end ifnottex
128 @iftex
129 The Emacs distribution contains Info manuals for the major modes for
130 Ada, C/C++/Objective C/Java/Corba IDL/Pike/AWK, and IDLWAVE@. For
131 Fortran mode, @pxref{Fortran,,, emacs-xtra, Specialized Emacs Features}.
132 @end iftex
133
134 @node Defuns
135 @section Top-Level Definitions, or Defuns
136
137 In Emacs, a major definition at the top level in the buffer, such as
138 a function, is called a @dfn{defun}. The name comes from Lisp, but in
139 Emacs we use it for all languages.
140
141 @menu
142 * Left Margin Paren:: An open-paren or similar opening delimiter
143 starts a defun if it is at the left margin.
144 * Moving by Defuns:: Commands to move over or mark a major definition.
145 * Imenu:: Making buffer indexes as menus.
146 * Which Function:: Which Function mode shows which function you are in.
147 @end menu
148
149 @node Left Margin Paren
150 @subsection Left Margin Convention
151
152 @cindex open-parenthesis in leftmost column
153 @cindex ( in leftmost column
154 Many programming-language modes assume by default that any opening
155 delimiter found at the left margin is the start of a top-level
156 definition, or defun. Therefore, @strong{don't put an opening
157 delimiter at the left margin unless it should have that significance}.
158 For instance, never put an open-parenthesis at the left margin in a
159 Lisp file unless it is the start of a top-level list.
160
161 The convention speeds up many Emacs operations, which would
162 otherwise have to scan back to the beginning of the buffer to analyze
163 the syntax of the code.
164
165 If you don't follow this convention, not only will you have trouble
166 when you explicitly use the commands for motion by defuns; other
167 features that use them will also give you trouble. This includes the
168 indentation commands (@pxref{Program Indent}) and Font Lock mode
169 (@pxref{Font Lock}).
170
171 The most likely problem case is when you want an opening delimiter
172 at the start of a line inside a string. To avoid trouble, put an
173 escape character (@samp{\}, in C and Emacs Lisp, @samp{/} in some
174 other Lisp dialects) before the opening delimiter. This will not
175 affect the contents of the string, but will prevent that opening
176 delimiter from starting a defun. Here's an example:
177
178 @example
179 (insert "Foo:
180 \(bar)
181 ")
182 @end example
183
184 To help you catch violations of this convention, Font Lock mode
185 highlights confusing opening delimiters (those that ought to be
186 quoted) in bold red.
187
188 @vindex open-paren-in-column-0-is-defun-start
189 If you need to override this convention, you can do so by setting
190 the variable @code{open-paren-in-column-0-is-defun-start}.
191 If this user option is set to @code{t} (the default), opening
192 parentheses or braces at column zero always start defuns. When it is
193 @code{nil}, defuns are found by searching for parens or braces at the
194 outermost level.
195
196 Usually, you should leave this option at its default value of
197 @code{t}. If your buffer contains parentheses or braces in column
198 zero which don't start defuns, and it is somehow impractical to remove
199 these parentheses or braces, it might be helpful to set the option to
200 @code{nil}. Be aware that this might make scrolling and display in
201 large buffers quite sluggish. Furthermore, the parentheses and braces
202 must be correctly matched throughout the buffer for it to work
203 properly.
204
205 @node Moving by Defuns
206 @subsection Moving by Defuns
207 @cindex defuns
208
209 These commands move point or set up the region based on top-level
210 major definitions, also called @dfn{defuns}.
211
212 @table @kbd
213 @item C-M-a
214 Move to beginning of current or preceding defun
215 (@code{beginning-of-defun}).
216 @item C-M-e
217 Move to end of current or following defun (@code{end-of-defun}).
218 @item C-M-h
219 Put region around whole current or following defun (@code{mark-defun}).
220 @end table
221
222 @cindex move to beginning or end of function
223 @cindex function, move to beginning or end
224 @kindex C-M-a
225 @kindex C-M-e
226 @kindex C-M-h
227 @findex beginning-of-defun
228 @findex end-of-defun
229 @findex mark-defun
230 The commands to move to the beginning and end of the current defun
231 are @kbd{C-M-a} (@code{beginning-of-defun}) and @kbd{C-M-e}
232 (@code{end-of-defun}). If you repeat one of these commands, or use a
233 positive numeric argument, each repetition moves to the next defun in
234 the direction of motion.
235
236 @kbd{C-M-a} with a negative argument @minus{}@var{n} moves forward
237 @var{n} times to the next beginning of a defun. This is not exactly
238 the same place that @kbd{C-M-e} with argument @var{n} would move to;
239 the end of this defun is not usually exactly the same place as the
240 beginning of the following defun. (Whitespace, comments, and perhaps
241 declarations can separate them.) Likewise, @kbd{C-M-e} with a
242 negative argument moves back to an end of a defun, which is not quite
243 the same as @kbd{C-M-a} with a positive argument.
244
245 @kindex C-M-h @r{(C mode)}
246 @findex c-mark-function
247 To operate on the current defun, use @kbd{C-M-h}
248 (@code{mark-defun}), which sets the mark at the end of the current
249 defun and puts point at its beginning. @xref{Marking Objects}. This
250 is the easiest way to get ready to kill the defun in order to move it
251 to a different place in the file. If you use the command while point
252 is between defuns, it uses the following defun. If you use the
253 command while the mark is already active, it sets the mark but does
254 not move point; furthermore, each successive use of @kbd{C-M-h}
255 extends the end of the region to include one more defun.
256
257 In C mode, @kbd{C-M-h} runs the function @code{c-mark-function},
258 which is almost the same as @code{mark-defun}; the difference is that
259 it backs up over the argument declarations, function name and returned
260 data type so that the entire C function is inside the region. This is
261 an example of how major modes adjust the standard key bindings so that
262 they do their standard jobs in a way better fitting a particular
263 language. Other major modes may replace any or all of these key
264 bindings for that purpose.
265
266 @node Imenu
267 @subsection Imenu
268 @cindex index of buffer definitions
269 @cindex buffer definitions index
270
271 The Imenu facility offers a way to find the major definitions in
272 a file by name. It is also useful in text formatter major modes,
273 where it treats each chapter, section, etc., as a definition.
274 (@xref{Tags}, for a more powerful feature that handles multiple files
275 together.)
276
277 @findex imenu
278 If you type @kbd{M-x imenu}, it reads the name of a definition using
279 the minibuffer, then moves point to that definition. You can use
280 completion to specify the name; the command always displays the whole
281 list of valid names.
282
283 @findex imenu-add-menubar-index
284 Alternatively, you can bind the command @code{imenu} to a mouse
285 click. Then it displays mouse menus for you to select a definition
286 name. You can also add the buffer's index to the menu bar by calling
287 @code{imenu-add-menubar-index}. If you want to have this menu bar
288 item available for all buffers in a certain major mode, you can do
289 this by adding @code{imenu-add-menubar-index} to its mode hook. But
290 if you have done that, you will have to wait a little while each time
291 you visit a file in that mode, while Emacs finds all the definitions
292 in that buffer.
293
294 @vindex imenu-auto-rescan
295 When you change the contents of a buffer, if you add or delete
296 definitions, you can update the buffer's index based on the
297 new contents by invoking the @samp{*Rescan*} item in the menu.
298 Rescanning happens automatically if you set @code{imenu-auto-rescan} to
299 a non-@code{nil} value. There is no need to rescan because of small
300 changes in the text.
301
302 @vindex imenu-sort-function
303 You can customize the way the menus are sorted by setting the
304 variable @code{imenu-sort-function}. By default, names are ordered as
305 they occur in the buffer; if you want alphabetic sorting, use the
306 symbol @code{imenu--sort-by-name} as the value. You can also
307 define your own comparison function by writing Lisp code.
308
309 Imenu provides the information to guide Which Function mode
310 @ifnottex
311 (@pxref{Which Function}).
312 @end ifnottex
313 @iftex
314 (see below).
315 @end iftex
316 The Speedbar can also use it (@pxref{Speedbar}).
317
318 @node Which Function
319 @subsection Which Function Mode
320 @cindex current function name in mode line
321
322 Which Function mode is a global minor mode (@pxref{Minor Modes})
323 which displays the current function name in the mode line, updating it
324 as you move around in a buffer.
325
326 @findex which-function-mode
327 @vindex which-func-modes
328 To either enable or disable Which Function mode, use the command
329 @kbd{M-x which-function-mode}. Which Function mode is a global minor
330 mode. By default, it takes effect in all major modes major modes that
331 know how to support it (i.e., all the major modes that support
332 Imenu). You can restrict it to a specific list of major modes by
333 changing the value of the variable @code{which-func-modes} from
334 @code{t} (which means to support all available major modes) to a list
335 of major mode names.
336
337 @node Program Indent
338 @section Indentation for Programs
339 @cindex indentation for programs
340
341 The best way to keep a program properly indented is to use Emacs to
342 reindent it as you change it. Emacs has commands to indent either a
343 single line, a specified number of lines, or all of the lines inside a
344 single parenthetical grouping.
345
346 @xref{Indentation}, for general information about indentation. This
347 section describes indentation features specific to programming
348 language modes.
349
350 @menu
351 * Basic Indent:: Indenting a single line.
352 * Multi-line Indent:: Commands to reindent many lines at once.
353 * Lisp Indent:: Specifying how each Lisp function should be indented.
354 * C Indent:: Extra features for indenting C and related modes.
355 * Custom C Indent:: Controlling indentation style for C and related modes.
356 @end menu
357
358 @cindex pretty-printer
359 Emacs also provides a Lisp pretty-printer in the @code{pp} package,
360 which reformats Lisp objects with nice-looking indentation.
361
362 @node Basic Indent
363 @subsection Basic Program Indentation Commands
364
365 @table @kbd
366 @item @key{TAB}
367 Adjust indentation of current line (@code{indent-for-tab-command}).
368 @item @key{RET}
369 Insert a newline, then adjust indentation of following line
370 (@code{newline}).
371 @end table
372
373 @kindex TAB @r{(programming modes)}
374 @findex c-indent-command
375 @findex indent-line-function
376 @findex indent-for-tab-command
377 The basic indentation command is @key{TAB}
378 (@code{indent-for-tab-command}), which was documented in
379 @ref{Indentation}. In programming language modes, @key{TAB} indents
380 the current line, based on the indentation and syntactic content of
381 the preceding lines; if the region is active, @key{TAB} indents each
382 line within the region, not just the current line.
383
384 The command @key{RET} (@code{newline}), which was documented in
385 @ref{Inserting Text}, does the same as @kbd{C-j} followed by
386 @key{TAB}: it inserts a new line, then adjusts the line's indentation.
387
388 When indenting a line that starts within a parenthetical grouping,
389 Emacs usually places the start of the line under the preceding line
390 within the group, or under the text after the parenthesis. If you
391 manually give one of these lines a nonstandard indentation (e.g., for
392 aesthetic purposes), the lines below will follow it.
393
394 The indentation commands for most programming language modes assume
395 that a open-parenthesis, open-brace or other opening delimiter at the
396 left margin is the start of a function. If the code you are editing
397 violates this assumption---even if the delimiters occur in strings or
398 comments---you must set @code{open-paren-in-column-0-is-defun-start}
399 to @code{nil} for indentation to work properly. @xref{Left Margin
400 Paren}.
401
402 @node Multi-line Indent
403 @subsection Indenting Several Lines
404
405 Sometimes, you may want to reindent several lines of code at a time.
406 One way to do this is to use the mark; when the mark is active and the
407 region is non-empty, @key{TAB} indents every line in the region.
408 Alternatively, the command @kbd{C-M-\} (@code{indent-region}) indents
409 every line in the region, whether or not the mark is active
410 (@pxref{Indentation Commands}).
411
412 In addition, Emacs provides the following commands for indenting
413 large chunks of code:
414
415 @table @kbd
416 @item C-M-q
417 Reindent all the lines within one parenthetical grouping.
418 @item C-u @key{TAB}
419 Shift an entire parenthetical grouping rigidly sideways so that its
420 first line is properly indented.
421 @item M-x indent-code-rigidly
422 Shift all the lines in the region rigidly sideways, but do not alter
423 lines that start inside comments and strings.
424 @end table
425
426 @kindex C-M-q
427 @findex indent-pp-sexp
428 To reindent the contents of a single parenthetical grouping,
429 position point before the beginning of the grouping and type
430 @kbd{C-M-q}. This changes the relative indentation within the
431 grouping, without affecting its overall indentation (i.e., the
432 indentation of the line where the grouping starts). The function that
433 @kbd{C-M-q} runs depends on the major mode; it is
434 @code{indent-pp-sexp} in Lisp mode, @code{c-indent-exp} in C mode,
435 etc. To correct the overall indentation as well, type @key{TAB}
436 first.
437
438 @kindex C-u TAB
439 If you like the relative indentation within a grouping but not the
440 indentation of its first line, move point to that first line and type
441 @kbd{C-u @key{TAB}}. In Lisp, C, and some other major modes,
442 @key{TAB} with a numeric argument reindents the current line as usual,
443 then reindents by the same amount all the lines in the parenthetical
444 grouping starting on the current line. It is clever, though, and does
445 not alter lines that start inside strings. Neither does it alter C
446 preprocessor lines when in C mode, but it does reindent any
447 continuation lines that may be attached to them.
448
449 @findex indent-code-rigidly
450 The command @kbd{M-x indent-code-rigidly} rigidly shifts all the
451 lines in the region sideways, like @code{indent-rigidly} does
452 (@pxref{Indentation Commands}). It doesn't alter the indentation of
453 lines that start inside a string, unless the region also starts inside
454 that string. The prefix arg specifies the number of columns to
455 indent.
456
457 @node Lisp Indent
458 @subsection Customizing Lisp Indentation
459 @cindex customizing Lisp indentation
460
461 The indentation pattern for a Lisp expression can depend on the function
462 called by the expression. For each Lisp function, you can choose among
463 several predefined patterns of indentation, or define an arbitrary one with
464 a Lisp program.
465
466 The standard pattern of indentation is as follows: the second line of the
467 expression is indented under the first argument, if that is on the same
468 line as the beginning of the expression; otherwise, the second line is
469 indented underneath the function name. Each following line is indented
470 under the previous line whose nesting depth is the same.
471
472 @vindex lisp-indent-offset
473 If the variable @code{lisp-indent-offset} is non-@code{nil}, it overrides
474 the usual indentation pattern for the second line of an expression, so that
475 such lines are always indented @code{lisp-indent-offset} more columns than
476 the containing list.
477
478 @vindex lisp-body-indent
479 Certain functions override the standard pattern. Functions whose
480 names start with @code{def} treat the second lines as the start of
481 a @dfn{body}, by indenting the second line @code{lisp-body-indent}
482 additional columns beyond the open-parenthesis that starts the
483 expression.
484
485 @cindex @code{lisp-indent-function} property
486 You can override the standard pattern in various ways for individual
487 functions, according to the @code{lisp-indent-function} property of
488 the function name. This is normally done for macro definitions, using
489 the @code{declare} construct. @xref{Defining Macros,,, elisp, the
490 Emacs Lisp Reference Manual}.
491
492 @node C Indent
493 @subsection Commands for C Indentation
494
495 Here are special features for indentation in C mode and related modes:
496
497 @table @code
498 @item C-c C-q
499 @kindex C-c C-q @r{(C mode)}
500 @findex c-indent-defun
501 Reindent the current top-level function definition or aggregate type
502 declaration (@code{c-indent-defun}).
503
504 @item C-M-q
505 @kindex C-M-q @r{(C mode)}
506 @findex c-indent-exp
507 Reindent each line in the balanced expression that follows point
508 (@code{c-indent-exp}). A prefix argument inhibits warning messages
509 about invalid syntax.
510
511 @item @key{TAB}
512 @findex c-indent-command
513 Reindent the current line, and/or in some cases insert a tab character
514 (@code{c-indent-command}).
515
516 @vindex c-tab-always-indent
517 If @code{c-tab-always-indent} is @code{t}, this command always reindents
518 the current line and does nothing else. This is the default.
519
520 If that variable is @code{nil}, this command reindents the current line
521 only if point is at the left margin or in the line's indentation;
522 otherwise, it inserts a tab (or the equivalent number of spaces,
523 if @code{indent-tabs-mode} is @code{nil}).
524
525 Any other value (not @code{nil} or @code{t}) means always reindent the
526 line, and also insert a tab if within a comment or a string.
527 @end table
528
529 To reindent the whole current buffer, type @kbd{C-x h C-M-\}. This
530 first selects the whole buffer as the region, then reindents that
531 region.
532
533 To reindent the current block, use @kbd{C-M-u C-M-q}. This moves
534 to the front of the block and then reindents it all.
535
536 @node Custom C Indent
537 @subsection Customizing C Indentation
538 @cindex style (for indentation)
539
540 C mode and related modes use a flexible mechanism for customizing
541 indentation. C mode indents a source line in two steps: first it
542 classifies the line syntactically according to its contents and
543 context; second, it determines the indentation offset associated by
544 your selected @dfn{style} with the syntactic construct and adds this
545 onto the indentation of the @dfn{anchor statement}.
546
547 @table @kbd
548 @item C-c . @var{style} @key{RET}
549 Select a predefined style @var{style} (@code{c-set-style}).
550 @end table
551
552 A @dfn{style} is a named collection of customizations that can be
553 used in C mode and the related modes. @ref{Styles,,, ccmode, The CC
554 Mode Manual}, for a complete description. Emacs comes with several
555 predefined styles, including @code{gnu}, @code{k&r}, @code{bsd},
556 @code{stroustrup}, @code{linux}, @code{python}, @code{java},
557 @code{whitesmith}, @code{ellemtel}, and @code{awk}. Some of these
558 styles are primarily intended for one language, but any of them can be
559 used with any of the languages supported by these modes. To find out
560 what a style looks like, select it and reindent some code, e.g., by
561 typing @kbd{C-M-q} at the start of a function definition.
562
563 @kindex C-c . @r{(C mode)}
564 @findex c-set-style
565 To choose a style for the current buffer, use the command @w{@kbd{C-c
566 .}}. Specify a style name as an argument (case is not significant).
567 This command affects the current buffer only, and it affects only
568 future invocations of the indentation commands; it does not reindent
569 the code already in the buffer. To reindent the whole buffer in the
570 new style, you can type @kbd{C-x h C-M-\}.
571
572 @vindex c-default-style
573 You can also set the variable @code{c-default-style} to specify the
574 default style for various major modes. Its value should be either the
575 style's name (a string) or an alist, in which each element specifies
576 one major mode and which indentation style to use for it. For
577 example,
578
579 @example
580 (setq c-default-style
581 '((java-mode . "java")
582 (awk-mode . "awk")
583 (other . "gnu")))
584 @end example
585
586 @noindent
587 specifies explicit choices for Java and AWK modes, and the default
588 @samp{gnu} style for the other C-like modes. (These settings are
589 actually the defaults.) This variable takes effect when you select
590 one of the C-like major modes; thus, if you specify a new default
591 style for Java mode, you can make it take effect in an existing Java
592 mode buffer by typing @kbd{M-x java-mode} there.
593
594 The @code{gnu} style specifies the formatting recommended by the GNU
595 Project for C; it is the default, so as to encourage use of our
596 recommended style.
597
598 @xref{Indentation Engine Basics,,, ccmode, the CC Mode Manual}, and
599 @ref{Customizing Indentation,,, ccmode, the CC Mode Manual}, for more
600 information on customizing indentation for C and related modes,
601 including how to override parts of an existing style and how to define
602 your own styles.
603
604 @findex c-guess
605 @findex c-guess-install
606 As an alternative to specifying a style, you can tell Emacs to guess
607 a style by typing @kbd{M-x c-guess} in a sample code buffer. You can
608 then apply the guessed style to other buffers with @kbd{M-x
609 c-guess-install}. @xref{Guessing the Style,,, ccmode, the CC Mode
610 Manual}, for details.
611
612 @node Parentheses
613 @section Commands for Editing with Parentheses
614
615 @findex check-parens
616 @cindex unbalanced parentheses and quotes
617 This section describes the commands and features that take advantage
618 of the parenthesis structure in a program, or help you keep it
619 balanced.
620
621 When talking about these facilities, the term ``parenthesis'' also
622 includes braces, brackets, or whatever delimiters are defined to match
623 in pairs. The major mode controls which delimiters are significant,
624 through the syntax table (@pxref{Syntax Tables,, Syntax Tables, elisp,
625 The Emacs Lisp Reference Manual}). In Lisp, only parentheses count;
626 in C, these commands apply to braces and brackets too.
627
628 You can use @kbd{M-x check-parens} to find any unbalanced
629 parentheses and unbalanced string quotes in the buffer.
630
631 @menu
632 * Expressions:: Expressions with balanced parentheses.
633 * Moving by Parens:: Commands for moving up, down and across
634 in the structure of parentheses.
635 * Matching:: Insertion of a close-delimiter flashes matching open.
636 @end menu
637
638 @node Expressions
639 @subsection Expressions with Balanced Parentheses
640
641 @cindex sexp
642 @cindex expression
643 @cindex balanced expression
644 Each programming language mode has its own definition of a
645 @dfn{balanced expression}. Balanced expressions typically include
646 individual symbols, numbers, and string constants, as well as pieces
647 of code enclosed in a matching pair of delimiters. The following
648 commands deal with balanced expressions (in Emacs, such expressions
649 are referred to internally as @dfn{sexps}@footnote{The word ``sexp''
650 is used to refer to an expression in Lisp.}).
651
652 @table @kbd
653 @item C-M-f
654 Move forward over a balanced expression (@code{forward-sexp}).
655 @item C-M-b
656 Move backward over a balanced expression (@code{backward-sexp}).
657 @item C-M-k
658 Kill balanced expression forward (@code{kill-sexp}).
659 @item C-M-t
660 Transpose expressions (@code{transpose-sexps}).
661 @item C-M-@@
662 @itemx C-M-@key{SPC}
663 Put mark after following expression (@code{mark-sexp}).
664 @end table
665
666 @kindex C-M-f
667 @kindex C-M-b
668 @findex forward-sexp
669 @findex backward-sexp
670 To move forward over a balanced expression, use @kbd{C-M-f}
671 (@code{forward-sexp}). If the first significant character after point
672 is an opening delimiter (e.g., @samp{(}, @samp{[} or @samp{@{} in C),
673 this command moves past the matching closing delimiter. If the
674 character begins a symbol, string, or number, the command moves over
675 that.
676
677 The command @kbd{C-M-b} (@code{backward-sexp}) moves backward over a
678 balanced expression---like @kbd{C-M-f}, but in the reverse direction.
679 If the expression is preceded by any prefix characters (single-quote,
680 backquote and comma, in Lisp), the command moves back over them as
681 well.
682
683 @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation
684 the specified number of times; with a negative argument means to move
685 in the opposite direction. In most modes, these two commands move
686 across comments as if they were whitespace. Note that their keys,
687 @kbd{C-M-f} and @kbd{C-M-b}, are analogous to @kbd{C-f} and @kbd{C-b},
688 which move by characters (@pxref{Moving Point}), and @kbd{M-f} and
689 @kbd{M-b}, which move by words (@pxref{Words}).
690
691 @cindex killing expressions
692 @kindex C-M-k
693 @findex kill-sexp
694 To kill a whole balanced expression, type @kbd{C-M-k}
695 (@code{kill-sexp}). This kills the text that @kbd{C-M-f} would move
696 over.
697
698 @cindex transposition of expressions
699 @kindex C-M-t
700 @findex transpose-sexps
701 @kbd{C-M-t} (@code{transpose-sexps}) switches the positions of the
702 previous balanced expression and the next one. It is analogous to the
703 @kbd{C-t} command, which transposes characters (@pxref{Transpose}).
704 An argument to @kbd{C-M-t} serves as a repeat count, moving the
705 previous expression over that many following ones. A negative
706 argument moves the previous balanced expression backwards across those
707 before it. An argument of zero, rather than doing nothing, transposes
708 the balanced expressions ending at or after point and the mark.
709
710 @kindex C-M-@@
711 @kindex C-M-@key{SPC}
712 @findex mark-sexp
713 To operate on balanced expressions with a command which acts on the
714 region, type @kbd{C-M-@key{SPC}} (@code{mark-sexp}). This sets the
715 mark where @kbd{C-M-f} would move to. While the mark is active, each
716 successive call to this command extends the region by shifting the
717 mark by one expression. Positive or negative numeric arguments move
718 the mark forward or backward by the specified number of expressions.
719 The alias @kbd{C-M-@@} is equivalent to @kbd{C-M-@key{SPC}}.
720 @xref{Marking Objects}, for more information about this and related
721 commands.
722
723 In languages that use infix operators, such as C, it is not possible
724 to recognize all balanced expressions because there can be multiple
725 possibilities at a given position. For example, C mode does not treat
726 @samp{foo + bar} as a single expression, even though it @emph{is} one
727 C expression; instead, it recognizes @samp{foo} as one expression and
728 @samp{bar} as another, with the @samp{+} as punctuation between them.
729 However, C mode recognizes @samp{(foo + bar)} as a single expression,
730 because of the parentheses.
731
732 @node Moving by Parens
733 @subsection Moving in the Parenthesis Structure
734
735 @cindex parenthetical groupings
736 @cindex parentheses, moving across
737 @cindex matching parenthesis and braces, moving to
738 @cindex braces, moving across
739 @cindex list commands
740
741 The following commands move over groupings delimited by parentheses
742 (or whatever else serves as delimiters in the language you are working
743 with). They ignore strings and comments, including any parentheses
744 within them, and also ignore parentheses that are quoted with an
745 escape character. These commands are mainly intended for editing
746 programs, but can be useful for editing any text containing
747 parentheses. They are referred to internally as ``list commands''
748 because in Lisp these groupings are lists.
749
750 These commands assume that the starting point is not inside a string
751 or a comment. If you invoke them from inside a string or comment, the
752 results are unreliable.
753
754 @table @kbd
755 @item C-M-n
756 Move forward over a parenthetical group (@code{forward-list}).
757 @item C-M-p
758 Move backward over a parenthetical group (@code{backward-list}).
759 @item C-M-u
760 Move up in parenthesis structure (@code{backward-up-list}).
761 @item C-M-d
762 Move down in parenthesis structure (@code{down-list}).
763 @end table
764
765 @kindex C-M-n
766 @kindex C-M-p
767 @findex forward-list
768 @findex backward-list
769 The list commands @kbd{C-M-n} (@code{forward-list}) and
770 @kbd{C-M-p} (@code{backward-list}) move forward or backward over one
771 (or @var{n}) parenthetical groupings.
772
773 @kindex C-M-u
774 @findex backward-up-list
775 @kbd{C-M-n} and @kbd{C-M-p} try to stay at the same level in the
776 parenthesis structure. To move @emph{up} one (or @var{n}) levels, use
777 @kbd{C-M-u} (@code{backward-up-list}). @kbd{C-M-u} moves backward up
778 past one unmatched opening delimiter. A positive argument serves as a
779 repeat count; a negative argument reverses the direction of motion, so
780 that the command moves forward and up one or more levels.
781
782 @kindex C-M-d
783 @findex down-list
784 To move @emph{down} in the parenthesis structure, use @kbd{C-M-d}
785 (@code{down-list}). In Lisp mode, where @samp{(} is the only opening
786 delimiter, this is nearly the same as searching for a @samp{(}. An
787 argument specifies the number of levels to go down.
788
789 @node Matching
790 @subsection Matching Parentheses
791 @cindex matching parentheses
792 @cindex parentheses, displaying matches
793
794 Emacs has a number of @dfn{parenthesis matching} features, which
795 make it easy to see how and whether parentheses (or other delimiters)
796 match up.
797
798 Whenever you type a self-inserting character that is a closing
799 delimiter, Emacs briefly indicates the location of the matching
800 opening delimiter, provided that is on the screen. If it is not on
801 the screen, Emacs displays some of the text near it in the echo area.
802 Either way, you can tell which grouping you are closing off. If the
803 opening delimiter and closing delimiter are mismatched---such as in
804 @samp{[x)}---a warning message is displayed in the echo area.
805
806 @vindex blink-matching-paren
807 @vindex blink-matching-paren-distance
808 @vindex blink-matching-delay
809 Three variables control the display of matching parentheses:
810
811 @itemize @bullet
812 @item
813 @code{blink-matching-paren} turns the feature on or off: @code{nil}
814 disables it, but the default is @code{t} to enable it. Set it to
815 @code{jump} to make indication work by momentarily moving the cursor
816 to the matching opening delimiter. Set it to @code{jump-offscreen} to
817 make the cursor jump, even if the opening delimiter is off screen.
818
819 @item
820 @code{blink-matching-delay} says how many seconds to keep indicating
821 the matching opening delimiter. This may be an integer or
822 floating-point number; the default is 1.
823
824 @item
825 @code{blink-matching-paren-distance} specifies how many characters
826 back to search to find the matching opening delimiter. If the match
827 is not found in that distance, Emacs stops scanning and nothing is
828 displayed. The default is 102400.
829 @end itemize
830
831 @cindex Show Paren mode
832 @cindex highlighting matching parentheses
833 @findex show-paren-mode
834 Show Paren mode, a global minor mode, provides a more powerful kind
835 of automatic matching. Whenever point is before an opening delimiter
836 or after a closing delimiter, both that delimiter and its opposite
837 delimiter are highlighted. To toggle Show Paren mode, type @kbd{M-x
838 show-paren-mode}.
839
840 @cindex Electric Pair mode
841 @cindex inserting matching parentheses
842 @findex electric-pair-mode
843 Electric Pair mode, a global minor mode, provides a way to easily
844 insert matching delimiters. Whenever you insert an opening delimiter,
845 the matching closing delimiter is automatically inserted as well,
846 leaving point between the two. Conversely, when you insert a closing
847 delimiter over an existing one, no inserting takes places and that
848 position is simply skipped over. These variables control additional
849 features of Electric Pair mode:
850
851 @itemize @bullet
852 @item
853 @code{electric-pair-preserve-balance}, when non-@code{nil}, makes the
854 default pairing logic balance out the number of opening and closing
855 delimiters.
856
857 @item
858 @code{electric-pair-delete-adjacent-pairs}, when non-@code{nil}, makes
859 backspacing between two adjacent delimiters also automatically delete
860 the closing delimiter.
861
862 @item
863 @code{electric-pair-open-newline-between-pairs}, when non-@code{nil},
864 makes inserting inserting a newline between two adjacent pairs also
865 automatically open and extra newline after point.
866
867 @item
868 @code{electric-pair-skip-whitespace}, when non-@code{nil}, causes the minor
869 mode to skip whitespace forward before deciding whether to skip over
870 the closing delimiter.
871 @end itemize
872
873 To toggle Electric Pair mode, type @kbd{M-x electric-pair-mode}. To
874 toggle the mode in a single buffer, use @kbd{M-x
875 electric-pair-local-mode}.
876
877 @node Comments
878 @section Manipulating Comments
879 @cindex comments
880
881 Because comments are such an important part of programming, Emacs
882 provides special commands for editing and inserting comments. It can
883 also do spell checking on comments with Flyspell Prog mode
884 (@pxref{Spelling}).
885
886 Some major modes have special rules for indenting different kinds of
887 comments. For example, in Lisp code, comments starting with two
888 semicolons are indented as if they were lines of code, while those
889 starting with three semicolons are supposed to be aligned to the left
890 margin and are often used for sectioning purposes. Emacs understand
891 these conventions; for instance, typing @key{TAB} on a comment line
892 will indent the comment to the appropriate position.
893
894 @example
895 ;; This function is just an example.
896 ;;; Here either two or three semicolons are appropriate.
897 (defun foo (x)
898 ;;; And now, the first part of the function:
899 ;; The following line adds one.
900 (1+ x)) ; This line adds one.
901 @end example
902
903 @menu
904 * Comment Commands:: Inserting, killing, and aligning comments.
905 * Multi-Line Comments:: Commands for adding and editing multi-line comments.
906 * Options for Comments::Customizing the comment features.
907 @end menu
908
909 @node Comment Commands
910 @subsection Comment Commands
911 @cindex indentation for comments
912 @cindex alignment for comments
913
914 The following commands operate on comments:
915
916 @table @asis
917 @item @kbd{M-;}
918 Insert or realign comment on current line; if the region is active,
919 comment or uncomment the region instead (@code{comment-dwim}).
920 @item @kbd{C-x C-;}
921 Comment or uncomment the current line (@code{comment-line}).
922 @item @kbd{C-u M-;}
923 Kill comment on current line (@code{comment-kill}).
924 @item @kbd{C-x ;}
925 Set comment column (@code{comment-set-column}).
926 @item @kbd{C-M-j}
927 @itemx @kbd{M-j}
928 Like @key{RET} followed by inserting and aligning a comment
929 (@code{comment-indent-new-line}). @xref{Multi-Line Comments}.
930 @item @kbd{M-x comment-region}
931 @itemx @kbd{C-c C-c} (in C-like modes)
932 Add comment delimiters to all the lines in the region.
933 @end table
934
935 @kindex M-;
936 @findex comment-dwim
937 The command to create or align a comment is @kbd{M-;}
938 (@code{comment-dwim}). The word ``dwim'' is an acronym for ``Do What
939 I Mean''; it indicates that this command can be used for many
940 different jobs relating to comments, depending on the situation where
941 you use it.
942
943 When a region is active (@pxref{Mark}), @kbd{M-;} either adds
944 comment delimiters to the region, or removes them. If every line in
945 the region is already a comment, it uncomments each of those lines
946 by removing their comment delimiters. Otherwise, it adds comment
947 delimiters to enclose the text in the region.
948
949 If you supply a prefix argument to @kbd{M-;} when a region is
950 active, that specifies the number of comment delimiters to add or
951 delete. A positive argument @var{n} adds @var{n} delimiters, while a
952 negative argument @var{-n} removes @var{n} delimiters.
953
954 If the region is not active, and there is no existing comment on the
955 current line, @kbd{M-;} adds a new comment to the current line. If
956 the line is blank (i.e., empty or containing only whitespace
957 characters), the comment is indented to the same position where
958 @key{TAB} would indent to (@pxref{Basic Indent}). If the line is
959 non-blank, the comment is placed after the last non-whitespace
960 character on the line; normally, Emacs tries putting it at the column
961 specified by the variable @code{comment-column} (@pxref{Options for
962 Comments}), but if the line already extends past that column, it puts
963 the comment at some suitable position, usually separated from the
964 non-comment text by at least one space. In each case, Emacs places
965 point after the comment's starting delimiter, so that you can start
966 typing the comment text right away.
967
968 You can also use @kbd{M-;} to align an existing comment. If a line
969 already contains the comment-start string, @kbd{M-;} realigns it to
970 the conventional alignment and moves point after the comment's
971 starting delimiter. As an exception, comments starting in column 0
972 are not moved. Even when an existing comment is properly aligned,
973 @kbd{M-;} is still useful for moving directly to the start of the
974 comment text.
975
976 @findex comment-line
977 @kindex C-x C-;
978 @kbd{C-x C-;} (@code{comment-line}) comments or uncomments complete
979 lines. When a region is active (@pxref{Mark}), @kbd{C-x C-;} either
980 comments or uncomments the lines in the region. If the region is not
981 active, this command comments or uncomments the line point is on.
982 With a positive prefix argument @var{n}, it operates on @var{n} lines
983 starting with the current one; with a negative @var{n}, it affects
984 @var{n} preceding lines. After invoking this command with a negative
985 argument, successive invocations with a positive argument will operate
986 on preceding lines as if the argument were negated.
987
988 @findex comment-kill
989 @kindex C-u M-;
990 @kbd{C-u M-;} (@code{comment-dwim} with a prefix argument) kills any
991 comment on the current line, along with the whitespace before it.
992 Since the comment is saved to the kill ring, you can reinsert it on
993 another line by moving to the end of that line, doing @kbd{C-y}, and
994 then @kbd{M-;} to realign the comment. You can achieve the same
995 effect as @kbd{C-u M-;} by typing @kbd{M-x comment-kill}
996 (@code{comment-dwim} actually calls @code{comment-kill} as a
997 subroutine when it is given a prefix argument).
998
999 @kindex C-c C-c (C mode)
1000 @findex comment-region
1001 @findex uncomment-region
1002 The command @kbd{M-x comment-region} is equivalent to calling
1003 @kbd{M-;} on an active region, except that it always acts on the
1004 region, even if the mark is inactive. In C mode and related modes,
1005 this command is bound to @kbd{C-c C-c}. The command @kbd{M-x
1006 uncomment-region} uncomments each line in the region; a numeric prefix
1007 argument specifies the number of comment delimiters to remove
1008 (negative arguments specify the number of comment to delimiters to
1009 add).
1010
1011 For C-like modes, you can configure the exact effect of @kbd{M-;} by
1012 setting the variables @code{c-indent-comment-alist} and
1013 @code{c-indent-comments-syntactically-p}. For example, on a line
1014 ending in a closing brace, @kbd{M-;} puts the comment one space after
1015 the brace rather than at @code{comment-column}. For full details see
1016 @ref{Comment Commands,,, ccmode, The CC Mode Manual}.
1017
1018 @node Multi-Line Comments
1019 @subsection Multiple Lines of Comments
1020
1021 @kindex C-M-j
1022 @kindex M-j
1023 @cindex blank lines in programs
1024 @findex comment-indent-new-line
1025 @vindex comment-multi-line
1026 If you are typing a comment and wish to continue it to another line,
1027 type @kbd{M-j} or @kbd{C-M-j} (@code{comment-indent-new-line}). This
1028 breaks the current line, and inserts the necessary comment delimiters
1029 and indentation to continue the comment.
1030
1031 For languages with closing comment delimiters (e.g., @samp{*/} in
1032 C), the exact behavior of @kbd{M-j} depends on the value of the
1033 variable @code{comment-multi-line}. If the value is @code{nil}, the
1034 command closes the comment on the old line and starts a new comment on
1035 the new line. Otherwise, it opens a new line within the current
1036 comment delimiters.
1037
1038 When Auto Fill mode is on, going past the fill column while typing a
1039 comment also continues the comment, in the same way as an explicit
1040 invocation of @kbd{M-j}.
1041
1042 To turn existing lines into comment lines, use @kbd{M-;} with the
1043 region active, or use @kbd{M-x comment-region}
1044 @ifinfo
1045 (@pxref{Comment Commands}).
1046 @end ifinfo
1047 @ifnotinfo
1048 as described in the preceding section.
1049 @end ifnotinfo
1050
1051 You can configure C Mode such that when you type a @samp{/} at the
1052 start of a line in a multi-line block comment, this closes the
1053 comment. Enable the @code{comment-close-slash} clean-up for this.
1054 @xref{Clean-ups,,, ccmode, The CC Mode Manual}.
1055
1056 @node Options for Comments
1057 @subsection Options Controlling Comments
1058
1059 @vindex comment-column
1060 @kindex C-x ;
1061 @findex comment-set-column
1062 As mentioned in @ref{Comment Commands}, when the @kbd{M-j} command
1063 adds a comment to a line, it tries to place the comment at the column
1064 specified by the buffer-local variable @code{comment-column}. You can
1065 set either the local value or the default value of this buffer-local
1066 variable in the usual way (@pxref{Locals}). Alternatively, you can
1067 type @kbd{C-x ;} (@code{comment-set-column}) to set the value of
1068 @code{comment-column} in the current buffer to the column where point
1069 is currently located. @kbd{C-u C-x ;} sets the comment column to
1070 match the last comment before point in the buffer, and then does a
1071 @kbd{M-;} to align the current line's comment under the previous one.
1072
1073 @vindex comment-start-skip
1074 The comment commands recognize comments based on the regular
1075 expression that is the value of the variable @code{comment-start-skip}.
1076 Make sure this regexp does not match the null string. It may match more
1077 than the comment starting delimiter in the strictest sense of the word;
1078 for example, in C mode the value of the variable is
1079 @c This stops M-q from breaking the line inside that @code.
1080 @code{@w{"\\(//+\\|/\\*+\\)\\s *"}}, which matches extra stars and
1081 spaces after the @samp{/*} itself, and accepts C++ style comments
1082 also. (Note that @samp{\\} is needed in Lisp syntax to include a
1083 @samp{\} in the string, which is needed to deny the first star its
1084 special meaning in regexp syntax. @xref{Regexp Backslash}.)
1085
1086 @vindex comment-start
1087 @vindex comment-end
1088 When a comment command makes a new comment, it inserts the value of
1089 @code{comment-start} as an opening comment delimiter. It also inserts
1090 the value of @code{comment-end} after point, as a closing comment
1091 delimiter. For example, in Lisp mode, @code{comment-start} is
1092 @samp{";"} and @code{comment-end} is @code{""} (the empty string). In
1093 C mode, @code{comment-start} is @code{"/* "} and @code{comment-end} is
1094 @code{" */"}.
1095
1096 @vindex comment-padding
1097 The variable @code{comment-padding} specifies a string that the
1098 commenting commands should insert between the comment delimiter(s) and
1099 the comment text. The default, @samp{" "}, specifies a single space.
1100 Alternatively, the value can be a number, which specifies that number
1101 of spaces, or @code{nil}, which means no spaces at all.
1102
1103 The variable @code{comment-multi-line} controls how @kbd{M-j} and
1104 Auto Fill mode continue comments over multiple lines.
1105 @xref{Multi-Line Comments}.
1106
1107 @vindex comment-indent-function
1108 The variable @code{comment-indent-function} should contain a function
1109 that will be called to compute the alignment for a newly inserted
1110 comment or for aligning an existing comment. It is set differently by
1111 various major modes. The function is called with no arguments, but with
1112 point at the beginning of the comment, or at the end of a line if a new
1113 comment is to be inserted. It should return the column in which the
1114 comment ought to start. For example, in Lisp mode, the indent hook
1115 function bases its decision on how many semicolons begin an existing
1116 comment, and on the code in the preceding lines.
1117
1118 @node Documentation
1119 @section Documentation Lookup
1120
1121 Emacs provides several features you can use to look up the
1122 documentation of functions, variables and commands that you plan to
1123 use in your program.
1124
1125 @menu
1126 * Info Lookup:: Looking up library functions and commands in Info files.
1127 * Man Page:: Looking up man pages of library functions and commands.
1128 * Lisp Doc:: Looking up Emacs Lisp functions, etc.
1129 @end menu
1130
1131 @node Info Lookup
1132 @subsection Info Documentation Lookup
1133
1134 @findex info-lookup-symbol
1135 @findex info-lookup-file
1136 @kindex C-h S
1137 For major modes that apply to languages which have documentation in
1138 Info, you can use @kbd{C-h S} (@code{info-lookup-symbol}) to view the
1139 Info documentation for a symbol used in the program. You specify the
1140 symbol with the minibuffer; the default is the symbol appearing in the
1141 buffer at point. For example, in C mode this looks for the symbol in
1142 the C Library Manual. The command only works if the appropriate
1143 manual's Info files are installed.
1144
1145 The major mode determines where to look for documentation for the
1146 symbol---which Info files to look in, and which indices to search.
1147 You can also use @kbd{M-x info-lookup-file} to look for documentation
1148 for a file name.
1149
1150 If you use @kbd{C-h S} in a major mode that does not support it,
1151 it asks you to specify the symbol help mode. You should enter
1152 a command such as @code{c-mode} that would select a major
1153 mode which @kbd{C-h S} does support.
1154
1155 @node Man Page
1156 @subsection Man Page Lookup
1157
1158 @cindex man page
1159 On Unix, the main form of on-line documentation was the @dfn{manual
1160 page} or @dfn{man page}. In the GNU operating system, we aim to
1161 replace man pages with better-organized manuals that you can browse
1162 with Info (@pxref{Misc Help}). This process is not finished, so it is
1163 still useful to read manual pages.
1164
1165 @findex manual-entry
1166 You can read the man page for an operating system command, library
1167 function, or system call, with the @kbd{M-x man} command. This
1168 prompts for a topic, with completion (@pxref{Completion}), and runs
1169 the @command{man} program to format the corresponding man page. If
1170 the system permits, it runs @command{man} asynchronously, so that you
1171 can keep on editing while the page is being formatted. The result
1172 goes in a buffer named @file{*Man @var{topic}*}. These buffers use a
1173 special major mode, Man mode, that facilitates scrolling and jumping
1174 to other manual pages. For details, type @kbd{C-h m} while in a Man
1175 mode buffer.
1176
1177 @cindex sections of manual pages
1178 Each man page belongs to one of ten or more @dfn{sections}, each
1179 named by a digit or by a digit and a letter. Sometimes there are man
1180 pages with the same name in different sections. To read a man page
1181 from a specific section, type @samp{@var{topic}(@var{section})} or
1182 @samp{@var{section} @var{topic}} when @kbd{M-x manual-entry} prompts
1183 for the topic. For example, the man page for the C library function
1184 @code{chmod} is in section 2, but there is a shell command of the same
1185 name, whose man page is in section 1; to view the former, type
1186 @kbd{M-x manual-entry @key{RET} chmod(2) @key{RET}}.
1187
1188 @vindex Man-switches
1189 @kindex M-n @r{(Man mode)}
1190 @kindex M-p @r{(Man mode)}
1191 If you do not specify a section, @kbd{M-x man} normally displays
1192 only the first man page found. On some systems, the @code{man}
1193 program accepts a @samp{-a} command-line option, which tells it to
1194 display all the man pages for the specified topic. To make use of
1195 this, change the value of the variable @code{Man-switches} to
1196 @samp{"-a"}. Then, in the Man mode buffer, you can type @kbd{M-n} and
1197 @kbd{M-p} to switch between man pages in different sections. The mode
1198 line shows how many manual pages are available.
1199
1200 @findex woman
1201 @cindex manual pages, on MS-DOS/MS-Windows
1202 An alternative way of reading manual pages is the @kbd{M-x woman}
1203 command. Unlike @kbd{M-x man}, it does not run any external programs
1204 to format and display the man pages; the formatting is done by Emacs,
1205 so it works on systems such as MS-Windows where the @command{man}
1206 program may be unavailable. It prompts for a man page, and displays
1207 it in a buffer named @file{*WoMan @var{section} @var{topic}}.
1208
1209 @kbd{M-x woman} computes the completion list for manpages the first
1210 time you invoke the command. With a numeric argument, it recomputes
1211 this list; this is useful if you add or delete manual pages.
1212
1213 If you type a name of a manual page and @kbd{M-x woman} finds that
1214 several manual pages by the same name exist in different sections, it
1215 pops up a window with possible candidates asking you to choose one of
1216 them.
1217
1218 For more information about setting up and using @kbd{M-x woman}, see
1219 @ifinfo
1220 @ref{Top, WoMan, Browse UN*X Manual Pages WithOut Man, woman, The
1221 WoMan Manual}.
1222 @end ifinfo
1223 @ifnotinfo
1224 the WoMan Info manual, which is distributed with Emacs.
1225 @end ifnotinfo
1226
1227 @node Lisp Doc
1228 @subsection Emacs Lisp Documentation Lookup
1229
1230 When editing Emacs Lisp code, you can use the commands @kbd{C-h f}
1231 (@code{describe-function}) and @kbd{C-h v} (@code{describe-variable})
1232 to view the built-in documentation for the Lisp functions and
1233 variables that you want to use. @xref{Name Help}.
1234
1235 @cindex Eldoc mode
1236 @findex eldoc-mode
1237 Eldoc is a buffer-local minor mode that helps with looking up Lisp
1238 documentation. When it is enabled, the echo area displays some useful
1239 information whenever there is a Lisp function or variable at point;
1240 for a function, it shows the argument list, and for a variable it
1241 shows the first line of the variable's documentation string. To
1242 toggle Eldoc mode, type @kbd{M-x eldoc-mode}. Eldoc mode can be used
1243 with the Emacs Lisp and Lisp Interaction major modes.
1244
1245 @node Hideshow
1246 @section Hideshow minor mode
1247 @cindex Hideshow mode
1248 @cindex mode, Hideshow
1249
1250 @findex hs-minor-mode
1251 Hideshow mode is a buffer-local minor mode that allows you to
1252 selectively display portions of a program, which are referred to as
1253 @dfn{blocks}. Type @kbd{M-x hs-minor-mode} to toggle this minor mode
1254 (@pxref{Minor Modes}).
1255
1256 When you use Hideshow mode to hide a block, the block disappears
1257 from the screen, to be replaced by an ellipsis (three periods in a
1258 row). Just what constitutes a block depends on the major mode. In C
1259 mode and related modes, blocks are delimited by braces, while in Lisp
1260 mode they are delimited by parentheses. Multi-line comments also
1261 count as blocks.
1262
1263 Hideshow mode provides the following commands:
1264
1265 @findex hs-hide-all
1266 @findex hs-hide-block
1267 @findex hs-show-all
1268 @findex hs-show-block
1269 @findex hs-show-region
1270 @findex hs-hide-level
1271 @findex hs-minor-mode
1272 @kindex C-c @@ C-h
1273 @kindex C-c @@ C-s
1274 @kindex C-c @@ C-M-h
1275 @kindex C-c @@ C-M-s
1276 @kindex C-c @@ C-r
1277 @kindex C-c @@ C-l
1278 @kindex S-Mouse-2
1279 @table @kbd
1280 @item C-c @@ C-h
1281 Hide the current block (@code{hs-hide-block}).
1282 @item C-c @@ C-s
1283 Show the current block (@code{hs-show-block}).
1284 @item C-c @@ C-c
1285 Either hide or show the current block (@code{hs-toggle-hiding}).
1286 @item S-Mouse-2
1287 Toggle hiding for the block you click on (@code{hs-mouse-toggle-hiding}).
1288 @item C-c @@ C-M-h
1289 Hide all top-level blocks (@code{hs-hide-all}).
1290 @item C-c @@ C-M-s
1291 Show all blocks in the buffer (@code{hs-show-all}).
1292 @item C-c @@ C-l
1293 Hide all blocks @var{n} levels below this block
1294 (@code{hs-hide-level}).
1295 @end table
1296
1297 @vindex hs-hide-comments-when-hiding-all
1298 @vindex hs-isearch-open
1299 @vindex hs-special-modes-alist
1300 These variables can be used to customize Hideshow mode:
1301
1302 @table @code
1303 @item hs-hide-comments-when-hiding-all
1304 If non-@code{nil}, @kbd{C-c @@ C-M-h} (@code{hs-hide-all}) hides
1305 comments too.
1306
1307 @item hs-isearch-open
1308 This variable specifies the conditions under which incremental search
1309 should unhide a hidden block when matching text occurs within the
1310 block. Its value should be either @code{code} (unhide only code
1311 blocks), @code{comment} (unhide only comments), @code{t} (unhide both
1312 code blocks and comments), or @code{nil} (unhide neither code blocks
1313 nor comments). The default value is @code{code}.
1314 @end table
1315
1316 @node Symbol Completion
1317 @section Completion for Symbol Names
1318 @cindex completion (symbol names)
1319
1320 Completion is normally done in the minibuffer (@pxref{Completion}),
1321 but you can also complete symbol names in ordinary Emacs buffers.
1322
1323 @kindex M-TAB
1324 @kindex C-M-i
1325 In programming language modes, type @kbd{C-M-i} or @kbd{M-@key{TAB}}
1326 to complete the partial symbol before point. On graphical displays,
1327 the @kbd{M-@key{TAB}} key is usually reserved by the window manager
1328 for switching graphical windows, so you should type @kbd{C-M-i} or
1329 @kbd{@key{ESC} @key{TAB}} instead.
1330
1331 @cindex tags-based completion
1332 @findex completion-at-point
1333 @cindex Lisp symbol completion
1334 @cindex completion (Lisp symbols)
1335 In most programming language modes, @kbd{C-M-i} (or
1336 @kbd{M-@key{TAB}}) invokes the command @code{completion-at-point},
1337 which generates its completion list in a flexible way. If Semantic
1338 mode is enabled, it tries to use the Semantic parser data for
1339 completion (@pxref{Semantic}). If Semantic mode is not enabled or
1340 fails at performing completion, it tries to complete using the
1341 selected tags table (@pxref{Tags}). If in Emacs Lisp mode, it
1342 performs completion using the function, variable, or property names
1343 defined in the current Emacs session.
1344
1345 In all other respects, in-buffer symbol completion behaves like
1346 minibuffer completion. For instance, if Emacs cannot complete to a
1347 unique symbol, it displays a list of completion alternatives in
1348 another window. @xref{Completion}.
1349
1350 In Text mode and related modes, @kbd{M-@key{TAB}} completes words
1351 based on the spell-checker's dictionary. @xref{Spelling}.
1352
1353 @node MixedCase Words
1354 @section MixedCase Words
1355 @cindex camel case
1356
1357 Some programming styles make use of mixed-case (or ``CamelCase'')
1358 symbols like @samp{unReadableSymbol}. (In the GNU project, we recommend
1359 using underscores to separate words within an identifier, rather than
1360 using case distinctions.) Emacs has various features to make it easier
1361 to deal with such symbols.
1362
1363 @cindex Glasses mode
1364 @findex mode, Glasses
1365 Glasses mode is a buffer-local minor mode that makes it easier to read
1366 such symbols, by altering how they are displayed. By default, it
1367 displays extra underscores between each lower-case letter and the
1368 following capital letter. This does not alter the buffer text, only how
1369 it is displayed.
1370
1371 To toggle Glasses mode, type @kbd{M-x glasses-mode} (@pxref{Minor
1372 Modes}). When Glasses mode is enabled, the minor mode indicator
1373 @samp{o^o} appears in the mode line. For more information about
1374 Glasses mode, type @kbd{C-h P glasses @key{RET}}.
1375
1376 @cindex Subword mode
1377 @findex subword-mode
1378 Subword mode is another buffer-local minor mode. In subword mode,
1379 Emacs's word commands recognize upper case letters in
1380 @samp{StudlyCapsIdentifiers} as word boundaries. When Subword mode is
1381 enabled, the minor mode indicator @samp{,} appears in the mode line.
1382 See also the similar @code{superword-mode} (@pxref{Misc for Programs}).
1383
1384 @node Semantic
1385 @section Semantic
1386 @cindex Semantic package
1387
1388 Semantic is a package that provides language-aware editing commands
1389 based on @code{source code parsers}. This section provides a brief
1390 description of Semantic; for full details,
1391 @ifnottex
1392 see @ref{Top, Semantic,, semantic, Semantic}.
1393 @end ifnottex
1394 @iftex
1395 see the Semantic Info manual, which is distributed with Emacs.
1396 @end iftex
1397
1398 Most of the language-aware features in Emacs, such as Font Lock
1399 mode (@pxref{Font Lock}), rely on rules of thumb@footnote{Regular
1400 expressions and syntax tables.} that usually give good results but are
1401 never completely exact. In contrast, the parsers used by Semantic
1402 have an exact understanding of programming language syntax. This
1403 allows Semantic to provide search, navigation, and completion commands
1404 that are powerful and precise.
1405
1406 @cindex Semantic mode
1407 @cindex mode, Semantic
1408 To begin using Semantic, type @kbd{M-x semantic-mode} or click on
1409 the menu item named @samp{Source Code Parsers (Semantic)} in the
1410 @samp{Tools} menu. This enables Semantic mode, a global minor mode.
1411
1412 When Semantic mode is enabled, Emacs automatically attempts to
1413 parse each file you visit. Currently, Semantic understands C, C++,
1414 Scheme, Javascript, Java, HTML, and Make. Within each parsed buffer,
1415 the following commands are available:
1416
1417 @table @kbd
1418 @item C-c , j
1419 @kindex C-c , j
1420 Prompt for the name of a function defined in the current file, and
1421 move point there (@code{semantic-complete-jump-local}).
1422
1423 @item C-c , J
1424 @kindex C-c , J
1425 Prompt for the name of a function defined in any file Emacs has
1426 parsed, and move point there (@code{semantic-complete-jump}).
1427
1428 @item C-c , @key{SPC}
1429 @kindex C-c , @key{SPC}
1430 Display a list of possible completions for the symbol at point
1431 (@code{semantic-complete-analyze-inline}). This also activates a set
1432 of special key bindings for choosing a completion: @key{RET} accepts
1433 the current completion, @kbd{M-n} and @kbd{M-p} cycle through possible
1434 completions, @key{TAB} completes as far as possible and then cycles,
1435 and @kbd{C-g} or any other key aborts completion.
1436
1437 @item C-c , l
1438 @kindex C-c , l
1439 Display a list of the possible completions of the symbol at point, in
1440 another window (@code{semantic-analyze-possible-completions}).
1441 @end table
1442
1443 @noindent
1444 In addition to the above commands, the Semantic package provides a
1445 variety of other ways to make use of parser information. For
1446 instance, you can use it to display a list of completions when Emacs
1447 is idle.
1448 @ifnottex
1449 @xref{Top, Semantic,, semantic, Semantic}, for details.
1450 @end ifnottex
1451
1452 @node Misc for Programs
1453 @section Other Features Useful for Editing Programs
1454
1455 Some Emacs commands that aren't designed specifically for editing
1456 programs are useful for that nonetheless.
1457
1458 The Emacs commands that operate on words, sentences and paragraphs
1459 are useful for editing code. Most symbols names contain words
1460 (@pxref{Words}), while sentences can be found in strings and comments
1461 (@pxref{Sentences}). As for paragraphs, they are defined in most
1462 programming language modes to begin and end at blank lines
1463 (@pxref{Paragraphs}). Therefore, judicious use of blank lines to make
1464 the program clearer will also provide useful chunks of text for the
1465 paragraph commands to work on. Auto Fill mode, if enabled in a
1466 programming language major mode, indents the new lines which it
1467 creates.
1468
1469 @findex superword-mode
1470 Superword mode is a buffer-local minor mode that causes editing and
1471 motion commands to treat symbols (e.g., @samp{this_is_a_symbol}) as words.
1472 When Superword mode is enabled, the minor mode indicator
1473 @iftex
1474 @samp{@math{^2}}
1475 @end iftex
1476 @ifnottex
1477 @samp{²}
1478 @end ifnottex
1479 appears in the mode line. See also the similar @code{subword-mode}
1480 (@pxref{MixedCase Words}).
1481
1482 @findex electric-layout-mode
1483 Electric Layout mode (@kbd{M-x electric-layout-mode}) is a global
1484 minor mode that automatically inserts newlines when you type certain
1485 characters; for example, @samp{@{}, @samp{@}} and @samp{;} in Javascript
1486 mode.
1487
1488 Apart from Hideshow mode (@pxref{Hideshow}), another way to
1489 selectively display parts of a program is to use the selective display
1490 feature (@pxref{Selective Display}). Programming modes often also
1491 support Outline minor mode (@pxref{Outline Mode}), which can be used
1492 with the Foldout package (@pxref{Foldout}).
1493
1494 @ifinfo
1495 The automatic typing features may be useful for writing programs.
1496 @xref{Top,,Autotyping, autotype, Autotyping}.
1497 @end ifinfo
1498
1499 @findex prettify-symbols-mode
1500 Prettify Symbols mode is a buffer-local minor mode that replaces
1501 certain strings with more attractive versions for display
1502 purposes. For example, in Emacs Lisp mode, it replaces the string
1503 @samp{lambda} with the Greek lambda character @samp{λ}. You may wish
1504 to use this
1505 in non-programming modes as well. You can customize the mode by
1506 adding more entries to @code{prettify-symbols-alist}. There is also a
1507 global version, @code{global-prettify-symbols-mode}, which enables the
1508 mode in all buffers that support it.
1509
1510
1511 @node C Modes
1512 @section C and Related Modes
1513 @cindex C mode
1514 @cindex Java mode
1515 @cindex Pike mode
1516 @cindex IDL mode
1517 @cindex CORBA IDL mode
1518 @cindex Objective C mode
1519 @cindex C++ mode
1520 @cindex AWK mode
1521 @cindex mode, Java
1522 @cindex mode, C
1523 @cindex mode, C++
1524 @cindex mode, Objective C
1525 @cindex mode, CORBA IDL
1526 @cindex mode, Pike
1527 @cindex mode, AWK
1528
1529 This section gives a brief description of the special features
1530 available in C, C++, Objective-C, Java, CORBA IDL, Pike and AWK modes.
1531 (These are called ``C mode and related modes''.)
1532 @ifinfo
1533 @xref{Top,, CC Mode, ccmode, CC Mode}, for more details.
1534 @end ifinfo
1535 @ifnotinfo
1536 For more details, see the CC mode Info manual, which is distributed
1537 with Emacs.
1538 @end ifnotinfo
1539
1540 @menu
1541 * Motion in C:: Commands to move by C statements, etc.
1542 * Electric C:: Colon and other chars can automatically reindent.
1543 * Hungry Delete:: A more powerful DEL command.
1544 * Other C Commands:: Filling comments, viewing expansion of macros,
1545 and other neat features.
1546 @end menu
1547
1548 @node Motion in C
1549 @subsection C Mode Motion Commands
1550
1551 This section describes commands for moving point, in C mode and
1552 related modes.
1553
1554 @table @code
1555 @item C-M-a
1556 @itemx C-M-e
1557 @findex c-beginning-of-defun
1558 @findex c-end-of-defun
1559 Move point to the beginning or end of the current function or
1560 top-level definition. In languages with enclosing scopes (such as
1561 C++'s classes) the @dfn{current function} is the immediate one,
1562 possibly inside a scope. Otherwise it is the one defined by the least
1563 enclosing braces. (By contrast, @code{beginning-of-defun} and
1564 @code{end-of-defun} search for braces in column zero.) @xref{Moving
1565 by Defuns}.
1566
1567 @item C-c C-u
1568 @kindex C-c C-u @r{(C mode)}
1569 @findex c-up-conditional
1570 Move point back to the containing preprocessor conditional, leaving the
1571 mark behind. A prefix argument acts as a repeat count. With a negative
1572 argument, move point forward to the end of the containing
1573 preprocessor conditional.
1574
1575 @samp{#elif} is equivalent to @samp{#else} followed by @samp{#if}, so
1576 the function will stop at a @samp{#elif} when going backward, but not
1577 when going forward.
1578
1579 @item C-c C-p
1580 @kindex C-c C-p @r{(C mode)}
1581 @findex c-backward-conditional
1582 Move point back over a preprocessor conditional, leaving the mark
1583 behind. A prefix argument acts as a repeat count. With a negative
1584 argument, move forward.
1585
1586 @item C-c C-n
1587 @kindex C-c C-n @r{(C mode)}
1588 @findex c-forward-conditional
1589 Move point forward across a preprocessor conditional, leaving the mark
1590 behind. A prefix argument acts as a repeat count. With a negative
1591 argument, move backward.
1592
1593 @item M-a
1594 @kindex M-a (C mode)
1595 @findex c-beginning-of-statement
1596 Move point to the beginning of the innermost C statement
1597 (@code{c-beginning-of-statement}). If point is already at the beginning
1598 of a statement, move to the beginning of the preceding statement. With
1599 prefix argument @var{n}, move back @var{n} @minus{} 1 statements.
1600
1601 In comments or in strings which span more than one line, this command
1602 moves by sentences instead of statements.
1603
1604 @item M-e
1605 @kindex M-e (C mode)
1606 @findex c-end-of-statement
1607 Move point to the end of the innermost C statement or sentence; like
1608 @kbd{M-a} except that it moves in the other direction
1609 (@code{c-end-of-statement}).
1610 @end table
1611
1612 @node Electric C
1613 @subsection Electric C Characters
1614
1615 In C mode and related modes, certain printing characters are
1616 @dfn{electric}---in addition to inserting themselves, they also
1617 reindent the current line, and optionally also insert newlines. The
1618 electric characters are @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#},
1619 @kbd{;}, @kbd{,}, @kbd{<}, @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and
1620 @kbd{)}.
1621
1622 You might find electric indentation inconvenient if you are editing
1623 chaotically indented code. If you are new to CC Mode, you might find
1624 it disconcerting. You can toggle electric action with the command
1625 @kbd{C-c C-l}; when it is enabled, @samp{/l} appears in the mode line
1626 after the mode name:
1627
1628 @table @kbd
1629 @item C-c C-l
1630 @kindex C-c C-l @r{(C mode)}
1631 @findex c-toggle-electric-state
1632 Toggle electric action (@code{c-toggle-electric-state}). With a
1633 positive prefix argument, this command enables electric action, with a
1634 negative one it disables it.
1635 @end table
1636
1637 Electric characters insert newlines only when, in addition to the
1638 electric state, the @dfn{auto-newline} feature is enabled (indicated
1639 by @samp{/la} in the mode line after the mode name). You can turn
1640 this feature on or off with the command @kbd{C-c C-a}:
1641
1642 @table @kbd
1643 @item C-c C-a
1644 @kindex C-c C-a @r{(C mode)}
1645 @findex c-toggle-auto-newline
1646 Toggle the auto-newline feature (@code{c-toggle-auto-newline}). With a
1647 prefix argument, this command turns the auto-newline feature on if the
1648 argument is positive, and off if it is negative.
1649 @end table
1650
1651 Usually the CC Mode style configures the exact circumstances in
1652 which Emacs inserts auto-newlines. You can also configure this
1653 directly. @xref{Custom Auto-newlines,,, ccmode, The CC Mode Manual}.
1654
1655 @node Hungry Delete
1656 @subsection Hungry Delete Feature in C
1657 @cindex hungry deletion (C Mode)
1658
1659 If you want to delete an entire block of whitespace at point, you
1660 can use @dfn{hungry deletion}. This deletes all the contiguous
1661 whitespace either before point or after point in a single operation.
1662 @dfn{Whitespace} here includes tabs and newlines, but not comments or
1663 preprocessor commands.
1664
1665 @table @kbd
1666 @item C-c C-@key{DEL}
1667 @itemx C-c @key{DEL}
1668 @findex c-hungry-delete-backwards
1669 @kindex C-c C-@key{DEL} (C Mode)
1670 @kindex C-c @key{DEL} (C Mode)
1671 Delete the entire block of whitespace preceding point (@code{c-hungry-delete-backwards}).
1672
1673 @item C-c C-d
1674 @itemx C-c C-@key{Delete}
1675 @itemx C-c @key{Delete}
1676 @findex c-hungry-delete-forward
1677 @kindex C-c C-d (C Mode)
1678 @kindex C-c C-@key{Delete} (C Mode)
1679 @kindex C-c @key{Delete} (C Mode)
1680 Delete the entire block of whitespace after point (@code{c-hungry-delete-forward}).
1681 @end table
1682
1683 As an alternative to the above commands, you can enable @dfn{hungry
1684 delete mode}. When this feature is enabled (indicated by @samp{/h} in
1685 the mode line after the mode name), a single @key{DEL} deletes all
1686 preceding whitespace, not just one space, and a single @kbd{C-d}
1687 (but @emph{not} plain @key{Delete}) deletes all following whitespace.
1688
1689 @table @kbd
1690 @item M-x c-toggle-hungry-state
1691 @findex c-toggle-hungry-state
1692 Toggle the hungry-delete feature
1693 (@code{c-toggle-hungry-state}). With a prefix argument,
1694 this command turns the hungry-delete feature on if the argument is
1695 positive, and off if it is negative.
1696 @end table
1697
1698 @vindex c-hungry-delete-key
1699 The variable @code{c-hungry-delete-key} controls whether the
1700 hungry-delete feature is enabled.
1701
1702 @node Other C Commands
1703 @subsection Other Commands for C Mode
1704
1705 @table @kbd
1706 @item M-x c-context-line-break
1707 @findex c-context-line-break
1708 This command inserts a line break and indents the new line in a manner
1709 appropriate to the context. In normal code, it does the work of
1710 @key{RET} (@code{newline}), in a C preprocessor line it additionally
1711 inserts a @samp{\} at the line break, and within comments it's like
1712 @kbd{M-j} (@code{c-indent-new-comment-line}).
1713
1714 @code{c-context-line-break} isn't bound to a key by default, but it
1715 needs a binding to be useful. The following code will bind it to
1716 @key{RET}. We use @code{c-initialization-hook} here to make sure
1717 the keymap is loaded before we try to change it.
1718
1719 @example
1720 (defun my-bind-clb ()
1721 (define-key c-mode-base-map "\C-m"
1722 'c-context-line-break))
1723 (add-hook 'c-initialization-hook 'my-bind-clb)
1724 @end example
1725
1726 @item C-M-h
1727 Put mark at the end of a function definition, and put point at the
1728 beginning (@code{c-mark-function}).
1729
1730 @item M-q
1731 @kindex M-q @r{(C mode)}
1732 @findex c-fill-paragraph
1733 Fill a paragraph, handling C and C++ comments (@code{c-fill-paragraph}).
1734 If any part of the current line is a comment or within a comment, this
1735 command fills the comment or the paragraph of it that point is in,
1736 preserving the comment indentation and comment delimiters.
1737
1738 @item C-c C-e
1739 @cindex macro expansion in C
1740 @cindex expansion of C macros
1741 @findex c-macro-expand
1742 @kindex C-c C-e @r{(C mode)}
1743 Run the C preprocessor on the text in the region, and show the result,
1744 which includes the expansion of all the macro calls
1745 (@code{c-macro-expand}). The buffer text before the region is also
1746 included in preprocessing, for the sake of macros defined there, but the
1747 output from this part isn't shown.
1748
1749 When you are debugging C code that uses macros, sometimes it is hard to
1750 figure out precisely how the macros expand. With this command, you
1751 don't have to figure it out; you can see the expansions.
1752
1753 @item C-c C-\
1754 @findex c-backslash-region
1755 @kindex C-c C-\ @r{(C mode)}
1756 Insert or align @samp{\} characters at the ends of the lines of the
1757 region (@code{c-backslash-region}). This is useful after writing or
1758 editing a C macro definition.
1759
1760 If a line already ends in @samp{\}, this command adjusts the amount of
1761 whitespace before it. Otherwise, it inserts a new @samp{\}. However,
1762 the last line in the region is treated specially; no @samp{\} is
1763 inserted on that line, and any @samp{\} there is deleted.
1764
1765 @item M-x cpp-highlight-buffer
1766 @cindex preprocessor highlighting
1767 @findex cpp-highlight-buffer
1768 Highlight parts of the text according to its preprocessor conditionals.
1769 This command displays another buffer named @file{*CPP Edit*}, which
1770 serves as a graphic menu for selecting how to display particular kinds
1771 of conditionals and their contents. After changing various settings,
1772 click on @samp{[A]pply these settings} (or go to that buffer and type
1773 @kbd{a}) to rehighlight the C mode buffer accordingly.
1774
1775 @item C-c C-s
1776 @findex c-show-syntactic-information
1777 @kindex C-c C-s @r{(C mode)}
1778 Display the syntactic information about the current source line
1779 (@code{c-show-syntactic-information}). This information directs how
1780 the line is indented.
1781
1782 @item M-x cwarn-mode
1783 @itemx M-x global-cwarn-mode
1784 @findex cwarn-mode
1785 @findex global-cwarn-mode
1786 @vindex global-cwarn-mode
1787 @cindex CWarn mode
1788 @cindex suspicious constructions in C, C++
1789 CWarn minor mode highlights certain suspicious C and C++ constructions:
1790
1791 @itemize @bullet{}
1792 @item
1793 Assignments inside expressions.
1794 @item
1795 Semicolon following immediately after @samp{if}, @samp{for}, and @samp{while}
1796 (except after a @samp{do @dots{} while} statement);
1797 @item
1798 C++ functions with reference parameters.
1799 @end itemize
1800
1801 @noindent
1802 You can enable the mode for one buffer with the command @kbd{M-x
1803 cwarn-mode}, or for all suitable buffers with the command @kbd{M-x
1804 global-cwarn-mode} or by customizing the variable
1805 @code{global-cwarn-mode}. You must also enable Font Lock mode to make
1806 it work.
1807
1808 @item M-x hide-ifdef-mode
1809 @findex hide-ifdef-mode
1810 @cindex Hide-ifdef mode
1811 @vindex hide-ifdef-shadow
1812 Hide-ifdef minor mode hides selected code within @samp{#if} and
1813 @samp{#ifdef} preprocessor blocks. If you change the variable
1814 @code{hide-ifdef-shadow} to @code{t}, Hide-ifdef minor mode
1815 shadows preprocessor blocks by displaying them with a less
1816 prominent face, instead of hiding them entirely. See the
1817 documentation string of @code{hide-ifdef-mode} for more information.
1818
1819 @item M-x ff-find-related-file
1820 @cindex related files
1821 @findex ff-find-related-file
1822 @vindex ff-related-file-alist
1823 Find a file related in a special way to the file visited by the
1824 current buffer. Typically this will be the header file corresponding
1825 to a C/C++ source file, or vice versa. The variable
1826 @code{ff-related-file-alist} specifies how to compute related file
1827 names.
1828 @end table
1829
1830 @node Asm Mode
1831 @section Asm Mode
1832
1833 @cindex Asm mode
1834 @cindex assembler mode
1835 Asm mode is a major mode for editing files of assembler code. It
1836 defines these commands:
1837
1838 @table @kbd
1839 @item @key{TAB}
1840 @code{tab-to-tab-stop}.
1841 @c FIXME: Maybe this should be consistent with other programming modes.
1842 @item C-j
1843 Insert a newline and then indent using @code{tab-to-tab-stop}.
1844 @item :
1845 Insert a colon and then remove the indentation from before the label
1846 preceding colon. Then do @code{tab-to-tab-stop}.
1847 @item ;
1848 Insert or align a comment.
1849 @end table
1850
1851 The variable @code{asm-comment-char} specifies which character
1852 starts comments in assembler syntax.
1853
1854 @ifnottex
1855 @include fortran-xtra.texi
1856 @end ifnottex