aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2001-06-26 13:43:32 +0000
committerRichard M. Stallman2001-06-26 13:43:32 +0000
commit93da5dfff0fd64863ea6d3e56c8338f503799c25 (patch)
treedbe36f0de5c9fc29728973e1aff70566be2a421c
parentebe19e1b1c25d2b50342e517a08a6dd1219b5e69 (diff)
downloademacs-93da5dfff0fd64863ea6d3e56c8338f503799c25.tar.gz
emacs-93da5dfff0fd64863ea6d3e56c8338f503799c25.zip
Major rewrite. Sections Tags, Emerge, Change Log and Authors
moved to maintaining.texi. Some sections reordered. Node Misc for Programs moved to just before the language-specific sections. New node Defuns contains an intro plus the old Defuns node (now renamed Moving by Defuns) as well as Imenu, Which Function, and a node Left Margin Paren to explain the convention about this. New node Parentheses now documents M-x check-parens. It contains subnodes Expressions, Moving by Parens, and Matching. Expressions and Moving by Parens contain the material formerly in Lists and List Commands, but divided up differently. The section Balanced Editing has been deleted. Most of the C indentation customization (all except c-set-style), has been replaced with a reference to the C Modes manual. Documentation now is divided into three subsections. Some rewrites in the Program Indent section about C-u TAB and C-M-q.
-rw-r--r--man/programs.texi2957
1 files changed, 647 insertions, 2310 deletions
diff --git a/man/programs.texi b/man/programs.texi
index 7ea7960177b..2787a07bf95 100644
--- a/man/programs.texi
+++ b/man/programs.texi
@@ -1,5 +1,5 @@
1@c This is part of the Emacs manual. 1@c This is part of the Emacs manual.
2@c Copyright (C) 1985,86,87,93,94,95,97,99,2000 Free Software Foundation, Inc. 2@c Copyright (C) 1985,86,87,93,94,95,97,99,00,2001 Free Software Foundation, Inc.
3@c See file emacs.texi for copying conditions. 3@c See file emacs.texi for copying conditions.
4@node Programs, Building, Text, Top 4@node Programs, Building, Text, Top
5@chapter Editing Programs 5@chapter Editing Programs
@@ -12,77 +12,36 @@ features can:
12 12
13@itemize @bullet 13@itemize @bullet
14@item 14@item
15Move over or kill balanced expressions (@pxref{Lists}). 15Find or move over top-level definitions (@pxref{Defuns}).
16@item 16@item
17Move over or mark top-level expressions, such as @dfn{defuns} in 17Apply the usual indentation conventions of the language
18Lisp, or function definitions in C (@pxref{Defuns}). 18(@pxref{Program Indent}).
19@item
20Show how parentheses balance (@pxref{Matching}).
21@item 19@item
22Insert, kill or align comments (@pxref{Comments}). 20Insert, kill or align comments (@pxref{Comments}).
23@item 21@item
24Follow the usual indentation conventions of the language 22Balance parentheses (@pxref{Parentheses}).
25(@pxref{Program Indent}).
26@item 23@item
27Highlight program syntax (@pxref{Font Lock}). 24Highlight program syntax (@pxref{Font Lock}).
28@item
29Compile and debug programs (@pxref{Building}).
30@end itemize 25@end itemize
31 26
32@menu 27@menu
33* Misc for Programs:: Other Emacs features useful for editing programs.
34* Program Modes:: Major modes for editing programs. 28* Program Modes:: Major modes for editing programs.
35* Lists:: Expressions with balanced parentheses. 29* Defuns:: Commands to operate on major top-level parts
36* List Commands:: The commands for working with list and sexps. 30 of a program.
37* Defuns:: Each program is made up of separate functions.
38 There are editing commands to operate on them.
39* Program Indent:: Adjusting indentation to show the nesting. 31* Program Indent:: Adjusting indentation to show the nesting.
40* Matching:: Insertion of a close-delimiter flashes matching open.
41* Comments:: Inserting, killing, and aligning comments. 32* Comments:: Inserting, killing, and aligning comments.
42* Balanced Editing:: Inserting two matching parentheses at once, etc. 33* Parentheses:: Commands that operate on parentheses.
43* Symbol Completion:: Completion on symbol names of your program or language. 34* Documentation:: Getting documentation of functions you plan to call.
44* Which Function:: Which Function mode shows which function you are in.
45* Hideshow:: Displaying blocks selectively. 35* Hideshow:: Displaying blocks selectively.
36* Symbol Completion:: Completion on symbol names of your program or language.
46* Glasses:: Making identifiersLikeThis more readable. 37* Glasses:: Making identifiersLikeThis more readable.
47* Documentation:: Getting documentation of functions you plan to call. 38* Misc for Programs:: Other Emacs features useful for editing programs.
48* Change Log:: Maintaining a change history for your program.
49* Authors:: Maintaining an @file{AUTHORS} file.
50* Tags:: Go direct to any function in your program in one
51 command. Tags remembers which file it is in.
52* Imenu:: Making buffer indexes as menus.
53* Emerge:: A convenient way of merging two versions of a program.
54* C Modes:: Special commands of C, C++, Objective-C, 39* C Modes:: Special commands of C, C++, Objective-C,
55 Java, and Pike modes. 40 Java, and Pike modes.
56* Fortran:: Fortran mode and its special features. 41* Fortran:: Fortran mode and its special features.
57* Asm Mode:: Asm mode and its special features. 42* Asm Mode:: Asm mode and its special features.
58@end menu 43@end menu
59 44
60@node Misc for Programs
61@section Other Features Useful for Editing Programs
62
63 A number of Emacs commands that aren't designed specifically for
64editing programs are useful for it nonetheless.
65
66 The Emacs commands that operate on words, sentences and paragraphs
67are useful for editing code. Most symbols names contain words
68(@pxref{Words}); sentences can be found in strings and comments
69(@pxref{Sentences}). Paragraphs in the strict sense may be found in
70program code (in long comments), but the paragraph commands are useful
71in other places too, because programming language major modes define
72paragraphs to begin and end at blank lines (@pxref{Paragraphs}).
73Judicious use of blank lines to make the program clearer will also
74provide useful chunks of text for the paragraph commands to work on.
75
76 The selective display feature is useful for looking at the overall
77structure of a function (@pxref{Selective Display}). This feature
78hides the lines that are indented more than a specified amount.
79Programming modes often support Outline minor mode (@pxref{Outline
80Mode}). The Foldout package provides folding-editor features
81(@pxref{Foldout}).
82
83 The ``automatic typing'' features may be useful for writing programs.
84@xref{Top,,Autotyping, autotype, Autotyping}.
85
86@node Program Modes 45@node Program Modes
87@section Major Modes for Programming Languages 46@section Major Modes for Programming Languages
88@cindex modes for programming languages 47@cindex modes for programming languages
@@ -124,7 +83,7 @@ variant of Lisp) and the Scheme-based DSSSL expression language, Ada,
124Awk, C, C++, Delphi (Object Pascal), Fortran (free format and fixed 83Awk, C, C++, Delphi (Object Pascal), Fortran (free format and fixed
125format), Icon, IDL (CORBA), IDLWAVE, Java, Metafont (@TeX{}'s 84format), Icon, IDL (CORBA), IDLWAVE, Java, Metafont (@TeX{}'s
126companion for font creation), Modula2, Objective-C, Octave, Pascal, 85companion for font creation), Modula2, Objective-C, Octave, Pascal,
127Perl, Pike, PostScript, Prolog, Simula, and Tcl, and VHDL. There is 86Perl, Pike, PostScript, Prolog, Simula, Tcl, and VHDL. There is
128also a major mode for makefiles, called Makefile mode. An alternative 87also a major mode for makefiles, called Makefile mode. An alternative
129mode for Perl is called CPerl mode. Modes are available for the 88mode for Perl is called CPerl mode. Modes are available for the
130scripting languages of the common Unix shells, VMS DCL, and 89scripting languages of the common Unix shells, VMS DCL, and
@@ -133,17 +92,14 @@ editing various sorts of configuration files.
133 92
134@kindex DEL @r{(programming modes)} 93@kindex DEL @r{(programming modes)}
135@findex c-electric-backspace 94@findex c-electric-backspace
136 In most programming languages, indentation is likely to vary from 95 In most programming languages, indentation should vary from line to
137line to line. So the major modes for those languages rebind @key{DEL} 96line to illustrate the structure of the program. So the major modes
138to treat a tab as if it were the equivalent number of spaces. This 97for program languages arrange for @key{TAB} to update the indentation
139makes it possible to reduce indentation one column at a time without 98of the current line. They also rebind @key{DEL} to treat a tab as if
140worrying whether it is made up of spaces or tabs. Use @kbd{C-b C-d} 99it were the equivalent number of spaces. This makes it possible to
141to delete a tab character before point, in these modes. 100reduce indentation one column at a time without worrying whether it is
142 101made up of spaces or tabs. Use @kbd{C-b C-d} to delete a tab
143 Programming language modes define paragraphs to be separated only by 102character before point, in these modes.
144blank lines, so that the paragraph commands remain useful. Auto Fill mode,
145if enabled in a programming language major mode, indents the new lines
146which it creates.
147 103
148 Separate manuals are available for the modes for Ada (@pxref{Top, , Ada 104 Separate manuals are available for the modes for Ada (@pxref{Top, , Ada
149Mode, ada-mode, Ada Mode}), C/C++/Objective C/Java/Corba IDL 105Mode, ada-mode, Ada Mode}), C/C++/Objective C/Java/Corba IDL
@@ -163,184 +119,82 @@ adding @samp{-hook}. For example, turning on C mode runs the hook
163@code{c-mode-hook}, while turning on Lisp mode runs the hook 119@code{c-mode-hook}, while turning on Lisp mode runs the hook
164@code{lisp-mode-hook}. @xref{Hooks}. 120@code{lisp-mode-hook}. @xref{Hooks}.
165 121
166@node Lists 122@node Defuns
167@section Lists and Sexps 123@section Top-Level Definitions, or Defuns
168
169@cindex Control-Meta
170 By convention, Emacs keys for dealing with balanced expressions are
171Control-Meta characters. They act like the corresponding Control and
172Meta equivalents, except that they operate on balanced expressions
173instead of on characters or words. For instance, the command
174@kbd{C-M-b} moves backward over a balanced expression, just as
175@kbd{C-b} moves back over a character and @kbd{M-b} moves back over a
176word. These commands are intended for expressions in programming
177languages, but can be useful for editing any text that has
178parentheses.
179
180@cindex list
181@cindex sexp
182@cindex expression
183 These commands fall into two classes. Some deal only with @dfn{lists}
184(parenthetical groupings). They see nothing except parentheses, brackets,
185braces (whichever ones must balance in the language you are working with),
186and escape characters that might be used to quote those.
187
188 The other commands deal with expressions or @dfn{sexps}. The word ``sexp''
189is derived from @dfn{s-expression}, the ancient term for an expression in
190Lisp. But in Emacs, the notion of ``sexp'' is not limited to Lisp. It
191refers to an expression in whatever language your program is written in.
192Each programming language has its own major mode, which customizes the
193syntax tables so that expressions in that language count as sexps.
194
195 Sexps typically include symbols, numbers, and string constants, as well
196as anything contained in parentheses, brackets or braces.
197
198 In languages that use prefix and infix operators, such as C, it is not
199possible for all expressions to be sexps. For example, C mode does not
200recognize @samp{foo + bar} as a sexp, even though it @emph{is} a C expression;
201it recognizes @samp{foo} as one sexp and @samp{bar} as another, with the
202@samp{+} as punctuation between them. This is a fundamental ambiguity:
203both @samp{foo + bar} and @samp{foo} are legitimate choices for the sexp to
204move over if point is at the @samp{f}. Note that @samp{(foo + bar)} is a
205single sexp in C mode.
206
207 Some languages have obscure forms of expression syntax that nobody
208has bothered to make Emacs understand properly.
209
210@node List Commands
211@section List And Sexp Commands
212
213@c doublewidecommands
214@table @kbd
215@item C-M-f
216Move forward over a sexp (@code{forward-sexp}).
217@item C-M-b
218Move backward over a sexp (@code{backward-sexp}).
219@item C-M-k
220Kill sexp forward (@code{kill-sexp}).
221@item C-M-@key{DEL}
222Kill sexp backward (@code{backward-kill-sexp}).
223@item C-M-u
224Move up and backward in list structure (@code{backward-up-list}).
225@item C-M-d
226Move down and forward in list structure (@code{down-list}).
227@item C-M-n
228Move forward over a list (@code{forward-list}).
229@item C-M-p
230Move backward over a list (@code{backward-list}).
231@item C-M-t
232Transpose expressions (@code{transpose-sexps}).
233@item C-M-@@
234Put mark after following expression (@code{mark-sexp}).
235@end table
236
237@cindex parentheses, moving across
238@cindex matching parenthesis and braces, moving to
239@cindex braces, moving across
240@kindex C-M-f
241@kindex C-M-b
242@findex forward-sexp
243@findex backward-sexp
244 To move forward over a sexp, use @kbd{C-M-f} (@code{forward-sexp}). If
245the first significant character after point is an opening delimiter
246(@samp{(} in Lisp; @samp{(}, @samp{[} or @samp{@{} in C), @kbd{C-M-f}
247moves past the matching closing delimiter. If the character begins a
248symbol, string, or number, @kbd{C-M-f} moves over that.
249
250 The command @kbd{C-M-b} (@code{backward-sexp}) moves backward over a
251sexp. The detailed rules are like those above for @kbd{C-M-f}, but with
252directions reversed. If there are any prefix characters (single-quote,
253backquote and comma, in Lisp) preceding the sexp, @kbd{C-M-b} moves back
254over them as well. The sexp commands move across comments as if they
255were whitespace in most modes.
256 124
257 @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation the 125 In Emacs, a major definition at the top level in the buffer is
258specified number of times; with a negative argument, it moves in the 126called a @dfn{defun}. The name comes from Lisp, but in Emacs we use
259opposite direction. 127it for all languages.
260 128
261@cindex deleting parenthesized expressions 129 In most programming language modes, Emacs assumes that a defun is
262@kindex C-M-k 130any pair of parentheses (or braces, if the language uses braces this
263@findex kill-sexp 131way) that starts at the left margin. For example, in C, the body of a
264@kindex C-M-DEL 132function definition is normally a defun, because the open-brace that
265@findex backward-kill-sexp 133begins it is normally at the left margin. A variable's initializer
266 Killing a whole sexp can be done with @kbd{C-M-k} (@code{kill-sexp}) 134can also count as a defun, if the open-brace that begins the
267or @kbd{C-M-@key{DEL}} (@code{backward-kill-sexp}). @kbd{C-M-k} kills 135initializer is at the left margin.
268the characters that @kbd{C-M-f} would move over, and @kbd{C-M-@key{DEL}}
269kills the characters that @kbd{C-M-b} would move over.
270 136
271@kindex C-M-n 137 However, some language modes provide their own code for recognizing
272@kindex C-M-p 138defuns in a way that suits the language syntax and conventions better.
273@findex forward-list
274@findex backward-list
275 The @dfn{list commands} move over lists, as the sexp commands do, but skip
276blithely over any number of other kinds of sexps (symbols, strings, etc.).
277They are @kbd{C-M-n} (@code{forward-list}) and @kbd{C-M-p}
278(@code{backward-list}). The main reason they are useful is that they
279usually ignore comments (since the comments usually do not contain any
280lists).@refill
281 139
282@kindex C-M-u 140@menu
283@kindex C-M-d 141* Left Margin Paren:: An open-paren or similar opening delimiter
284@findex backward-up-list 142 starts a defun if it is at the left margin.
285@findex down-list 143* Moving by Defuns:: Commands to move over or mark a major definition.
286 @kbd{C-M-n} and @kbd{C-M-p} stay at the same level in parentheses, when 144* Imenu:: Making buffer indexes as menus.
287that's possible. To move @emph{up} one (or @var{n}) levels, use @kbd{C-M-u} 145* Which Function:: Which Function mode shows which function you are in.
288(@code{backward-up-list}). 146@end menu
289@kbd{C-M-u} moves backward up past one unmatched opening delimiter. A
290positive argument serves as a repeat count; a negative argument reverses
291direction of motion and also requests repetition, so it moves forward and
292up one or more levels.@refill
293
294 To move @emph{down} in list structure, use @kbd{C-M-d}
295(@code{down-list}). In Lisp mode, where @samp{(} is the only opening
296delimiter, this is nearly the same as searching for a @samp{(}. An
297argument specifies the number of levels of parentheses to go down.
298 147
299@cindex transposition of parenthesized expressions 148@node Left Margin Paren
300@kindex C-M-t 149@subsection Left Margin Convention
301@findex transpose-sexps
302 A somewhat random-sounding command which is nevertheless handy is
303@kbd{C-M-t} (@code{transpose-sexps}), which drags the previous sexp
304across the next one. An argument serves as a repeat count, and a
305negative argument drags backwards (thus canceling out the effect of
306@kbd{C-M-t} with a positive argument). An argument of zero, rather than
307doing nothing, transposes the sexps ending after point and the mark.
308 150
309@kindex C-M-@@ 151@cindex open-parenthesis in leftmost column
310@findex mark-sexp 152@cindex ( in leftmost column
311 To set the region around the next sexp in the buffer, use @kbd{C-M-@@} 153 In most major modes, Emacs assumes that any opening delimiter found
312(@code{mark-sexp}), which sets mark at the same place that @kbd{C-M-f} 154at the left margin is the start of a top-level definition, or defun.
313would move to. @kbd{C-M-@@} takes arguments like @kbd{C-M-f}. In 155Therefore, @strong{never put an opening delimiter at the left margin
314particular, a negative argument is useful for putting the mark at the 156unless it should have that significance.} For instance, never put an
315beginning of the previous sexp. 157open-parenthesis at the left margin in a Lisp file unless it is the
158start of a top-level list. Never put an open-brace or other opening
159delimiter at the beginning of a line of C code unless it is at top
160level.
161
162 If you don't follow this convention, not only will you have trouble
163when you explicitly use the commands for motion by defuns; other
164features that use them will also give you trouble. This includes
165the indentation commands (@pxref{Program Indent}) and Font Lock
166mode (@pxref{Font Lock}).
167
168 The most likely problem case is when you want an opening delimiter
169at the start of a line inside a string. To avoid trouble, put an
170escape character (@samp{\}, in C and Emacs Lisp, @samp{/} in some
171other Lisp dialects) before the opening delimiter. This will not
172affect the contents of the string, but will prevent that opening
173delimiter from starting a defun. Here's an example:
316 174
317 The list and sexp commands' understanding of syntax is completely 175@example
318controlled by the syntax table. Any character can, for example, be 176 (insert "Foo:
319declared to be an opening delimiter and act like an open parenthesis. 177\(bar)
320@xref{Syntax}. 178")
179@end example
321 180
322@node Defuns 181 In the earliest days, the original Emacs found defuns by moving
323@section Defuns 182upward a level of parentheses or braces until there were no more
183levels to go up. This always required scanning all the way back to
184the beginning of the buffer, even for a small function. To speed up
185the operation, we changed Emacs to assume that any opening delimiter
186at the left margin is the start of a defun. This heuristic is nearly
187always right, and avoids the need to scan back to the beginning of the
188buffer. However, it mandates following the convention described
189above.
190
191@node Moving by Defuns
192@subsection Moving by Defuns
324@cindex defuns 193@cindex defuns
325 194
326 In Emacs, a parenthetical grouping at the top level in the buffer is 195 These commands move point or set up the region based on top-level
327called a @dfn{defun}. The name derives from the fact that most top-level 196major definitions, also called @dfn{defuns}.
328lists in a Lisp file are instances of the special form @code{defun}, but
329any top-level parenthetical grouping counts as a defun in Emacs parlance
330regardless of what its contents are, and regardless of the programming
331language in use. For example, in C, the body of a function definition is a
332defun.
333
334 197
335@cindex move to beginning or end of function
336@cindex function, move to beginning or end
337@kindex C-M-a
338@kindex C-M-e
339@kindex C-M-h
340@findex beginning-of-defun
341@findex end-of-defun
342@findex mark-defun
343@c doublewidecommands
344@table @kbd 198@table @kbd
345@item C-M-a 199@item C-M-a
346Move to beginning of current or preceding defun 200Move to beginning of current or preceding defun
@@ -369,43 +223,91 @@ the direction of motion.
369@var{n} times to the next beginning of a defun. This is not exactly 223@var{n} times to the next beginning of a defun. This is not exactly
370the same place that @kbd{C-M-e} with argument @var{n} would move to; 224the same place that @kbd{C-M-e} with argument @var{n} would move to;
371the end of this defun is not usually exactly the same place as the 225the end of this defun is not usually exactly the same place as the
372beginning of the following defun. (Typically whitespace or comments 226beginning of the following defun. (Whitespace, comments, and perhaps
373separate them.) Likewise, @kbd{C-M-e} with a negative argument moves 227declarations can separate them.) Likewise, @kbd{C-M-e} with a
374back to an end of a defun, which is not quite the same as @kbd{C-M-a} 228negative argument moves back to an end of a defun, which is not quite
375with a positive argument. 229the same as @kbd{C-M-a} with a positive argument.
376 230
377@kindex C-M-h @r{(C mode)} 231@kindex C-M-h @r{(C mode)}
378@findex c-mark-function 232@findex c-mark-function
379 If you wish to operate on the current defun, use @kbd{C-M-h} 233 To operate on the current defun, use @kbd{C-M-h} (@code{mark-defun})
380(@code{mark-defun}) which puts point at the beginning and mark at the end 234which puts point at the beginning and mark at the end of the current
381of the current or next defun. For example, this is the easiest way to get 235or next defun. this is the easiest way to get ready to kill the defun
382ready to move the defun to a different place in the text. In C mode, 236in order move it to a different place in the file.
383@kbd{C-M-h} runs the function @code{c-mark-function}, which is almost the 237
384same as @code{mark-defun}; the difference is that it backs up over the 238 In C mode, @kbd{C-M-h} runs the function @code{c-mark-function},
385argument declarations, function name and returned data type so that the 239which is almost the same as @code{mark-defun}; the difference is that
386entire C function is inside the region. @xref{Marking Objects}. 240it backs up over the argument declarations, function name and returned
241data type so that the entire C function is inside the region.
242@xref{Marking Objects}. This is an example of how major modes adjust
243the standard key bindings so that they do their standard jobs in a way
244better fitting a particular language. Other major modes may adjust
245any or all of these key bindings for that purpose.
387 246
388@cindex open-parenthesis in leftmost column 247@node Imenu
389@cindex ( in leftmost column 248@subsection Imenu
390 Emacs assumes that any open-parenthesis found in the leftmost column 249@cindex indexes of buffer contents
391is the start of a defun. Therefore, @strong{never put an 250@cindex buffer content indexes
392open-parenthesis at the left margin in a Lisp file unless it is the 251@cindex tags
393start of a top-level list. Never put an open-brace or other opening 252
394delimiter at the beginning of a line of C code unless it starts the body 253 The Imenu facility offers a way to find the definitions or sections
395of a function.} The most likely problem case is when you want an 254in a file.
396opening delimiter at the start of a line inside a string. To avoid 255
397trouble, put an escape character (@samp{\}, in C and Emacs Lisp, 256@findex imenu
398@samp{/} in some other Lisp dialects) before the opening delimiter. It 257@findex imenu-add-menu-bar-index
399will not affect the contents of the string. 258 If you type @kbd{M-x imenu}, it reads the name of a section or
400 259definition in the current buffer, then goes to that section or
401 In the remotest past, the original Emacs found defuns by moving upward a 260definition. You can use completion to specify the name, and a
402level of parentheses until there were no more levels to go up. This always 261complete list of possible names is always displayed.
403required scanning all the way back to the beginning of the buffer, even for 262
404a small function. To speed up the operation, Emacs was changed to assume 263 Alternatively you can bind the command @code{imenu} to a mouse
405that any @samp{(} (or other character assigned the syntactic class of 264click. Then it displays mouse menus for you to select the section or
406opening-delimiter) at the left margin is the start of a defun. This 265definition you want. You can also add the buffer's index to the menu
407heuristic is nearly always right and avoids the costly scan; however, 266bar by calling @code{imenu-add-menu-bar-index}. If you want to have
408it mandates the convention described above. 267this menu bar item available for all buffers in a certain major mode,
268you can do this by adding @code{imenu-add-menu-bar-index} to its mode
269hook. But then you will have to wait for the buffer to be searched
270for sections and definitions, each time you visit a file which uses
271that mode.
272
273@vindex imenu-auto-rescan
274 When you change the contents of a buffer, if you add or delete
275definitions or sections, you can update the buffer's index to
276correspond to the new contents by invoking the @samp{*Rescan*} item in
277the menu. Rescanning happens automatically if
278@code{imenu-auto-rescan} is non-@code{nil}. There is no need to
279rescan because of small changes in the text.
280
281@vindex imenu-sort-function
282 You can customize the way the menus are sorted via the variable
283@code{imenu-sort-function}. By default names are ordered as they
284occur in the buffer; alphabetic sorting is provided as an alternative.
285
286 Imenu provides the information to guide Which Function mode
287@ifnottex
288(@pxref{Which Function}).
289@end ifnottex
290@iftex
291(see below).
292@end iftex
293The Speedbar can also use it (@pxref{Speedbar}).
294
295@node Which Function
296@subsection Which Function Mode
297
298 Which Function mode is a minor mode that displays the current
299function name in the mode line, updating it as you move around in a
300buffer.
301
302@findex which-function-mode
303@vindex which-func-modes
304 To enable (or disable) Which Function mode, use the command @kbd{M-x
305which-function-mode}. This command is global; it applies to all
306buffers, both existing ones and those yet to be created. However, this
307only affects certain major modes, those listed in the value of
308@code{which-func-modes}. If the value is @code{t}, then Which Function
309mode applies to all major modes that know how to support it---which are
310the major modes that support Imenu.
409 311
410@node Program Indent 312@node Program Indent
411@section Indentation for Programs 313@section Indentation for Programs
@@ -435,7 +337,6 @@ according to the usual conventions of the language you are editing.
435@kbd{C-j} is normally defined to do @key{RET} followed by @key{TAB}; 337@kbd{C-j} is normally defined to do @key{RET} followed by @key{TAB};
436thus, it too indents in a mode-specific fashion. 338thus, it too indents in a mode-specific fashion.
437 339
438@c WideCommands
439@table @kbd 340@table @kbd
440@item @key{TAB} 341@item @key{TAB}
441Adjust indentation of current line. 342Adjust indentation of current line.
@@ -481,8 +382,8 @@ at the left margin is assumed by Emacs (including the indentation routines)
481to be the start of a function. Therefore, you must never have an opening 382to be the start of a function. Therefore, you must never have an opening
482delimiter in column zero that is not the beginning of a function, not even 383delimiter in column zero that is not the beginning of a function, not even
483inside a string. This restriction is vital for making the indentation 384inside a string. This restriction is vital for making the indentation
484commands fast; you must simply accept it. @xref{Defuns}, for more 385commands fast; you must simply accept it. @xref{Left Margin Paren},
485information on this. 386for more information on this.
486 387
487 Normally, lines are indented with tabs and spaces. If you want Emacs 388 Normally, lines are indented with tabs and spaces. If you want Emacs
488to use spaces only, see @ref{Just Spaces}. 389to use spaces only, see @ref{Just Spaces}.
@@ -490,16 +391,16 @@ to use spaces only, see @ref{Just Spaces}.
490@node Multi-line Indent 391@node Multi-line Indent
491@subsection Indenting Several Lines 392@subsection Indenting Several Lines
492 393
493 When you wish to reindent several lines of code which have been altered 394 When you wish to reindent several lines of code which have been
494or moved to a different level in the list structure, you have several 395altered or moved to a different level in the parenthesis structure,
495commands available. 396you have several commands available.
496 397
497@table @kbd 398@table @kbd
498@item C-M-q 399@item C-M-q
499Reindent all the lines within one list (@code{indent-sexp}). 400Reindent all the lines within one parenthetical grouping(@code{indent-sexp}).
500@item C-u @key{TAB} 401@item C-u @key{TAB}
501Shift an entire list rigidly sideways so that its first line 402Shift an entire parenthetical grouping rigidly sideways so that its
502is properly indented. 403first line is properly indented.
503@item C-M-\ 404@item C-M-\
504Reindent all lines in the region (@code{indent-region}). 405Reindent all lines in the region (@code{indent-region}).
505@item M-x indent-code-rigidly 406@item M-x indent-code-rigidly
@@ -509,23 +410,22 @@ lines that start inside comments and strings.
509 410
510@kindex C-M-q 411@kindex C-M-q
511@findex indent-sexp 412@findex indent-sexp
512 You can reindent the contents of a single list by positioning point 413 You can reindent the contents of a single parenthetical grouping by
513before the beginning of it and typing @kbd{C-M-q} (@code{indent-sexp} in 414positioning point before the beginning of it and typing @kbd{C-M-q}
514Lisp mode, @code{c-indent-exp} in C mode; also bound to other suitable 415(@code{indent-sexp} in Lisp mode, @code{c-indent-exp} in C mode; also
515commands in other modes). The indentation of the line the sexp starts on 416bound to other suitable commands in other modes). The indentation of
516is not changed; therefore, only the relative indentation within the list, 417the line where the grouping starts is not changed; therefore, this
517and not its position, is changed. To correct the position as well, type a 418changes only the relative indentation within the grouping, not its
518@key{TAB} before the @kbd{C-M-q}. 419overall indentation. To correct that as well, type @key{TAB} first.
519 420
520@kindex C-u TAB 421@kindex C-u TAB
521 If the relative indentation within a list is correct but the 422 If you like the relative indentation within a grouping, but not the
522indentation of its first line is not, go to that line and type @kbd{C-u 423indentation of its first line, you can type @kbd{C-u @key{TAB}} to
523@key{TAB}}. @key{TAB} with a numeric argument reindents the current 424reindent the whole grouping as a rigid unit. @key{TAB} with a numeric
524line as usual, then reindents by the same amount all the lines in the 425argument reindents the current line as usual, then reindents by the
525grouping starting on the current line. In other words, it reindents the 426same amount all the lines in the parenthetical grouping starting on
526whole grouping rigidly as a unit. It is clever, though, and does not 427the current line. It is clever, though, and does not alter lines that
527alter lines that start inside strings, or C preprocessor lines when in C 428start inside strings, or C preprocessor lines when in C mode.
528mode.
529 429
530@findex indent-code-rigidly 430@findex indent-code-rigidly
531 Another way to specify the range to be reindented is with the region. 431 Another way to specify the range to be reindented is with the region.
@@ -534,7 +434,7 @@ every line whose first character is between point and mark. The command
534@kbd{M-x indent-code-rigidly} rigidly shifts all the lines in the region 434@kbd{M-x indent-code-rigidly} rigidly shifts all the lines in the region
535sideways, like @code{indent-rigidly} does (@pxref{Indentation 435sideways, like @code{indent-rigidly} does (@pxref{Indentation
536Commands}), except that it doesn't alter the indentation of lines that 436Commands}), except that it doesn't alter the indentation of lines that
537start inside comments and strings, unless the region starts inside that 437start inside a comment or a string, unless the region starts inside that
538comment or string. 438comment or string.
539 439
540@node Lisp Indent 440@node Lisp Indent
@@ -612,7 +512,7 @@ lines until the end of the list.
612@node C Indent 512@node C Indent
613@subsection Commands for C Indentation 513@subsection Commands for C Indentation
614 514
615 Here are the commands for indentation in C mode and related modes: 515 Here are special features for indentation in C mode and related modes:
616 516
617@table @code 517@table @code
618@item C-c C-q 518@item C-c C-q
@@ -644,11 +544,6 @@ if @code{indent-tabs-mode} is @code{nil}).
644Any other value (not @code{nil} or @code{t}) means always reindent the 544Any other value (not @code{nil} or @code{t}) means always reindent the
645line, and also insert a tab if within a comment, a string, or a 545line, and also insert a tab if within a comment, a string, or a
646preprocessor directive. 546preprocessor directive.
647
648@item C-u @key{TAB}
649Reindent the current line according to its syntax; also rigidly reindent
650any other lines of the expression that starts on the current line.
651@xref{Multi-line Indent}.
652@end table 547@end table
653 548
654 To reindent the whole current buffer, type @kbd{C-x h C-M-\}. This 549 To reindent the whole current buffer, type @kbd{C-x h C-M-\}. This
@@ -660,515 +555,37 @@ to the front of the block and then reindents it all.
660 555
661@node Custom C Indent 556@node Custom C Indent
662@subsection Customizing C Indentation 557@subsection Customizing C Indentation
558@cindex style (for indentation)
663 559
664 C mode and related modes use a simple yet flexible mechanism for 560 C mode and related modes use a simple yet flexible mechanism for
665customizing indentation. The mechanism works in two steps: first it 561customizing indentation. The mechanism works in two steps: first it
666classifies the line syntactically according to its contents and context; 562classifies the line syntactically according to its contents and context;
667second, it associates each kind of syntactic construct with an 563second, it associates each kind of syntactic construct with an
668indentation offset which you can customize. 564indentation offset based on your selected @dfn{style}.
669
670@menu
671* Syntactic Analysis::
672* Indentation Calculation::
673* Changing Indent Style::
674* Syntactic Symbols::
675* Variables for C Indent::
676* C Indent Styles::
677@end menu
678
679@node Syntactic Analysis
680@subsubsection Step 1---Syntactic Analysis
681@cindex syntactic analysis
682
683 In the first step, the C indentation mechanism looks at the line
684before the one you are currently indenting and determines the syntactic
685components of the construct on that line. It builds a list of these
686syntactic components, each of which contains a @dfn{syntactic symbol}
687and sometimes also a buffer position. Some syntactic symbols describe
688grammatical elements, for example @code{statement} and
689@code{substatement}; others describe locations amidst grammatical
690elements, for example @code{class-open} and @code{knr-argdecl}.
691
692 Conceptually, a line of C code is always indented relative to the
693indentation of some line higher up in the buffer. This is represented
694by the buffer positions in the syntactic component list.
695
696 Here is an example. Suppose we have the following code in a C++ mode
697buffer (the line numbers don't actually appear in the buffer):
698
699@example
7001: void swap (int& a, int& b)
7012: @{
7023: int tmp = a;
7034: a = b;
7045: b = tmp;
7056: @}
706@end example
707
708 If you type @kbd{C-c C-s} (which runs the command
709@code{c-show-syntactic-information}) on line 4, it shows the result of
710the indentation mechanism for that line:
711
712@example
713syntactic analysis: ((statement . 32))
714@end example
715
716 This indicates that the line is a statement and it is indented
717relative to buffer position 32, which happens to be the @samp{i} in
718@code{int} on line 3. If you move the cursor to line 3 and type
719@kbd{C-c C-s}, it displays this:
720
721@example
722syntactic analysis: ((defun-block-intro . 28))
723@end example
724
725 This indicates that the @code{int} line is the first statement in a
726block, and is indented relative to buffer position 28, which is the
727brace just after the function header.
728
729@noindent
730Here is another example:
731
732@example
7331: int add (int val, int incr, int doit)
7342: @{
7353: if (doit)
7364: @{
7375: return (val + incr);
7386: @}
7397: return (val);
7408: @}
741@end example
742
743@noindent
744Typing @kbd{C-c C-s} on line 4 displays this:
745
746@example
747syntactic analysis: ((substatement-open . 43))
748@end example
749
750 This says that the brace @emph{opens} a substatement block. By the
751way, a @dfn{substatement} indicates the line after an @code{if},
752@code{else}, @code{while}, @code{do}, @code{switch}, @code{for},
753@code{try}, @code{catch}, @code{finally}, or @code{synchronized}
754statement.
755
756@cindex syntactic component
757@cindex syntactic symbol
758@vindex c-syntactic-context
759 Within the C indentation commands, after a line has been analyzed
760syntactically for indentation, the variable @code{c-syntactic-context}
761contains a list that describes the results. Each element in this list
762is a @dfn{syntactic component}: a cons cell containing a syntactic
763symbol and (optionally) its corresponding buffer position. There may be
764several elements in a component list; typically only one element has a
765buffer position.
766
767@node Indentation Calculation
768@subsubsection Step 2---Indentation Calculation
769@cindex Indentation Calculation
770
771 The C indentation mechanism calculates the indentation for the current
772line using the list of syntactic components, @code{c-syntactic-context},
773derived from syntactic analysis. Each component is a cons cell that
774contains a syntactic symbol and may also contain a buffer position.
775
776 Each component contributes to the final total indentation of the line
777in two ways. First, the syntactic symbol identifies an element of
778@code{c-offsets-alist}, which is an association list mapping syntactic
779symbols into indentation offsets. Each syntactic symbol's offset adds
780to the total indentation. Second, if the component includes a buffer
781position, the column number of that position adds to the indentation.
782All these offsets and column numbers, added together, give the total
783indentation.
784
785 The following examples demonstrate the workings of the C indentation
786mechanism:
787
788@example
7891: void swap (int& a, int& b)
7902: @{
7913: int tmp = a;
7924: a = b;
7935: b = tmp;
7946: @}
795@end example
796
797 Suppose that point is on line 3 and you type @key{TAB} to reindent the
798line. As explained above (@pxref{Syntactic Analysis}), the syntactic
799component list for that line is:
800
801@example
802((defun-block-intro . 28))
803@end example
804
805 In this case, the indentation calculation first looks up
806@code{defun-block-intro} in the @code{c-offsets-alist} alist. Suppose
807that it finds the integer 2; it adds this to the running total
808(initialized to zero), yielding a updated total indentation of 2 spaces.
809
810 The next step is to find the column number of buffer position 28.
811Since the brace at buffer position 28 is in column zero, this adds 0 to
812the running total. Since this line has only one syntactic component,
813the total indentation for the line is 2 spaces.
814
815@example
8161: int add (int val, int incr, int doit)
8172: @{
8183: if (doit)
8194: @{
8205: return(val + incr);
8216: @}
8227: return(val);
8238: @}
824@end example
825
826 If you type @key{TAB} on line 4, the same process is performed, but
827with different data. The syntactic component list for this line is:
828
829@example
830((substatement-open . 43))
831@end example
832
833 Here, the indentation calculation's first job is to look up the
834symbol @code{substatement-open} in @code{c-offsets-alist}. Let's assume
835that the offset for this symbol is 2. At this point the running total
836is 2 (0 + 2 = 2). Then it adds the column number of buffer position 43,
837which is the @samp{i} in @code{if} on line 3. This character is in
838column 2 on that line. Adding this yields a total indentation of 4
839spaces.
840
841@vindex c-strict-syntax-p
842 If a syntactic symbol in the analysis of a line does not appear in
843@code{c-offsets-alist}, it is ignored.
844
845@node Changing Indent Style
846@subsubsection Changing Indentation Style
847
848 There are two ways to customize the indentation style for the C-like
849modes. First, you can select one of several predefined styles, each of
850which specifies offsets for all the syntactic symbols. For more
851flexibility, you can customize the handling of individual syntactic
852symbols. @xref{Syntactic Symbols}, for a list of all defined syntactic
853symbols.
854 565
855@table @kbd 566@table @kbd
856@item M-x c-set-style @key{RET} @var{style} @key{RET} 567@item M-x c-set-style @key{RET} @var{style} @key{RET}
857Select predefined indentation style @var{style}. Type @kbd{?} when 568Select predefined indentation style @var{style}.
858entering @var{style} to see a list of supported styles; to find out what
859a style looks like, select it and reindent some C code, e.g., by typing
860@key{TAB} at the leftmost column of a few lines. @xref{C Indent
861Styles}, for more details about available styles and their
862customizations.
863
864@item C-c C-o @var{symbol} @key{RET} @var{offset} @key{RET}
865Set the indentation offset for syntactic symbol @var{symbol}
866(@code{c-set-offset}). The second argument @var{offset} specifies the
867new indentation offset.
868@end table 569@end table
869 570
870 The @code{c-offsets-alist} variable controls the amount of 571 A style is a named collection of indentation customizations that can
871indentation to give to each syntactic symbol. Its value is an 572be used in C mode and the related modes. Emacs comes with several
872association list, and each element of the list has the form 573predefined styles, including @code{gnu}, @code{k&r}, @code{bsd},
873@code{(@var{syntactic-symbol} . @var{offset})}. By changing the offsets 574@code{stroustrup}, @code{linux}, @code{python}, @code{java},
874for various syntactic symbols, you can customize indentation in fine 575@code{whitesmith}, @code{ellemtel}, @code{cc-mode}, and @code{user}.
875detail. To change this alist, use @code{c-set-offset} (see below). 576Some of these styles are primarily intended for one language, but any
876 577of them can be used with any of the languages supported by these
877 Each offset value in @code{c-offsets-alist} can be an integer, a 578modes. To find out what a style looks like, select it and reindent
878function or variable name, a list, or one of the following symbols: @code{+}, 579some code, e.g., by typing @key{C-M-q} at the start of a function
879@code{-}, @code{++}, @code{--}, @code{*}, or @code{/}, indicating positive or negative 580definition.
880multiples of the variable @code{c-basic-offset}. Thus, if you want to
881change the levels of indentation to be 3 spaces instead of 2 spaces, set
882@code{c-basic-offset} to 3.
883
884 Using a function as the offset value provides the ultimate flexibility
885in customizing indentation. The function is called with a single
886argument containing the @code{cons} of the syntactic symbol and
887the buffer position, if any. The function should return an integer
888offset.
889
890 If the offset value is a list, its elements are processed according
891to the rules above until a non-@code{nil} value is found. That value is
892then added to the total indentation in the normal manner. The primary
893use for this is to combine the results of several functions.
894
895@kindex C-c C-o @r{(C mode)}
896@findex c-set-offset
897 The command @kbd{C-c C-o} (@code{c-set-offset}) is the easiest way to
898set offsets, both interactively or in your @file{~/.emacs} file. First
899specify the syntactic symbol, then the offset you want. @xref{Syntactic
900Symbols}, for a list of valid syntactic symbols and their meanings.
901
902@node Syntactic Symbols
903@subsubsection Syntactic Symbols
904
905 Here is a table of valid syntactic symbols for indentation in C and
906related modes, with their syntactic meanings. Normally, most of these
907symbols are assigned offsets in @code{c-offsets-alist}.
908
909@table @code
910@item string
911Inside a multi-line string.
912
913@item c
914Inside a multi-line C style block comment.
915
916@item defun-open
917On a brace that opens a function definition.
918
919@item defun-close
920On a brace that closes a function definition.
921
922@item defun-block-intro
923In the first line in a top-level defun.
924
925@item class-open
926On a brace that opens a class definition.
927
928@item class-close
929On a brace that closes a class definition.
930
931@item inline-open
932On a brace that opens an in-class inline method.
933
934@item inline-close
935On a brace that closes an in-class inline method.
936
937@item extern-lang-open
938On a brace that opens an external language block.
939
940@item extern-lang-close
941On a brace that closes an external language block.
942
943@item func-decl-cont
944The region between a function definition's argument list and the defun
945opening brace (excluding K&R function definitions). In C, you cannot
946put anything but whitespace and comments between them; in C++ and Java,
947@code{throws} declarations and other things can appear in this context.
948
949@item knr-argdecl-intro
950On the first line of a K&R C argument declaration.
951
952@item knr-argdecl
953In one of the subsequent lines in a K&R C argument declaration.
954
955@item topmost-intro
956On the first line in a topmost construct definition.
957
958@item topmost-intro-cont
959On the topmost definition continuation lines.
960
961@item member-init-intro
962On the first line in a member initialization list.
963
964@item member-init-cont
965On one of the subsequent member initialization list lines.
966
967@item inher-intro
968On the first line of a multiple inheritance list.
969
970@item inher-cont
971On one of the subsequent multiple inheritance lines.
972
973@item block-open
974On a statement block open brace.
975
976@item block-close
977On a statement block close brace.
978
979@item brace-list-open
980On the opening brace of an @code{enum} or @code{static} array list.
981
982@item brace-list-close
983On the closing brace of an @code{enum} or @code{static} array list.
984
985@item brace-list-intro
986On the first line in an @code{enum} or @code{static} array list.
987
988@item brace-list-entry
989On one of the subsequent lines in an @code{enum} or @code{static} array
990list.
991
992@item brace-entry-open
993On one of the subsequent lines in an @code{enum} or @code{static} array
994list, when the line begins with an open brace.
995
996@item statement
997On an ordinary statement.
998
999@item statement-cont
1000On a continuation line of a statement.
1001
1002@item statement-block-intro
1003On the first line in a new statement block.
1004
1005@item statement-case-intro
1006On the first line in a @code{case} ``block.''
1007
1008@item statement-case-open
1009On the first line in a @code{case} block starting with brace.
1010
1011@item inexpr-statement
1012On a statement block inside an expression. This is used for a GNU
1013extension to the C language, and for Pike special functions that take a
1014statement block as an argument.
1015
1016@item inexpr-class
1017On a class definition inside an expression. This is used for anonymous
1018classes and anonymous array initializers in Java.
1019
1020@item substatement
1021On the first line after an @code{if}, @code{while}, @code{for},
1022@code{do}, or @code{else}.
1023
1024@item substatement-open
1025On the brace that opens a substatement block.
1026
1027@item case-label
1028On a @code{case} or @code{default} label.
1029
1030@item access-label
1031On a C++ @code{private}, @code{protected}, or @code{public} access label.
1032
1033@item label
1034On any ordinary label.
1035
1036@item do-while-closure
1037On the @code{while} that ends a @code{do}-@code{while} construct.
1038
1039@item else-clause
1040On the @code{else} of an @code{if}-@code{else} construct.
1041
1042@item catch-clause
1043On the @code{catch} and @code{finally} lines in
1044@code{try}@dots{}@code{catch} constructs in C++ and Java.
1045
1046@item comment-intro
1047On a line containing only a comment introduction.
1048
1049@item arglist-intro
1050On the first line in an argument list.
1051
1052@item arglist-cont
1053On one of the subsequent argument list lines when no arguments follow on
1054the same line as the arglist opening parenthesis.
1055
1056@item arglist-cont-nonempty
1057On one of the subsequent argument list lines when at least one argument
1058follows on the same line as the arglist opening parenthesis.
1059
1060@item arglist-close
1061On the closing parenthesis of an argument list.
1062
1063@item stream-op
1064On one of the lines continuing a stream operator construct.
1065
1066@item inclass
1067On a construct that is nested inside a class definition. The
1068indentation is relative to the open brace of the class definition.
1069
1070@item inextern-lang
1071On a construct that is nested inside an external language block.
1072
1073@item inexpr-statement
1074On the first line of statement block inside an expression. This is used
1075for the GCC extension to C that uses the syntax @code{(@{ @dots{} @})}.
1076It is also used for the special functions that takes a statement block
1077as an argument in Pike.
1078
1079@item inexpr-class
1080On the first line of a class definition inside an expression. This is
1081used for anonymous classes and anonymous array initializers in Java.
1082
1083@item cpp-macro
1084On the start of a cpp macro.
1085
1086@item friend
1087On a C++ @code{friend} declaration.
1088
1089@item objc-method-intro
1090On the first line of an Objective-C method definition.
1091
1092@item objc-method-args-cont
1093On one of the lines continuing an Objective-C method definition.
1094
1095@item objc-method-call-cont
1096On one of the lines continuing an Objective-C method call.
1097
1098@item inlambda
1099Like @code{inclass}, but used inside lambda (i.e. anonymous) functions. Only
1100used in Pike.
1101
1102@item lambda-intro-cont
1103On a line continuing the header of a lambda function, between the
1104@code{lambda} keyword and the function body. Only used in Pike.
1105@end table
1106
1107@node Variables for C Indent
1108@subsubsection Variables for C Indentation
1109
1110 This section describes additional variables which control the
1111indentation behavior of C mode and related mode.
1112
1113@table @code
1114@item c-offsets-alist
1115@vindex c-offsets-alist
1116Association list of syntactic symbols and their indentation offsets.
1117You should not set this directly, only with @code{c-set-offset}.
1118@xref{Changing Indent Style}, for details.
1119
1120@item c-style-alist
1121@vindex c-style-alist
1122Variable for defining indentation styles; see below.
1123
1124@item c-basic-offset
1125@vindex c-basic-offset
1126Amount of basic offset used by @code{+} and @code{-} symbols in
1127@code{c-offsets-alist}.@refill
1128
1129@item c-special-indent-hook
1130@vindex c-special-indent-hook
1131Hook for user-defined special indentation adjustments. This hook is
1132called after a line is indented by C mode and related modes.
1133@end table
1134
1135 The variable @code{c-style-alist} specifies the predefined indentation
1136styles. Each element has form @code{(@var{name}
1137@var{variable-setting}@dots{})}, where @var{name} is the name of the
1138style. Each @var{variable-setting} has the form @code{(@var{variable}
1139. @var{value})}; @var{variable} is one of the customization variables
1140used by C mode, and @var{value} is the value for that variable when
1141using the selected style.
1142
1143 When @var{variable} is @code{c-offsets-alist}, that is a special case:
1144@var{value} is appended to the front of the value of @code{c-offsets-alist}
1145instead of replacing that value outright. Therefore, it is not necessary
1146for @var{value} to specify each and every syntactic symbol---only those
1147for which the style differs from the default.
1148
1149 The indentation of lines containing only comments is also affected by
1150the variable @code{c-comment-only-line-offset} (@pxref{Comments in C}).
1151
1152@node C Indent Styles
1153@subsubsection C Indentation Styles
1154@cindex c indentation styles
1155
1156 A @dfn{C style} is a collection of indentation style customizations
1157that can be used in C mode and the related modes. Emacs comes with
1158several predefined C styles, including @code{gnu}, @code{k&r},
1159@code{bsd}, @code{stroustrup}, @code{linux}, @code{python},
1160@code{java}, @code{whitesmith}, @code{ellemtel}, @code{cc-mode}, and
1161@code{user}. Some of these styles are primarily intended for one
1162language, but any of them can be used with any of the languages
1163supported by these modes.
1164 581
1165@findex c-set-style 582@findex c-set-style
1166 To choose a style for the current buffer, use the command @kbd{M-x 583 To choose a style for the current buffer, use the command @kbd{M-x
1167c-set-style}. Specify a style name as an argument (case is not 584c-set-style}. Specify a style name as an argument (case is not
1168significant in C style names). This command affects the current 585significant). This command affects the current buffer only, and it
1169buffer only, but it affects only future invocations of the indentation 586affects only future invocations of the indentation commands; it does
1170command; it does not change the indentation of the code in the buffer. 587not change the indentation of the code in the buffer. To reindent the
1171To reindent the text, you can type @kbd{C-x h C-M-\}. 588whole buffer in the new style, you can type @kbd{C-x h C-M-\}.
1172 589
1173@vindex c-default-style 590@vindex c-default-style
1174 You can also set the variable @code{c-default-style} to specify the 591 You can also set the variable @code{c-default-style} to specify the
@@ -1190,78 +607,237 @@ existing Java mode buffer by typing @kbd{M-x java-mode} there.
1190 607
1191 The @code{gnu} style specifies the formatting recommended by the GNU 608 The @code{gnu} style specifies the formatting recommended by the GNU
1192Project for C; it is the default, so as to encourage use of our 609Project for C; it is the default, so as to encourage use of our
1193recommended style. If you make changes in variables such as 610recommended style.
1194@code{c-basic-offset} and @code{c-offsets-alist} in your
1195@file{~/.emacs} file, those changes override what the @code{gnu} style
1196specifies.
1197 611
1198@findex c-add-style 612 @xref{Customizing Indentation,, cc-mode, the CC Mode Manual}, for
1199 To define a new C indentation style, call the function 613more information on customizing indentation for C and related modes,
1200@code{c-add-style}: 614including how to override parts of an existing style and how to define
615your own styles.
1201 616
1202@example 617@node Parentheses
1203(c-add-style @var{name} @var{values} @var{use-now}) 618@section Commands for Editing with Parentheses
1204@end example
1205 619
1206@noindent 620@findex check-parens
1207Here @var{name} is the name of the new style (a string), and 621@cindex unbalanced parentheses and quotes
1208@var{values} is an alist whose elements have the form 622 This section describes the commands and features that take advantage
1209@code{(@var{variable} . @var{value})}. The variables you specify 623of the parenthesis structure in a program, or help you keep it
1210should be among those documented in @ref{Variables for C Indent}. If 624balanced.
1211@var{use-now} is non-@code{nil}, @code{c-add-style} selects the new 625
1212style after defining it. 626 When talking about these facilities, the term ``parenthesis'' also
627includes braces, brackets, or whatever delimiters are defined to match
628in pairs. This is controlled by the major mode, through the syntax
629table (@pxref{Syntax}). In Lisp, only parentheses count; in C, these
630commands apply to braces and brackets too.
631
632 You can use @kbd{M-x check-parens} to find any unbalanced
633parentheses and unbalanced string quotes in the buffer.
634
635@menu
636* Expressions:: Expressions with balanced parentheses.
637* Moving by Parens:: Commands for moving up, down and across
638 in the structure of parentheses.
639* Matching:: Insertion of a close-delimiter flashes matching open.
640@end menu
641
642@node Expressions
643@subsection Expressions with Balanced Parentheses
644
645@cindex sexp
646@cindex expression
647@cindex balanced expression
648 These commands deal with balanced expressions, also called
649@dfn{sexps}@footnote{The word ``sexp'' is used to refer to an
650expression in Lisp.}.
651
652@table @kbd
653@item C-M-f
654Move forward over a balanced expression (@code{forward-sexp}).
655@item C-M-b
656Move backward over a balanced expression(@code{backward-sexp}).
657@item C-M-k
658Kill balanced expression forward (@code{kill-sexp}).
659@item C-M-@key{DEL}
660Kill balanced expression backward (@code{backward-kill-sexp}).
661@item C-M-t
662Transpose expressions (@code{transpose-sexps}).
663@item C-M-@@
664Put mark after following expression (@code{mark-sexp}).
665@end table
666
667 Each programming language major mode customizes the definition of
668balanced expressions to suit that language. Balanced expressions
669typically include symbols, numbers, and string constants, as well as
670anything contained in parentheses, brackets or braces. Some languages
671have obscure forms of expression syntax that nobody has bothered to
672implement in Emacs.
673
674@cindex Control-Meta
675 By convention, the keys for these commands are always Control-Meta
676characters. They usually act like the corresponding Meta characters,
677except that they take note of parentheses and their contents. For
678instance, the command @kbd{C-M-b} moves backward over a balanced
679expression, just as @kbd{M-b} moves back over a word.
680
681@kindex C-M-f
682@kindex C-M-b
683@findex forward-sexp
684@findex backward-sexp
685 To move forward over a balanced expression, use @kbd{C-M-f}
686(@code{forward-sexp}). If the first significant character after point
687is an opening delimiter (@samp{(} in Lisp; @samp{(}, @samp{[} or
688@samp{@{} in C), @kbd{C-M-f} moves past the matching closing
689delimiter. If the character begins a symbol, string, or number,
690@kbd{C-M-f} moves over that.
691
692 The command @kbd{C-M-b} (@code{backward-sexp}) moves backward over a
693balanced expression. The detailed rules are like those above for
694@kbd{C-M-f}, but with directions reversed. If there are prefix
695characters (single-quote, backquote and comma, in Lisp) preceding the
696expression, @kbd{C-M-b} moves back over them as well. The balanced
697expression commands move across comments as if they were whitespace,
698in most modes.
699
700 @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation the
701specified number of times; with a negative argument, it moves in the
702opposite direction.
703
704@cindex killing expressions
705@kindex C-M-k
706@findex kill-sexp
707@kindex C-M-DEL
708@findex backward-kill-sexp
709 Killing a whole balanced expression can be done with @kbd{C-M-k}
710(@code{kill-sexp}) or @kbd{C-M-@key{DEL}} (@code{backward-kill-sexp}).
711@kbd{C-M-k} kills the characters that @kbd{C-M-f} would move over, and
712@kbd{C-M-@key{DEL}} kills the characters that @kbd{C-M-b} would move
713over.
714
715@cindex transposition of expressions
716@kindex C-M-t
717@findex transpose-sexps
718 A somewhat random-sounding command which is nevertheless handy is
719@kbd{C-M-t} (@code{transpose-sexps}), which drags the previous
720balanced expression across the next one. An argument serves as a
721repeat count, and a negative argument drags backwards (thus canceling
722out the effect of @kbd{C-M-t} with a positive argument). An argument
723of zero, rather than doing nothing, transposes the balanced
724expressions ending after point and the mark.
725
726@kindex C-M-@@
727@findex mark-sexp
728 To set the region around the next balanced expression in the buffer,
729use @kbd{C-M-@@} (@code{mark-sexp}), which sets mark at the same place
730that @kbd{C-M-f} would move to. @kbd{C-M-@@} takes arguments like
731@kbd{C-M-f}. In particular, a negative argument is useful for putting
732the mark at the beginning of the previous balanced expression.
733
734 In languages that use infix operators, such as C, it is not possible
735to recognize all balanced expressions as such because there can be
736multiple possibilities at a given position. For example, C mode does
737not treat @samp{foo + bar} as a single expression, even though it
738@emph{is} one C expression; instead, it recognizes @samp{foo} as one
739expression and @samp{bar} as another, with the @samp{+} as punctuation
740between them. Both @samp{foo + bar} and @samp{foo} are legitimate
741choices for ``the expression following point'' when point is at the
742@samp{f}. Note that @samp{(foo + bar)} does act as a single
743expression in C mode.
744
745@node Moving by Parens
746@subsection Moving in the Parenthesis Structure
747
748@cindex parenthetical groupings
749@cindex parentheses, moving across
750@cindex matching parenthesis and braces, moving to
751@cindex braces, moving across
752@cindex list commands
753 The Emacs commands for handling parenthetical groupings see nothing
754except parentheses (or whatever characters must balance in the
755language you are working with), and the escape characters that might
756be used to quote those. They are mainly intended for editing
757programs, but can be useful for editing any text that has parentheses.
758They are sometimes called ``list'' commands because in Lisp these
759groupings are lists.
760
761@table @kbd
762@item C-M-n
763Move forward over a parenthetical group (@code{forward-list}).
764@item C-M-p
765Move backward over a parenthetical group(@code{backward-list}).
766@item C-M-u
767Move up in parenthesis structure (@code{backward-up-list}).
768@item C-M-d
769Move down in parenthesis structure (@code{down-list}).
770@end table
771
772@kindex C-M-n
773@kindex C-M-p
774@findex forward-list
775@findex backward-list
776 The ``list'' commands @kbd{C-M-n} (@code{forward-list}) and
777@kbd{C-M-p} (@code{backward-list}) move over one (or @var{n})
778parenthetical groupings, skipping blithely over any amount of text
779that doesn't include meaningful parentheses (symbols, strings, etc.).
780
781@kindex C-M-u
782@kindex C-M-d
783@findex backward-up-list
784@findex down-list
785 @kbd{C-M-n} and @kbd{C-M-p} try to stay at the same level in the
786parenthesis structure. To move @emph{up} one (or @var{n}) levels, use
787@kbd{C-M-u} (@code{backward-up-list}). @kbd{C-M-u} moves backward up
788past one unmatched opening delimiter. A positive argument serves as a
789repeat count; a negative argument reverses the direction of motion, so
790that the command forward and up one or more levels.
791
792 To move @emph{down} in the parenthesis structure, use @kbd{C-M-d}
793(@code{down-list}). In Lisp mode, where @samp{(} is the only opening
794delimiter, this is nearly the same as searching for a @samp{(}. An
795argument specifies the number of levels to go down.
1213 796
1214@node Matching 797@node Matching
1215@section Automatic Display Of Matching Parentheses 798@subsection Automatic Display Of Matching Parentheses
1216@cindex matching parentheses 799@cindex matching parentheses
1217@cindex parentheses, displaying matches 800@cindex parentheses, displaying matches
1218 801
1219 The Emacs parenthesis-matching feature is designed to show 802 The Emacs parenthesis-matching feature is designed to show
1220automatically how parentheses match in the text. Whenever you type a 803automatically how parentheses (and other matching delimiters) match in
1221self-inserting character that is a closing delimiter, the cursor moves 804the text. Whenever you type a self-inserting character that is a
1222momentarily to the location of the matching opening delimiter, provided 805closing delimiter, the cursor moves momentarily to the location of the
1223that is on the screen. If it is not on the screen, some text near it is 806matching opening delimiter, provided that is on the screen. If it is
1224displayed in the echo area. Either way, you can tell what grouping is 807not on the screen, Emacs displays some text near it in the echo area.
1225being closed off. 808Either way, you can tell what grouping you are closing off.
1226 809
1227 In Lisp, automatic matching applies only to parentheses. In C, it 810 If the opening delimiter and closing delimiter are mismatched---such
1228applies to braces and brackets too. Emacs knows which characters to regard 811as in @samp{[x)}---a warning message is displayed in the echo area.
1229as matching delimiters based on the syntax table, which is set by the major
1230mode. @xref{Syntax}.
1231
1232 If the opening delimiter and closing delimiter are mismatched---such as
1233in @samp{[x)}---a warning message is displayed in the echo area. The
1234correct matches are specified in the syntax table.
1235 812
1236@vindex blink-matching-paren 813@vindex blink-matching-paren
1237@vindex blink-matching-paren-distance 814@vindex blink-matching-paren-distance
1238@vindex blink-matching-delay 815@vindex blink-matching-delay
1239 Three variables control parenthesis match display. 816 Three variables control parenthesis match display.
1240@code{blink-matching-paren} turns the feature on or off; @code{nil} 817@code{blink-matching-paren} turns the feature on or off: @code{nil}
1241turns it off, but the default is @code{t} to turn match display on. 818disables it, but the default is @code{t} to enable match display.
1242 819
1243 @code{blink-matching-delay} says how many seconds to leave the 820 @code{blink-matching-delay} says how many seconds to leave the
1244cursor on the matching open parenthesis, before bringing it back to 821cursor on the matching opening delimiter, before bringing it back to
1245the real location of point; the default is 1, but on some systems it 822the real location of point; the default is 1, but on some systems it
1246is useful to specify a fraction of a second. 823is useful to specify a fraction of a second.
1247 824
1248 @code{blink-matching-paren-distance} specifies how many characters 825 @code{blink-matching-paren-distance} specifies how many characters
1249back to search to find the matching opening delimiter. If the match 826back to search to find the matching opening delimiter. If the match
1250is not found in that far, scanning stops, and nothing is displayed. 827is not found in that far, scanning stops, and nothing is displayed.
1251This is to prevent scanning for the matching delimiter from wasting 828This is to prevent the scan for the matching delimiter from wasting
1252lots of time when there is no match. The default is 25600. 829lots of time when there is no match. The default is 25600.
1253 830
1254@cindex Show Paren mode 831@cindex Show Paren mode
1255@cindex highlighting matching parentheses 832@cindex highlighting matching parentheses
1256@findex show-paren-mode 833@findex show-paren-mode
1257 Show Paren mode provides a more powerful kind of automatic 834 Show Paren mode provides a more powerful kind of automatic matching.
1258parenthesis matching. Whenever point is after a close parenthesis, 835Whenever point is after a closing delimiter, that delimiter and its
1259the close parenthesis and its matching open parenthesis are both 836matching opening delimiter are both highlighted; otherwise, if point
1260highlighted; otherwise, if point is before an open parenthesis, the 837is before an opening delimiter, the matching closing delimiter is
1261matching close parenthesis is highlighted. (There is no need to 838highlighted. (There is no need to highlight the opening delimiter in
1262highlight the open parenthesis after point because the cursor appears 839that case, because the cursor appears on top of that character.) Use
1263on top of that character.) Use the command @kbd{M-x show-paren-mode} 840the command @kbd{M-x show-paren-mode} to enable or disable this mode.
1264to enable or disable this mode.
1265 841
1266 By default, @code{show-paren-mode} uses colors to highlight the 842 By default, @code{show-paren-mode} uses colors to highlight the
1267parentheses. However, if your display doesn't support colors, you can 843parentheses. However, if your display doesn't support colors, you can
@@ -1277,9 +853,9 @@ underline. @xref{Face Customization}.
1277provides special commands for editing and inserting comments. 853provides special commands for editing and inserting comments.
1278 854
1279@menu 855@menu
1280* Comment Commands:: 856* Comment Commands:: Inserting, killing, and indenting comments.
1281* Multi-Line Comments:: 857* Multi-Line Comments:: Commands for adding and editing multi-line comments.
1282* Options for Comments:: 858* Options for Comments::Customizing the comment features.
1283@end menu 859@end menu
1284 860
1285@node Comment Commands 861@node Comment Commands
@@ -1474,256 +1050,87 @@ comment ought to start. For example, in Lisp mode, the indent hook
1474function bases its decision on how many semicolons begin an existing 1050function bases its decision on how many semicolons begin an existing
1475comment, and on the code in the preceding lines. 1051comment, and on the code in the preceding lines.
1476 1052
1477@node Balanced Editing 1053@node Documentation
1478@section Editing Without Unbalanced Parentheses 1054@section Documentation Lookup
1479
1480@table @kbd
1481@item M-(
1482Put parentheses around next sexp(s) (@code{insert-parentheses}).
1483@item M-)
1484Move past next close parenthesis and reindent
1485(@code{move-past-close-and-reindent}).
1486@end table
1487
1488@kindex M-(
1489@kindex M-)
1490@findex insert-parentheses
1491@findex move-past-close-and-reindent
1492 The commands @kbd{M-(} (@code{insert-parentheses}) and @kbd{M-)}
1493(@code{move-past-close-and-reindent}) are designed to facilitate a style
1494of editing which keeps parentheses balanced at all times. @kbd{M-(}
1495inserts a pair of parentheses, either together as in @samp{()}, or, if
1496given an argument, around the next several sexps. It leaves point after
1497the open parenthesis. The command @kbd{M-)} moves past the close
1498parenthesis, deleting any indentation preceding it, and indenting with
1499@kbd{C-j} after it.
1500
1501 For example, instead of typing @kbd{( F O O )}, you can type @kbd{M-(
1502F O O}, which has the same effect except for leaving the cursor before
1503the close parenthesis.
1504
1505@vindex parens-require-spaces
1506 @kbd{M-(} may insert a space before the open parenthesis, depending on
1507the syntax class of the preceding character. Set
1508@code{parens-require-spaces} to @code{nil} value if you wish to inhibit
1509this.
1510 1055
1511@findex check-parens 1056 Emacs provides several features you can use to look up the
1512@cindex unbalanced parentheses and quotes 1057documentation of functions, variables and commands that you plan to
1513 You can use @kbd{M-x check-parens} to find any unbalanced 1058use in your program.
1514parentheses and unbalanced string quotes in a buffer.
1515 1059
1516@node Symbol Completion 1060@menu
1517@section Completion for Symbol Names 1061* Info Lookup:: Looking up library functions and commands
1518@cindex completion (symbol names) 1062 in Info files.
1063* Man Page:: Looking up man pages of library functions and commands.
1064* Lisp Doc:: Looking up Emacs Lisp functions, etc.
1065@end menu
1519 1066
1520 Usually completion happens in the minibuffer. But one kind of completion 1067@node Info Lookup
1521is available in all buffers: completion for symbol names. 1068@subsection Info Documentation Lookup
1522 1069
1523@kindex M-TAB 1070@findex info-lookup-symbol
1524 The character @kbd{M-@key{TAB}} runs a command to complete the partial 1071@findex info-lookup-file
1525symbol before point against the set of meaningful symbol names. Any 1072@kindex C-h C-i
1526additional characters determined by the partial name are inserted at 1073 For C, Lisp, and other languages that have documentation in Info,
1074you can use @kbd{C-h C-i} (@code{info-lookup-symbol}) to view the Info
1075documentation for a symbol. You specify the symbol with the
1076minibuffer; the default is the symbol appearing in the buffer at
1527point. 1077point.
1528 1078
1529 If the partial name in the buffer has more than one possible completion 1079 The major mode determines where to look for documentation for the
1530and they have no additional characters in common, a list of all possible 1080symbol---which Info files to look in, and which indices to search.
1531completions is displayed in another window. 1081You can also use @kbd{M-x info-lookup-file} to look for documentation
1532 1082for a file name.
1533@cindex tags-based completion
1534@cindex Info index completion
1535@findex complete-symbol
1536 In most programming language major modes, @kbd{M-@key{TAB}} runs the
1537command @code{complete-symbol}, which provides two kinds of completion.
1538Normally it does completion based on a tags table (@pxref{Tags}); with a
1539numeric argument (regardless of the value), it does completion based on
1540the names listed in the Info file indexes for your language. Thus, to
1541complete the name of a symbol defined in your own program, use
1542@kbd{M-@key{TAB}} with no argument; to complete the name of a standard
1543library function, use @kbd{C-u M-@key{TAB}}. Of course, Info-based
1544completion works only if there is an Info file for the standard library
1545functions of your language, and only if it is installed at your site.
1546
1547@cindex Lisp symbol completion
1548@cindex completion (Lisp symbols)
1549@findex lisp-complete-symbol
1550 In Emacs-Lisp mode, the name space for completion normally consists of
1551nontrivial symbols present in Emacs---those that have function
1552definitions, values or properties. However, if there is an
1553open-parenthesis immediately before the beginning of the partial symbol,
1554only symbols with function definitions are considered as completions.
1555The command which implements this is @code{lisp-complete-symbol}.
1556 1083
1557 In Text mode and related modes, @kbd{M-@key{TAB}} completes words 1084 This feature currently supports the modes Awk, Autoconf, Bison, C,
1558based on the spell-checker's dictionary. @xref{Spelling}. 1085Emacs Lisp, LaTeX, M4, Makefile, Octave, Perl, Scheme, and Texinfo,
1086provided you have installed the relevant Info files, which are
1087typically available with the appropriate GNU package.
1559 1088
1560@node Which Function 1089@node Man Page
1561@section Which Function Mode 1090@subsection Man Page Lookup
1562 1091
1563 Which Function mode is a minor mode that displays the current function 1092 Eventually the GNU project hopes to replace most man pages in the
1564name in the mode line, as you move around in a buffer. 1093GNU operating system with better-organized manuals that you can browse
1565 1094with Info (@pxref{Misc Help}). Since this process is not finished, it
1566@findex which-function-mode 1095is still useful to read manual pages.
1567@vindex which-func-modes
1568 To enable (or disable) Which Function mode, use the command @kbd{M-x
1569which-function-mode}. This command is global; it applies to all
1570buffers, both existing ones and those yet to be created. However, this
1571only affects certain major modes, those listed in the value of
1572@code{which-func-modes}. (If the value is @code{t}, then Which Function
1573mode applies to all major modes that know how to support it---which are
1574the major modes that support Imenu.)
1575
1576@node Hideshow
1577@section Hideshow minor mode
1578
1579@findex hs-minor-mode
1580 Hideshow minor mode provides selective display of portions of a
1581file, known as @dfn{blocks}. You can use @kbd{M-x hs-minor-mode} to
1582enable or disable this mode, or add @code{hs-minor-mode} to the mode
1583hook for certain major modes in order to enable it automatically for
1584those modes.
1585
1586 Just what constitutes a block depends on the major mode. In C mode
1587or C++ mode, they are delimited by braces, while in Lisp mode and
1588similar modes they are delimited by parentheses. Multi-line comments
1589also count as blocks.
1590
1591@findex hs-hide-all
1592@findex hs-hide-block
1593@findex hs-show-all
1594@findex hs-show-block
1595@findex hs-show-region
1596@findex hs-hide-level
1597@findex hs-minor-mode
1598@kindex C-c @@ C-h
1599@kindex C-c @@ C-s
1600@kindex C-c @@ C-M-h
1601@kindex C-c @@ C-M-s
1602@kindex C-c @@ C-r
1603@kindex C-c @@ C-l
1604@kindex S-Mouse-2
1605@table @kbd
1606@item C-c @@ C-h
1607Hide the current block (@code{hs-hide-block}).
1608@item C-c @@ C-s
1609Show the current block (@code{hs-show-block}).
1610@item C-c @@ C-c
1611Either hide or show the current block (@code{hs-toggle-hiding})
1612@item S-Mouse-2
1613Either hide or show the block you click on (@code{hs-mouse-toggle-hiding})
1614@item C-c @@ C-M-h
1615Hide all top-level blocks (@code{hs-hide-all}).
1616@item C-c @@ C-M-s
1617Show everything in the buffer (@code{hs-show-all}).
1618@item C-c @@ C-l
1619Hide all blocks @var{n} levels below this block
1620(@code{hs-hide-level}).
1621@end table
1622
1623@vindex hs-hide-comments-when-hiding-all
1624@vindex hs-isearch-open
1625@vindex hs-special-modes-alist
1626 These user options exist for customizing Hideshow mode.
1627
1628@table @code
1629@item hs-hide-comments-when-hiding-all
1630Non-@code{nil} says that @kbd{hs-hide-all} should hide comments too.
1631@item hs-isearch-open
1632Specifies what kind of hidden blocks to open in Isearch mode.
1633@item hs-special-modes-alist
1634Specifies how to initialize Hideshow variables for different modes.
1635@end table
1636
1637@node Glasses
1638@section Glasses minor mode
1639@cindex Glasses mode
1640@cindex identifiers, making long ones readable
1641@cindex StudlyCaps, making them readable
1642@findex glasses-mode
1643
1644 Glasses minor mode makes @samp{unreadableIdentifiersLikeThis}
1645readable by altering the display. It can do this in two different
1646ways: by displaying underscores between an lower-case letter and the
1647following capital letter, or by emboldening the capital letters. It
1648does not alter the buffer text, only the way they display, so you can
1649use it even on read-only buffers. You can use the command @kbd{M-x
1650glasses-mode} to enable or disable the mode; you can also add
1651@code{glasses-mode} to the mode hook of appropriate programming
1652language major modes.
1653
1654@node Documentation
1655@section Documentation Commands
1656
1657 As you edit Lisp code to be run in Emacs, the commands @kbd{C-h f}
1658(@code{describe-function}) and @kbd{C-h v} (@code{describe-variable}) can
1659be used to print documentation of functions and variables that you want to
1660call. These commands use the minibuffer to read the name of a function or
1661variable to document, and display the documentation in a window.
1662
1663 For extra convenience, these commands provide default arguments based on
1664the code in the neighborhood of point. @kbd{C-h f} sets the default to the
1665function called in the innermost list containing point. @kbd{C-h v} uses
1666the symbol name around or adjacent to point as its default.
1667
1668@cindex Eldoc mode
1669@findex eldoc-mode
1670 For Emacs Lisp code, you can also use Eldoc mode. This minor mode
1671constantly displays in the echo area the argument list for the function
1672being called at point. (In other words, it finds the function call that
1673point is contained in, and displays the argument list of that function.)
1674Eldoc mode applies in Emacs Lisp and Lisp Interaction modes only. Use
1675the command @kbd{M-x eldoc-mode} to enable or disable this feature.
1676
1677@findex info-lookup-symbol
1678@findex info-lookup-file
1679@kindex C-h C-i
1680 For C, Lisp, and other languages, you can use @kbd{C-h C-i}
1681(@code{info-lookup-symbol}) to view the Info documentation for a symbol.
1682You specify the symbol with the minibuffer; by default, it uses the
1683symbol that appears in the buffer at point. The major mode determines
1684where to look for documentation for the symbol---which Info files and
1685which indices. You can also use @kbd{M-x info-lookup-file} to look for
1686documentation for a file name. Currently this supports the following
1687modes: Awk, Autoconf, Bison, C, Emacs Lisp, LaTeX, M4,
1688Makefile, Octave, Perl, Scheme and Texinfo, provided you have installed
1689the relevant Info files, which are typically available with the appropriate GNU
1690package.
1691 1096
1692@findex manual-entry 1097@findex manual-entry
1693@cindex manual pages 1098@cindex manual pages
1694 You can read the ``man page'' for an operating system command, library 1099 You can read the ``man page'' for an operating system command,
1695function, or system call, with the @kbd{M-x manual-entry} command. It 1100library function, or system call, with the @kbd{M-x manual-entry}
1696runs the @code{man} program to format the man page, and runs it 1101command. It runs the @code{man} program to format the man page, and
1697asynchronously if your system permits, so that you can keep on editing 1102runs it asynchronously if your system permits, so that you can keep on
1698while the page is being formatted. (MS-DOS and MS-Windows 3 do not 1103editing while the page is being formatted. (MS-DOS and MS-Windows 3
1699permit asynchronous subprocesses, so on these systems you cannot edit 1104do not permit asynchronous subprocesses, so on these systems you
1700while Emacs waits for @code{man} to exit.) The result goes in a buffer 1105cannot edit while Emacs waits for @code{man} to finish.) The result
1701named @samp{*Man @var{topic}*}. These buffers use a special major mode, 1106goes in a buffer named @samp{*Man @var{topic}*}. These buffers use a
1702Man mode, that facilitates scrolling and examining other manual pages. 1107special major mode, Man mode, that facilitates scrolling and jumping
1703For details, type @kbd{C-h m} while in a man page buffer. 1108to other manual pages. For details, type @kbd{C-h m} while in a man
1109page buffer.
1704 1110
1705@cindex sections of manual pages 1111@cindex sections of manual pages
1706 Man pages are classified into @dfn{sections}; sometimes there are 1112 Each man page belongs to one of around ten @dfn{sections}; sometimes
1707man pages with the same name in different sections. To read a man 1113there are multiple man pages with the same name in different sections.
1708page from a specific section, type @samp{@var{topic}(@var{section})} or 1114To read a man page from a specific section, type
1709@samp{@var{section} @var{topic}} when @kbd{M-x manual-entry} prompts 1115@samp{@var{topic}(@var{section})} or @samp{@var{section} @var{topic}}
1710for the topic. For example, to read the man page for the C library 1116when @kbd{M-x manual-entry} prompts for the topic. For example, to
1711function @code{chmod} (as opposed to a command by the same name), type 1117read the man page for the C library function @code{chmod} (as opposed
1712@kbd{M-x manual-entry @key{RET} chmod(2v) @key{RET}} (assuming 1118to a command by the same name), type @kbd{M-x manual-entry @key{RET}
1713@code{chmod} is in section @samp{2v}). 1119chmod(2v) @key{RET}} (assuming @code{chmod} is in section @samp{2v}).
1714 1120
1715 If you do not specify a section, the results depend on how the 1121 If you do not specify a section, the results depend on how the
1716@code{man} command works on your system. Some of them display only 1122@code{man} command works on your system. Some of them display only
1717the first man page they find. Others display all man pages that have 1123the first man page they find. Others display all man pages that have
1718the specified name, so you can page between them with the @kbd{M-n} 1124the specified name, so you can move between them with the @kbd{M-n}
1719and @kbd{M-p} keys. The mode line shows how many manual pages are 1125and @kbd{M-p} keys. The mode line shows how many manual pages are
1720available in the Man buffer. 1126present in the Man buffer.
1721 1127
1722@vindex Man-fontify-manpage-flag 1128@vindex Man-fontify-manpage-flag
1723 For a long man page, setting the faces properly can take substantial 1129 By default, Emacs uses faces in man pages if Emacs can display
1724time. By default, Emacs uses faces in man pages if Emacs can display 1130different fonts or colors. For a long man page, setting the faces
1725different fonts or colors. You can turn off use of faces in man pages 1131properly can take substantial time. You can turn off use of faces in
1726by setting the variable @code{Man-fontify-manpage-flag} to @code{nil}. 1132man pages by setting the variable @code{Man-fontify-manpage-flag} to
1133@code{nil}.
1727 1134
1728@findex Man-fontify-manpage 1135@findex Man-fontify-manpage
1729 If you insert the text of a man page into an Emacs buffer in some 1136 If you insert the text of a man page into an Emacs buffer in some
@@ -1744,7 +1151,7 @@ provides completion based on the list of manual pages that are
1744installed on your machine; the list of available manual pages is 1151installed on your machine; the list of available manual pages is
1745computed automatically the first time you invoke @code{woman}. The 1152computed automatically the first time you invoke @code{woman}. The
1746word at point in the current buffer is used to suggest the default 1153word at point in the current buffer is used to suggest the default
1747name of the manual page. 1154for the name the manual page.
1748 1155
1749 With a numeric argument, @kbd{M-x woman} recomputes the list of the 1156 With a numeric argument, @kbd{M-x woman} recomputes the list of the
1750manual pages used for completion. This is useful if you add or delete 1157manual pages used for completion. This is useful if you add or delete
@@ -1756,25 +1163,25 @@ pops up a window with possible candidates asking you to choose one of
1756them. 1163them.
1757 1164
1758@vindex woman-manpath 1165@vindex woman-manpath
1759 By default, @kbd{M-x woman} looks up the manual pages in directories 1166 By default, @kbd{M-x woman} looks for manual pages in the
1760listed by the @code{MANPATH} environment variable. (If @code{MANPATH} 1167directories specified in the @code{MANPATH} environment variable. (If
1761is not set, @code{woman} uses a suitable default value, which can be 1168@code{MANPATH} is not set, @code{woman} uses a suitable default value,
1762customized.) More precisely, @code{woman} looks for subdirectories that 1169which can be customized.) More precisely, @code{woman} looks for
1763match the shell wildcard @file{man*} in each one of these directories, 1170subdirectories that match the shell wildcard @file{man*} in each one
1764and tries to find the manual pages in those subdirectories. When first 1171of these directories, and tries to find the manual pages in those
1765invoked, @kbd{M-x woman} converts the value of @code{MANPATH} to a list 1172subdirectories. When first invoked, @kbd{M-x woman} converts the
1766of directory names and stores that list in the @code{woman-manpath} 1173value of @code{MANPATH} to a list of directory names and stores that
1767variable. By changing the value of this variable, you can customize the 1174list in the @code{woman-manpath} variable. Changing the value of this
1768list of directories where @code{woman} looks for manual pages. 1175variable is another way to control the list of directories used.
1769 1176
1770@vindex woman-path 1177@vindex woman-path
1771 In addition, you can augment the list of directories searched by 1178 You can also augment the list of directories searched by
1772@code{woman} by setting the value of the @code{woman-path} variable. 1179@code{woman} by setting the value of the @code{woman-path} variable.
1773This variable should hold a list of specific directories which 1180This variable should hold a list of specific directories which
1774@code{woman} should search, in addition to those in 1181@code{woman} should search, in addition to those in
1775@code{woman-manpath}. Unlike @code{woman-manpath}, the directories in 1182@code{woman-manpath}. Unlike @code{woman-manpath}, the directories in
1776@code{woman-path} are searched for the manual pages, not for @file{man*} 1183@code{woman-path} are searched for the manual pages, not for
1777subdirectories. 1184@file{man*} subdirectories.
1778 1185
1779@findex woman-find-file 1186@findex woman-find-file
1780 Occasionally, you might need to display manual pages that are not in 1187 Occasionally, you might need to display manual pages that are not in
@@ -1784,1260 +1191,189 @@ name of a manual page file, with completion, and then formats and
1784displays that file like @kbd{M-x woman} does. 1191displays that file like @kbd{M-x woman} does.
1785 1192
1786@vindex woman-dired-keys 1193@vindex woman-dired-keys
1787 First time you invoke @kbd{M-x woman}, it defines the Dired @kbd{W} 1194 The first time you invoke @kbd{M-x woman}, it defines the Dired
1788key to run the @code{woman-find-file} command on the current line's 1195@kbd{W} key to run the @code{woman-find-file} command on the current
1789file. You can disable this by setting the variable 1196line's file. You can disable this by setting the variable
1790@code{woman-dired-keys} to @code{nil}. @xref{Dired}. In addition, the 1197@code{woman-dired-keys} to @code{nil}. @xref{Dired}. In addition,
1791Tar-mode @kbd{w} key is bound to @code{woman-find-file} on the current 1198the Tar-mode @kbd{w} key is define to invoke @code{woman-find-file} on
1792line's archive member. 1199the current line's archive member.
1793 1200
1794 For more information about setting up and using @kbd{M-x woman}, see 1201 For more information about setting up and using @kbd{M-x woman}, see
1795@ref{Top, WoMan, Browse UN*X Manual Pages WithOut Man, woman, The WoMan 1202@ref{Top, WoMan, Browse UN*X Manual Pages WithOut Man, woman, The WoMan
1796Manual}. 1203Manual}.
1797 1204
1798 Eventually the GNU project hopes to replace most man pages with 1205@node Lisp Doc
1799better-organized manuals that you can browse with Info. @xref{Misc 1206@subsection Emacs Lisp Documentation Lookup
1800Help}. Since this process is only partially completed, it is still
1801useful to read manual pages.
1802
1803@node Change Log
1804@section Change Logs
1805
1806@cindex change log
1807@kindex C-x 4 a
1808@findex add-change-log-entry-other-window
1809 The Emacs command @kbd{C-x 4 a} adds a new entry to the change log
1810file for the file you are editing
1811(@code{add-change-log-entry-other-window}). If that file is actually
1812a backup file, it makes an entry appropriate for the file's
1813parent---that is useful for making log entries for functions that
1814have been deleted in the current version.
1815
1816 A change log file contains a chronological record of when and why you
1817have changed a program, consisting of a sequence of entries describing
1818individual changes. Normally it is kept in a file called
1819@file{ChangeLog} in the same directory as the file you are editing, or
1820one of its parent directories. A single @file{ChangeLog} file can
1821record changes for all the files in its directory and all its
1822subdirectories.
1823
1824 A change log entry starts with a header line that contains the
1825current date, your name, and your email address (taken from the
1826variable @code{user-mail-address}). Aside from these header lines,
1827every line in the change log starts with a space or a tab. The bulk
1828of the entry consists of @dfn{items}, each of which starts with a line
1829starting with whitespace and a star. Here are two entries, both dated
1830in May 1993, each with two items:
1831
1832@iftex
1833@medbreak
1834@end iftex
1835@smallexample
18361993-05-25 Richard Stallman <rms@@gnu.org>
1837
1838 * man.el: Rename symbols `man-*' to `Man-*'.
1839 (manual-entry): Make prompt string clearer.
1840
1841 * simple.el (blink-matching-paren-distance):
1842 Change default to 12,000.
1843
18441993-05-24 Richard Stallman <rms@@gnu.org>
1845
1846 * vc.el (minor-mode-map-alist): Don't use it if it's void.
1847 (vc-cancel-version): Doc fix.
1848@end smallexample
1849
1850 One entry can describe several changes; each change should have its
1851own item. Normally there should be a blank line between items. When
1852items are related (parts of the same change, in different places), group
1853them by leaving no blank line between them. The second entry above
1854contains two items grouped in this way.
1855
1856 @kbd{C-x 4 a} visits the change log file and creates a new entry
1857unless the most recent entry is for today's date and your name. It
1858also creates a new item for the current file. For many languages, it
1859can even guess the name of the function or other object that was
1860changed.
1861
1862@vindex add-log-keep-changes-together
1863 When the option @code{add-log-keep-changes-together} is
1864non-@code{nil}, @kbd{C-x 4 a} adds to any existing entry for the file
1865rather than starting a new entry.
1866
1867@vindex change-log-version-info-enabled
1868@vindex change-log-version-number-regexp-list
1869@cindex file version in change log entries
1870 If the value of the variable @code{change-log-version-info-enabled}
1871is non-@code{nil}, @kbd{C-x 4 a} adds the file's version number to the
1872change log entry. It finds the version number by searching the first
1873ten percent of the file, using regular expressions from the variable
1874@code{change-log-version-number-regexp-list}.
1875
1876@cindex Change Log mode
1877@findex change-log-mode
1878 The change log file is visited in Change Log mode. In this major
1879mode, each bunch of grouped items counts as one paragraph, and each
1880entry is considered a page. This facilitates editing the entries.
1881@kbd{C-j} and auto-fill indent each new line like the previous line;
1882this is convenient for entering the contents of an entry.
1883
1884@findex change-log-merge
1885 You can use the command @kbd{M-x change-log-merge} to merge other
1886log files into a buffer in Change Log Mode, preserving the date
1887ordering of entries.
1888
1889@findex change-log-redate
1890@cindex converting change log date style
1891 Versions of Emacs before 20.1 used a different format for the time of
1892the change log entry:
1893
1894@smallexample
1895Fri May 25 11:23:23 1993 Richard Stallman <rms@@gnu.org>
1896@end smallexample
1897
1898@noindent
1899The @kbd{M-x change-log-redate} command converts all the old-style
1900date entries in the change log file visited in the current buffer to
1901the new format, to make the file uniform in style. This is handy when
1902entries are contributed by many different people, some of whom use old
1903versions of Emacs.
1904
1905 Version control systems are another way to keep track of changes in your
1906program and keep a change log. @xref{Log Buffer}.
1907
1908@node Authors
1909@section @file{AUTHORS} files
1910@cindex @file{AUTHORS} file
1911
1912 Programs which have many contributors usually include a file named
1913@file{AUTHORS} in their distribution, which lists the individual
1914contributions. Emacs has a special command for maintaining the
1915@file{AUTHORS} file that is part of the Emacs distribution.
1916
1917@findex authors
1918 The @kbd{M-x authors} command prompts for the name of the root of the
1919Emacs source directory. It then scans @file{ChageLog} files and Lisp
1920source files under that directory for information about authors of
1921individual packages and people who made changes in source files, and
1922puts the information it gleans into a buffer named @samp{*Authors*}.
1923You can then edit the contents of that buffer and merge it with the
1924exisiting @file{AUTHORS} file.
1925
1926 Do not assume that this command finds all the contributors; don't
1927assume that a person not listed in the output was not a contributor.
1928If you merged in someone's contribution and did not put his name
1929in the change log, he won't show up in @kbd{M-x authors} either.
1930
1931@node Tags
1932@section Tags Tables
1933@cindex tags table
1934
1935 A @dfn{tags table} is a description of how a multi-file program is
1936broken up into files. It lists the names of the component files and the
1937names and positions of the functions (or other named subunits) in each
1938file. Grouping the related files makes it possible to search or replace
1939through all the files with one command. Recording the function names
1940and positions makes possible the @kbd{M-.} command which finds the
1941definition of a function by looking up which of the files it is in.
1942
1943 Tags tables are stored in files called @dfn{tags table files}. The
1944conventional name for a tags table file is @file{TAGS}.
1945
1946 Each entry in the tags table records the name of one tag, the name of the
1947file that the tag is defined in (implicitly), and the position in that file
1948of the tag's definition.
1949
1950 Just what names from the described files are recorded in the tags table
1951depends on the programming language of the described file. They
1952normally include all file names, functions and subroutines, and may
1953also include global variables, data types, and anything else
1954convenient. Each name recorded is called a @dfn{tag}.
1955
1956@cindex C++ class browser, tags
1957@cindex tags, C++
1958@cindex class browser, C++
1959@cindex Ebrowse
1960 See also the Ebrowse facility, which is tailored for C++.
1961@xref{Top,, Ebrowse, ebrowse, Ebrowse User's Manual}.
1962
1963@menu
1964* Tag Syntax:: Tag syntax for various types of code and text files.
1965* Create Tags Table:: Creating a tags table with @code{etags}.
1966* Etags Regexps:: Create arbitrary tags using regular expressions.
1967* Select Tags Table:: How to visit a tags table.
1968* Find Tag:: Commands to find the definition of a specific tag.
1969* Tags Search:: Using a tags table for searching and replacing.
1970* List Tags:: Listing and finding tags defined in a file.
1971@end menu
1972
1973@node Tag Syntax
1974@subsection Source File Tag Syntax
1975
1976 Here is how tag syntax is defined for the most popular languages:
1977
1978@itemize @bullet
1979@item
1980In C code, any C function or typedef is a tag, and so are definitions of
1981@code{struct}, @code{union} and @code{enum}.
1982@code{#define} macro definitions and @code{enum} constants are also
1983tags, unless you specify @samp{--no-defines} when making the tags table.
1984Similarly, global variables are tags, unless you specify
1985@samp{--no-globals}. Use of @samp{--no-globals} and @samp{--no-defines}
1986can make the tags table file much smaller.
1987
1988You can tag function declarations and external variables in addition
1989to function definitions by giving the @samp{--declarations} option to
1990@code{etags}.
1991
1992@item
1993In C++ code, in addition to all the tag constructs of C code, member
1994functions are also recognized, and optionally member variables if you
1995use the @samp{--members} option. Tags for variables and functions in
1996classes are named @samp{@var{class}::@var{variable}} and
1997@samp{@var{class}::@var{function}}. @code{operator} definitions have
1998tag names like @samp{operator+}.
1999
2000@item
2001In Java code, tags include all the constructs recognized in C++, plus
2002the @code{interface}, @code{extends} and @code{implements} constructs.
2003Tags for variables and functions in classes are named
2004@samp{@var{class}.@var{variable}} and @samp{@var{class}.@var{function}}.
2005
2006@item
2007In La@TeX{} text, the argument of any of the commands @code{\chapter},
2008@code{\section}, @code{\subsection}, @code{\subsubsection},
2009@code{\eqno}, @code{\label}, @code{\ref}, @code{\cite}, @code{\bibitem},
2010@code{\part}, @code{\appendix}, @code{\entry}, or @code{\index}, is a
2011tag.@refill
2012
2013Other commands can make tags as well, if you specify them in the
2014environment variable @env{TEXTAGS} before invoking @code{etags}. The
2015value of this environment variable should be a colon-separated list of
2016command names. For example,
2017
2018@example
2019TEXTAGS="def:newcommand:newenvironment"
2020export TEXTAGS
2021@end example
2022
2023@noindent
2024specifies (using Bourne shell syntax) that the commands @samp{\def},
2025@samp{\newcommand} and @samp{\newenvironment} also define tags.
2026
2027@item
2028In Lisp code, any function defined with @code{defun}, any variable
2029defined with @code{defvar} or @code{defconst}, and in general the first
2030argument of any expression that starts with @samp{(def} in column zero, is
2031a tag.
2032
2033@item
2034In Scheme code, tags include anything defined with @code{def} or with a
2035construct whose name starts with @samp{def}. They also include variables
2036set with @code{set!} at top level in the file.
2037@end itemize
2038
2039 Several other languages are also supported:
2040
2041@itemize @bullet
2042
2043@item
2044In Ada code, functions, procedures, packages, tasks, and types are
2045tags. Use the @samp{--packages-only} option to create tags for
2046packages only.
2047
2048In Ada, the same name can be used for different kinds of entity
2049(e.g.@:, for a procedure and for a function). Also, for things like
2050packages, procedures and functions, there is the spec (i.e.@: the
2051interface) and the body (i.e.@: the implementation). To make it
2052easier to pick the definition you want, Ada tag name have suffixes
2053indicating the type of entity:
2054
2055@table @samp
2056@item /b
2057package body.
2058@item /f
2059function.
2060@item /k
2061task.
2062@item /p
2063procedure.
2064@item /s
2065package spec.
2066@item /t
2067type.
2068@end table
2069
2070 Thus, @kbd{M-x find-tag @key{RET} bidule/b @key{RET}} will go
2071directly to the body of the package @code{bidule}, while @kbd{M-x
2072find-tag @key{RET} bidule @key{RET}} will just search for any tag
2073@code{bidule}.
2074
2075@item
2076In assembler code, labels appearing at the beginning of a line,
2077followed by a colon, are tags.
2078
2079@item
2080In Bison or Yacc input files, each rule defines as a tag the nonterminal
2081it constructs. The portions of the file that contain C code are parsed
2082as C code.
2083
2084@item
2085In Cobol code, tags are paragraph names; that is, any word starting in
2086column 8 and followed by a period.
2087
2088@item
2089In Erlang code, the tags are the functions, records, and macros defined
2090in the file.
2091
2092@item
2093In Fortran code, functions, subroutines and blockdata are tags.
2094
2095@item
2096In makefiles, targets are tags.
2097
2098@item
2099In Objective C code, tags include Objective C definitions for classes,
2100class categories, methods, and protocols.
2101
2102@item
2103In Pascal code, the tags are the functions and procedures defined in
2104the file.
2105
2106@item
2107In Perl code, the tags are the procedures defined by the @code{sub},
2108@code{my} and @code{local} keywords. Use @samp{--globals} if you want
2109to tag global variables.
2110
2111@item
2112In PostScript code, the tags are the functions.
2113
2114@item
2115In Prolog code, a tag name appears at the left margin.
2116
2117@item
2118In Python code, @code{def} or @code{class} at the beginning of a line
2119generate a tag.
2120@end itemize
2121
2122 You can also generate tags based on regexp matching (@pxref{Etags
2123Regexps}) to handle other formats and languages.
2124
2125@node Create Tags Table
2126@subsection Creating Tags Tables
2127@cindex @code{etags} program
2128
2129 The @code{etags} program is used to create a tags table file. It knows
2130the syntax of several languages, as described in
2131@iftex
2132the previous section.
2133@end iftex
2134@ifinfo
2135@ref{Tag Syntax}.
2136@end ifinfo
2137Here is how to run @code{etags}:
2138
2139@example
2140etags @var{inputfiles}@dots{}
2141@end example
2142
2143@noindent
2144The @code{etags} program reads the specified files, and writes a tags
2145table named @file{TAGS} in the current working directory.
2146
2147 If the specified files don't exist, @code{etags} looks for
2148compressed versions of them and uncompresses them to read them. Under
2149MS-DOS, @code{etags} also looks for file names like @file{mycode.cgz}
2150if it is given @samp{mycode.c} on the command line and @file{mycode.c}
2151does not exist.
2152
2153 @code{etags} recognizes the language used in an input file based on
2154its file name and contents. You can specify the language with the
2155@samp{--language=@var{name}} option, described below.
2156
2157 If the tags table data become outdated due to changes in the files
2158described in the table, the way to update the tags table is the same
2159way it was made in the first place. But it is not necessary to do
2160this very often.
2161
2162 If the tags table fails to record a tag, or records it for the wrong
2163file, then Emacs cannot possibly find its definition. However, if the
2164position recorded in the tags table becomes a little bit wrong (due to
2165some editing in the file that the tag definition is in), the only
2166consequence is a slight delay in finding the tag. Even if the stored
2167position is very wrong, Emacs will still find the tag, but it must
2168search the entire file for it.
2169
2170 So you should update a tags table when you define new tags that you want
2171to have listed, or when you move tag definitions from one file to another,
2172or when changes become substantial. Normally there is no need to update
2173the tags table after each edit, or even every day.
2174
2175 One tags table can virtually include another. Specify the included
2176tags file name with the @samp{--include=@var{file}} option when
2177creating the file that is to include it. The latter file then acts as
2178if it covered all the source files specified in the included file, as
2179well as the files it directly contains.
2180
2181 If you specify the source files with relative file names when you run
2182@code{etags}, the tags file will contain file names relative to the
2183directory where the tags file was initially written. This way, you can
2184move an entire directory tree containing both the tags file and the
2185source files, and the tags file will still refer correctly to the source
2186files.
2187
2188 If you specify absolute file names as arguments to @code{etags}, then
2189the tags file will contain absolute file names. This way, the tags file
2190will still refer to the same files even if you move it, as long as the
2191source files remain in the same place. Absolute file names start with
2192@samp{/}, or with @samp{@var{device}:/} on MS-DOS and MS-Windows.
2193
2194 When you want to make a tags table from a great number of files, you
2195may have problems listing them on the command line, because some systems
2196have a limit on its length. The simplest way to circumvent this limit
2197is to tell @code{etags} to read the file names from its standard input,
2198by typing a dash in place of the file names, like this:
2199
2200@smallexample
2201find . -name "*.[chCH]" -print | etags -
2202@end smallexample
2203
2204 Use the option @samp{--language=@var{name}} to specify the language
2205explicitly. You can intermix these options with file names; each one
2206applies to the file names that follow it. Specify
2207@samp{--language=auto} to tell @code{etags} to resume guessing the
2208language from the file names and file contents. Specify
2209@samp{--language=none} to turn off language-specific processing
2210entirely; then @code{etags} recognizes tags by regexp matching alone
2211(@pxref{Etags Regexps}).
2212
2213 @samp{etags --help} prints the list of the languages @code{etags}
2214knows, and the file name rules for guessing the language. It also prints
2215a list of all the available @code{etags} options, together with a short
2216explanation.
2217
2218@node Etags Regexps
2219@subsection Etags Regexps
2220
2221 The @samp{--regex} option provides a general way of recognizing tags
2222based on regexp matching. You can freely intermix it with file names.
2223Each @samp{--regex} option adds to the preceding ones, and applies only
2224to the following files. The syntax is:
2225
2226@smallexample
2227--regex=/@var{tagregexp}[/@var{nameregexp}]/
2228@end smallexample
2229
2230@noindent
2231where @var{tagregexp} is used to match the lines to tag. It is always
2232anchored, that is, it behaves as if preceded by @samp{^}. If you want
2233to account for indentation, just match any initial number of blanks by
2234beginning your regular expression with @samp{[ \t]*}. In the regular
2235expressions, @samp{\} quotes the next character, and @samp{\t} stands
2236for the tab character. Note that @code{etags} does not handle the other
2237C escape sequences for special characters.
2238
2239@cindex interval operator (in regexps)
2240 The syntax of regular expressions in @code{etags} is the same as in
2241Emacs, augmented with the @dfn{interval operator}, which works as in
2242@code{grep} and @code{ed}. The syntax of an interval operator is
2243@samp{\@{@var{m},@var{n}\@}}, and its meaning is to match the preceding
2244expression at least @var{m} times and up to @var{n} times.
2245
2246 You should not match more characters with @var{tagregexp} than that
2247needed to recognize what you want to tag. If the match is such that
2248more characters than needed are unavoidably matched by @var{tagregexp}
2249(as will usually be the case), you should add a @var{nameregexp}, to
2250pick out just the tag. This will enable Emacs to find tags more
2251accurately and to do completion on tag names more reliably. You can
2252find some examples below.
2253
2254 The option @samp{--ignore-case-regex} (or @samp{-c}) works like
2255@samp{--regex}, except that matching ignores case. This is
2256appropriate for certain programming languages.
2257
2258 The @samp{-R} option deletes all the regexps defined with
2259@samp{--regex} options. It applies to the file names following it, as
2260you can see from the following example:
2261
2262@smallexample
2263etags --regex=/@var{reg1}/ voo.doo --regex=/@var{reg2}/ \
2264 bar.ber -R --lang=lisp los.er
2265@end smallexample
2266
2267@noindent
2268Here @code{etags} chooses the parsing language for @file{voo.doo} and
2269@file{bar.ber} according to their contents. @code{etags} also uses
2270@var{reg1} to recognize additional tags in @file{voo.doo}, and both
2271@var{reg1} and @var{reg2} to recognize additional tags in
2272@file{bar.ber}. @code{etags} uses the Lisp tags rules, and no regexp
2273matching, to recognize tags in @file{los.er}.
2274
2275 You can specify a regular expression for a particular language, by
2276writing @samp{@{lang@}} in front of it. Then @code{etags} will use
2277the regular expression only for files of that language. (@samp{etags
2278--help} prints the list of languages recognised by @code{etags}.) The
2279following example tags the @code{DEFVAR} macros in the Emacs source
2280files, for the C language only:
2281
2282@smallexample
2283--regex='@{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
2284@end smallexample
2285
2286@noindent
2287This feature is particularly useful when you store a list of regular
2288expressions in a file. The following option syntax instructs
2289@code{etags} to read two files of regular expressions. The regular
2290expressions contained in the second file are matched without regard to
2291case.
2292
2293@smallexample
2294--regex=@@first-file --ignore-case-regex=@@second-file
2295@end smallexample
2296
2297@noindent
2298A regex file contains one regular expressions per line. Empty lines,
2299and lines beginning with space or tab are ignored. When the first
2300character in a line is @samp{@@}, @code{etags} assumes that the rest
2301of the line is the name of a file of regular expressions; thus, one
2302such file can include another file. All the other lines are taken to
2303be regular expressions. If the first non-whitespace text on the line
2304is @samp{--}, that line is a comment.
2305
2306 For example, one can create a file called @samp{emacs.tags} with the
2307following contents:
2308
2309@smallexample
2310 -- This is for GNU Emacs C source files
2311@{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/\1/
2312@end smallexample
2313
2314@noindent
2315and then use it like this:
2316
2317@smallexample
2318etags --regex=@@emacs.tags *.[ch] */*.[ch]
2319@end smallexample
2320
2321 Here are some more examples. The regexps are quoted to protect them
2322from shell interpretation.
2323
2324@itemize @bullet
2325
2326@item
2327Tag Octave files:
2328
2329@smallexample
2330etags --language=none \
2331 --regex='/[ \t]*function.*=[ \t]*\([^ \t]*\)[ \t]*(/\1/' \
2332 --regex='/###key \(.*\)/\1/' \
2333 --regex='/[ \t]*global[ \t].*/' \
2334 *.m
2335@end smallexample
2336
2337@noindent
2338Note that tags are not generated for scripts, so that you have to add
2339a line by yourself of the form @samp{###key @var{scriptname}} if you
2340want to jump to it.
2341
2342@item
2343Tag Tcl files:
2344
2345@smallexample
2346etags --language=none --regex='/proc[ \t]+\([^ \t]+\)/\1/' *.tcl
2347@end smallexample
2348
2349@item
2350Tag VHDL files:
2351
2352@smallexample
2353etags --language=none \
2354 --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/' \
2355 --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\
2356 \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
2357@end smallexample
2358@end itemize
2359
2360@node Select Tags Table
2361@subsection Selecting a Tags Table
2362
2363@vindex tags-file-name
2364@findex visit-tags-table
2365 Emacs has at any time one @dfn{selected} tags table, and all the commands
2366for working with tags tables use the selected one. To select a tags table,
2367type @kbd{M-x visit-tags-table}, which reads the tags table file name as an
2368argument. The name @file{TAGS} in the default directory is used as the
2369default file name.
2370
2371 All this command does is store the file name in the variable
2372@code{tags-file-name}. Emacs does not actually read in the tags table
2373contents until you try to use them. Setting this variable yourself is just
2374as good as using @code{visit-tags-table}. The variable's initial value is
2375@code{nil}; that value tells all the commands for working with tags tables
2376that they must ask for a tags table file name to use.
2377
2378 Using @code{visit-tags-table} when a tags table is already loaded
2379gives you a choice: you can add the new tags table to the current list
2380of tags tables, or start a new list. The tags commands use all the tags
2381tables in the current list. If you start a new list, the new tags table
2382is used @emph{instead} of others. If you add the new table to the
2383current list, it is used @emph{as well as} the others. When the tags
2384commands scan the list of tags tables, they don't always start at the
2385beginning of the list; they start with the first tags table (if any)
2386that describes the current file, proceed from there to the end of the
2387list, and then scan from the beginning of the list until they have
2388covered all the tables in the list.
2389
2390@vindex tags-table-list
2391 You can specify a precise list of tags tables by setting the variable
2392@code{tags-table-list} to a list of strings, like this:
2393
2394@c keep this on two lines for formatting in smallbook
2395@example
2396@group
2397(setq tags-table-list
2398 '("~/emacs" "/usr/local/lib/emacs/src"))
2399@end group
2400@end example
2401
2402@noindent
2403This tells the tags commands to look at the @file{TAGS} files in your
2404@file{~/emacs} directory and in the @file{/usr/local/lib/emacs/src}
2405directory. The order depends on which file you are in and which tags
2406table mentions that file, as explained above.
2407
2408 Do not set both @code{tags-file-name} and @code{tags-table-list}.
2409
2410@node Find Tag
2411@subsection Finding a Tag
2412
2413 The most important thing that a tags table enables you to do is to find
2414the definition of a specific tag.
2415
2416@table @kbd
2417@item M-.@: @var{tag} @key{RET}
2418Find first definition of @var{tag} (@code{find-tag}).
2419@item C-u M-.
2420Find next alternate definition of last tag specified.
2421@item C-u - M-.
2422Go back to previous tag found.
2423@item C-M-. @var{pattern} @key{RET}
2424Find a tag whose name matches @var{pattern} (@code{find-tag-regexp}).
2425@item C-u C-M-.
2426Find the next tag whose name matches the last pattern used.
2427@item C-x 4 .@: @var{tag} @key{RET}
2428Find first definition of @var{tag}, but display it in another window
2429(@code{find-tag-other-window}).
2430@item C-x 5 .@: @var{tag} @key{RET}
2431Find first definition of @var{tag}, and create a new frame to select the
2432buffer (@code{find-tag-other-frame}).
2433@item M-*
2434Pop back to where you previously invoked @kbd{M-.} and friends.
2435@end table
2436
2437@kindex M-.
2438@findex find-tag
2439 @kbd{M-.}@: (@code{find-tag}) is the command to find the definition of
2440a specified tag. It searches through the tags table for that tag, as a
2441string, and then uses the tags table info to determine the file that the
2442definition is in and the approximate character position in the file of
2443the definition. Then @code{find-tag} visits that file, moves point to
2444the approximate character position, and searches ever-increasing
2445distances away to find the tag definition.
2446
2447 If an empty argument is given (just type @key{RET}), the sexp in the
2448buffer before or around point is used as the @var{tag} argument.
2449@xref{Lists}, for info on sexps.
2450
2451 You don't need to give @kbd{M-.} the full name of the tag; a part
2452will do. This is because @kbd{M-.} finds tags in the table which
2453contain @var{tag} as a substring. However, it prefers an exact match
2454to a substring match. To find other tags that match the same
2455substring, give @code{find-tag} a numeric argument, as in @kbd{C-u
2456M-.}; this does not read a tag name, but continues searching the tags
2457table's text for another tag containing the same substring last used.
2458If you have a real @key{META} key, @kbd{M-0 M-.}@: is an easier
2459alternative to @kbd{C-u M-.}.
2460
2461@kindex C-x 4 .
2462@findex find-tag-other-window
2463@kindex C-x 5 .
2464@findex find-tag-other-frame
2465 Like most commands that can switch buffers, @code{find-tag} has a
2466variant that displays the new buffer in another window, and one that
2467makes a new frame for it. The former is @kbd{C-x 4 .}, which invokes
2468the command @code{find-tag-other-window}. The latter is @kbd{C-x 5 .},
2469which invokes @code{find-tag-other-frame}.
2470
2471 To move back to places you've found tags recently, use @kbd{C-u -
2472M-.}; more generally, @kbd{M-.} with a negative numeric argument. This
2473command can take you to another buffer. @kbd{C-x 4 .} with a negative
2474argument finds the previous tag location in another window.
2475
2476@kindex M-*
2477@findex pop-tag-mark
2478@vindex find-tag-marker-ring-length
2479 As well as going back to places you've found tags recently, you can go
2480back to places @emph{from where} you found them. Use @kbd{M-*}, which
2481invokes the command @code{pop-tag-mark}, for this. Typically you would
2482find and study the definition of something with @kbd{M-.} and then
2483return to where you were with @kbd{M-*}.
2484
2485 Both @kbd{C-u - M-.} and @kbd{M-*} allow you to retrace your steps to
2486a depth determined by the variable @code{find-tag-marker-ring-length}.
2487
2488@findex find-tag-regexp
2489@kindex C-M-.
2490 The command @kbd{C-M-.} (@code{find-tag-regexp}) visits the tags that
2491match a specified regular expression. It is just like @kbd{M-.} except
2492that it does regexp matching instead of substring matching.
2493
2494@node Tags Search
2495@subsection Searching and Replacing with Tags Tables
2496@cindex search and replace in multiple files
2497@cindex multiple-file search and replace
2498
2499 The commands in this section visit and search all the files listed in the
2500selected tags table, one by one. For these commands, the tags table serves
2501only to specify a sequence of files to search.
2502
2503@table @kbd
2504@item M-x tags-search @key{RET} @var{regexp} @key{RET}
2505Search for @var{regexp} through the files in the selected tags
2506table.
2507@item M-x tags-query-replace @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
2508Perform a @code{query-replace-regexp} on each file in the selected tags table.
2509@item M-,
2510Restart one of the commands above, from the current location of point
2511(@code{tags-loop-continue}).
2512@end table
2513
2514@findex tags-search
2515 @kbd{M-x tags-search} reads a regexp using the minibuffer, then
2516searches for matches in all the files in the selected tags table, one
2517file at a time. It displays the name of the file being searched so you
2518can follow its progress. As soon as it finds an occurrence,
2519@code{tags-search} returns.
2520
2521@kindex M-,
2522@findex tags-loop-continue
2523 Having found one match, you probably want to find all the rest. To find
2524one more match, type @kbd{M-,} (@code{tags-loop-continue}) to resume the
2525@code{tags-search}. This searches the rest of the current buffer, followed
2526by the remaining files of the tags table.@refill
2527
2528@findex tags-query-replace
2529 @kbd{M-x tags-query-replace} performs a single
2530@code{query-replace-regexp} through all the files in the tags table. It
2531reads a regexp to search for and a string to replace with, just like
2532ordinary @kbd{M-x query-replace-regexp}. It searches much like @kbd{M-x
2533tags-search}, but repeatedly, processing matches according to your
2534input. @xref{Replace}, for more information on query replace.
2535
2536@vindex tags-case-fold-search
2537@cindex case-sensitivity and tags search
2538 You can control the case-sensitivity of tags search commands by
2539customizing the value of the variable @code{tags-case-fold-search}. The
2540default is to use the same setting as the value of
2541@code{case-fold-search} (@pxref{Search Case}).
2542
2543 It is possible to get through all the files in the tags table with a
2544single invocation of @kbd{M-x tags-query-replace}. But often it is
2545useful to exit temporarily, which you can do with any input event that
2546has no special query replace meaning. You can resume the query replace
2547subsequently by typing @kbd{M-,}; this command resumes the last tags
2548search or replace command that you did.
2549
2550 The commands in this section carry out much broader searches than the
2551@code{find-tag} family. The @code{find-tag} commands search only for
2552definitions of tags that match your substring or regexp. The commands
2553@code{tags-search} and @code{tags-query-replace} find every occurrence
2554of the regexp, as ordinary search commands and replace commands do in
2555the current buffer.
2556
2557 These commands create buffers only temporarily for the files that they
2558have to search (those which are not already visited in Emacs buffers).
2559Buffers in which no match is found are quickly killed; the others
2560continue to exist.
2561
2562 It may have struck you that @code{tags-search} is a lot like
2563@code{grep}. You can also run @code{grep} itself as an inferior of
2564Emacs and have Emacs show you the matching lines one by one. This works
2565much like running a compilation; finding the source locations of the
2566@code{grep} matches works like finding the compilation errors.
2567@xref{Compilation}.
2568
2569@node List Tags
2570@subsection Tags Table Inquiries
2571
2572@table @kbd
2573@item M-x list-tags @key{RET} @var{file} @key{RET}
2574Display a list of the tags defined in the program file @var{file}.
2575@item M-x tags-apropos @key{RET} @var{regexp} @key{RET}
2576Display a list of all tags matching @var{regexp}.
2577@end table
2578
2579@findex list-tags
2580 @kbd{M-x list-tags} reads the name of one of the files described by
2581the selected tags table, and displays a list of all the tags defined in
2582that file. The ``file name'' argument is really just a string to
2583compare against the file names recorded in the tags table; it is read as
2584a string rather than as a file name. Therefore, completion and
2585defaulting are not available, and you must enter the file name the same
2586way it appears in the tags table. Do not include a directory as part of
2587the file name unless the file name recorded in the tags table includes a
2588directory.
2589
2590@findex tags-apropos
2591@vindex tags-apropos-verbose
2592 @kbd{M-x tags-apropos} is like @code{apropos} for tags
2593(@pxref{Apropos}). It finds all the tags in the selected tags table
2594whose entries match @var{regexp}, and displays them. If the variable
2595@code{tags-apropos-verbose} is non-@code{nil}, it displays the names
2596of the tags files together with the tag names.
2597
2598@vindex tags-tag-face
2599@vindex tags-apropos-additional-actions
2600You can customize the appearance of the output with the face
2601@code{tags-tag-face}. You can display additional output with @kbd{M-x
2602tags-apropos} by customizing the variable
2603@code{tags-apropos-additional-actions}---see its documentation for
2604details.
2605
2606 You can also use the collection of tag names to complete a symbol
2607name in the buffer. @xref{Symbol Completion}.
2608
2609@node Imenu
2610@section Imenu
2611@cindex indexes of buffer contents
2612@cindex buffer content indexes
2613@cindex tags
2614
2615 The Imenu facility is another way to find definitions or sections
2616in a file. It is similar in spirit to Tags, but operates on a single
2617buffer only, and works entirely within Emacs with no need for a separate
2618tags table.
2619 1207
2620@findex imenu 1208 As you edit Lisp code to be run in Emacs, you can use the commands
2621@findex imenu-add-menu-bar-index 1209@kbd{C-h f} (@code{describe-function}) and @kbd{C-h v}
2622 If you type @kbd{M-x imenu}, it reads the name of a section or 1210(@code{describe-variable}) to view documentation of functions and
2623definition in the current buffer, then goes to that section or 1211variables that you want to use. These commands use the minibuffer to
2624definition. You can use completion to specify the name, and a 1212read the name of a function or variable to document, and display the
2625complete list of possible names is always displayed. 1213documentation in a window. Their default arguments are based on the
1214code in the neighborhood of point. For @kbd{C-h f}, the default is
1215the function called in the innermost list containing point. @kbd{C-h
1216v} uses the symbol name around or adjacent to point as its default.
2626 1217
2627 Alternatively you can bind the command @code{imenu} to a mouse 1218@cindex Eldoc mode
2628click. Then it displays mouse menus for you to select the section or 1219@findex eldoc-mode
2629definition you want. You can also add the buffer's index to the menu 1220 A more automatic but less powerful method is Eldoc mode. This minor
2630bar by calling @code{imenu-add-menu-bar-index}. If you want to have 1221mode constantly displays in the echo area the argument list for the
2631this menu bar item available for all buffers in a certain major mode, 1222function being called at point. (In other words, it finds the
2632you can do this by adding @code{imenu-add-menu-bar-index} to its mode 1223function call that point is contained in, and displays the argument
2633hook. But then you will have to wait for the buffer to be searched 1224list of that function.) Eldoc mode applies in Emacs Lisp and Lisp
2634for sections and definitions, each time you visit a file which uses 1225Interaction modes only. Use the command @kbd{M-x eldoc-mode} to
2635that mode. 1226enable or disable this feature.
2636
2637@vindex imenu-auto-rescan
2638 When you change the contents of a buffer, if you add or delete
2639definitions or sections, you can update the buffer's index to
2640correspond to the new contents by invoking the @samp{*Rescan*} item in
2641the menu. Rescanning happens automatically if
2642@code{imenu-auto-rescan} is non-@code{nil}. There is no need to
2643rescan because of small changes in the text.
2644
2645@vindex imenu-sort-function
2646 You can customize the way the menus are sorted via the variable
2647@code{imenu-sort-function}. By default names are ordered as they
2648occur in the buffer; alphabetic sorting is provided as an alternative.
2649
2650 Imenu provides the information to guide Which Function mode
2651(@pxref{Which Function}). The Speedbar can also use it
2652(@pxref{Speedbar}).
2653
2654@node Emerge, C Modes, Imenu, Programs
2655@section Merging Files with Emerge
2656@cindex Emerge
2657@cindex merging files
2658
2659It's not unusual for programmers to get their signals crossed and modify
2660the same program in two different directions. To recover from this
2661confusion, you need to merge the two versions. Emerge makes this
2662easier. See also @ref{Comparing Files}, for commands to compare
2663in a more manual fashion, and @ref{,Ediff,, ediff, The Ediff Manual}.
2664 1227
2665@menu 1228@node Hideshow
2666* Overview of Emerge:: How to start Emerge. Basic concepts. 1229@section Hideshow minor mode
2667* Submodes of Emerge:: Fast mode vs. Edit mode.
2668 Skip Prefers mode and Auto Advance mode.
2669* State of Difference:: You do the merge by specifying state A or B
2670 for each difference.
2671* Merge Commands:: Commands for selecting a difference,
2672 changing states of differences, etc.
2673* Exiting Emerge:: What to do when you've finished the merge.
2674* Combining in Emerge:: How to keep both alternatives for a difference.
2675* Fine Points of Emerge:: Misc.
2676@end menu
2677 1230
2678@node Overview of Emerge 1231@findex hs-minor-mode
2679@subsection Overview of Emerge 1232 Hideshow minor mode provides selective display of portions of a
1233program, known as @dfn{blocks}. You can use @kbd{M-x hs-minor-mode}
1234to enable or disable this mode, or add @code{hs-minor-mode} to the
1235mode hook for certain major modes in order to enable it automatically
1236for those modes.
2680 1237
2681To start Emerge, run one of these four commands: 1238 Just what constitutes a block depends on the major mode. In C mode
1239or C++ mode, they are delimited by braces, while in Lisp mode and
1240similar modes they are delimited by parentheses. Multi-line comments
1241also count as blocks.
2682 1242
1243@findex hs-hide-all
1244@findex hs-hide-block
1245@findex hs-show-all
1246@findex hs-show-block
1247@findex hs-show-region
1248@findex hs-hide-level
1249@findex hs-minor-mode
1250@kindex C-c @@ C-h
1251@kindex C-c @@ C-s
1252@kindex C-c @@ C-M-h
1253@kindex C-c @@ C-M-s
1254@kindex C-c @@ C-r
1255@kindex C-c @@ C-l
1256@kindex S-Mouse-2
2683@table @kbd 1257@table @kbd
2684@item M-x emerge-files 1258@item C-c @@ C-h
2685@findex emerge-files 1259Hide the current block (@code{hs-hide-block}).
2686Merge two specified files. 1260@item C-c @@ C-s
2687 1261Show the current block (@code{hs-show-block}).
2688@item M-x emerge-files-with-ancestor 1262@item C-c @@ C-c
2689@findex emerge-files-with-ancestor 1263Either hide or show the current block (@code{hs-toggle-hiding})
2690Merge two specified files, with reference to a common ancestor. 1264@item S-Mouse-2
2691 1265Either hide or show the block you click on (@code{hs-mouse-toggle-hiding})
2692@item M-x emerge-buffers 1266@item C-c @@ C-M-h
2693@findex emerge-buffers 1267Hide all top-level blocks (@code{hs-hide-all}).
2694Merge two buffers. 1268@item C-c @@ C-M-s
2695 1269Show everything in the buffer (@code{hs-show-all}).
2696@item M-x emerge-buffers-with-ancestor 1270@item C-c @@ C-l
2697@findex emerge-buffers-with-ancestor 1271Hide all blocks @var{n} levels below this block
2698Merge two buffers with reference to a common ancestor in a third 1272(@code{hs-hide-level}).
2699buffer.
2700@end table
2701
2702@cindex merge buffer (Emerge)
2703@cindex A and B buffers (Emerge)
2704 The Emerge commands compare two files or buffers, and display the
2705comparison in three buffers: one for each input text (the @dfn{A buffer}
2706and the @dfn{B buffer}), and one (the @dfn{merge buffer}) where merging
2707takes place. The merge buffer shows the full merged text, not just the
2708differences. Wherever the two input texts differ, you can choose which
2709one of them to include in the merge buffer.
2710
2711 The Emerge commands that take input from existing buffers use only the
2712accessible portions of those buffers, if they are narrowed
2713(@pxref{Narrowing}).
2714
2715 If a common ancestor version is available, from which the two texts to
2716be merged were both derived, Emerge can use it to guess which
2717alternative is right. Wherever one current version agrees with the
2718ancestor, Emerge presumes that the other current version is a deliberate
2719change which should be kept in the merged version. Use the
2720@samp{with-ancestor} commands if you want to specify a common ancestor
2721text. These commands read three file or buffer names---variant A,
2722variant B, and the common ancestor.
2723
2724 After the comparison is done and the buffers are prepared, the
2725interactive merging starts. You control the merging by typing special
2726@dfn{merge commands} in the merge buffer. The merge buffer shows you a
2727full merged text, not just differences. For each run of differences
2728between the input texts, you can choose which one of them to keep, or
2729edit them both together.
2730
2731 The merge buffer uses a special major mode, Emerge mode, with commands
2732for making these choices. But you can also edit the buffer with
2733ordinary Emacs commands.
2734
2735 At any given time, the attention of Emerge is focused on one
2736particular difference, called the @dfn{selected} difference. This
2737difference is marked off in the three buffers like this:
2738
2739@example
2740vvvvvvvvvvvvvvvvvvvv
2741@var{text that differs}
2742^^^^^^^^^^^^^^^^^^^^
2743@end example
2744
2745@noindent
2746Emerge numbers all the differences sequentially and the mode
2747line always shows the number of the selected difference.
2748
2749 Normally, the merge buffer starts out with the A version of the text.
2750But when the A version of a difference agrees with the common ancestor,
2751then the B version is initially preferred for that difference.
2752
2753 Emerge leaves the merged text in the merge buffer when you exit. At
2754that point, you can save it in a file with @kbd{C-x C-w}. If you give a
2755numeric argument to @code{emerge-files} or
2756@code{emerge-files-with-ancestor}, it reads the name of the output file
2757using the minibuffer. (This is the last file name those commands read.)
2758Then exiting from Emerge saves the merged text in the output file.
2759
2760 Normally, Emerge commands save the output buffer in its file when you
2761exit. If you abort Emerge with @kbd{C-]}, the Emerge command does not
2762save the output buffer, but you can save it yourself if you wish.
2763
2764@node Submodes of Emerge
2765@subsection Submodes of Emerge
2766
2767 You can choose between two modes for giving merge commands: Fast mode
2768and Edit mode. In Fast mode, basic merge commands are single
2769characters, but ordinary Emacs commands are disabled. This is
2770convenient if you use only merge commands. In Edit mode, all merge
2771commands start with the prefix key @kbd{C-c C-c}, and the normal Emacs
2772commands are also available. This allows editing the merge buffer, but
2773slows down Emerge operations.
2774
2775 Use @kbd{e} to switch to Edit mode, and @kbd{C-c C-c f} to switch to
2776Fast mode. The mode line indicates Edit and Fast modes with @samp{E}
2777and @samp{F}.
2778
2779 Emerge has two additional submodes that affect how particular merge
2780commands work: Auto Advance mode and Skip Prefers mode.
2781
2782 If Auto Advance mode is in effect, the @kbd{a} and @kbd{b} commands
2783advance to the next difference. This lets you go through the merge
2784faster as long as you simply choose one of the alternatives from the
2785input. The mode line indicates Auto Advance mode with @samp{A}.
2786
2787 If Skip Prefers mode is in effect, the @kbd{n} and @kbd{p} commands
2788skip over differences in states prefer-A and prefer-B (@pxref{State of
2789Difference}). Thus you see only differences for which neither version
2790is presumed ``correct.'' The mode line indicates Skip Prefers mode with
2791@samp{S}.
2792
2793@findex emerge-auto-advance-mode
2794@findex emerge-skip-prefers-mode
2795 Use the command @kbd{s a} (@code{emerge-auto-advance-mode}) to set or
2796clear Auto Advance mode. Use @kbd{s s}
2797(@code{emerge-skip-prefers-mode}) to set or clear Skip Prefers mode.
2798These commands turn on the mode with a positive argument, turns it off
2799with a negative or zero argument, and toggle the mode with no argument.
2800
2801@node State of Difference
2802@subsection State of a Difference
2803
2804 In the merge buffer, a difference is marked with lines of @samp{v} and
2805@samp{^} characters. Each difference has one of these seven states:
2806
2807@table @asis
2808@item A
2809The difference is showing the A version. The @kbd{a} command always
2810produces this state; the mode line indicates it with @samp{A}.
2811
2812@item B
2813The difference is showing the B version. The @kbd{b} command always
2814produces this state; the mode line indicates it with @samp{B}.
2815
2816@item default-A
2817@itemx default-B
2818The difference is showing the A or the B state by default, because you
2819haven't made a choice. All differences start in the default-A state
2820(and thus the merge buffer is a copy of the A buffer), except those for
2821which one alternative is ``preferred'' (see below).
2822
2823When you select a difference, its state changes from default-A or
2824default-B to plain A or B. Thus, the selected difference never has
2825state default-A or default-B, and these states are never displayed in
2826the mode line.
2827
2828The command @kbd{d a} chooses default-A as the default state, and @kbd{d
2829b} chooses default-B. This chosen default applies to all differences
2830which you haven't ever selected and for which no alternative is preferred.
2831If you are moving through the merge sequentially, the differences you
2832haven't selected are those following the selected one. Thus, while
2833moving sequentially, you can effectively make the A version the default
2834for some sections of the merge buffer and the B version the default for
2835others by using @kbd{d a} and @kbd{d b} between sections.
2836
2837@item prefer-A
2838@itemx prefer-B
2839The difference is showing the A or B state because it is
2840@dfn{preferred}. This means that you haven't made an explicit choice,
2841but one alternative seems likely to be right because the other
2842alternative agrees with the common ancestor. Thus, where the A buffer
2843agrees with the common ancestor, the B version is preferred, because
2844chances are it is the one that was actually changed.
2845
2846These two states are displayed in the mode line as @samp{A*} and @samp{B*}.
2847
2848@item combined
2849The difference is showing a combination of the A and B states, as a
2850result of the @kbd{x c} or @kbd{x C} commands.
2851
2852Once a difference is in this state, the @kbd{a} and @kbd{b} commands
2853don't do anything to it unless you give them a numeric argument.
2854
2855The mode line displays this state as @samp{comb}.
2856@end table 1273@end table
2857 1274
2858@node Merge Commands 1275@vindex hs-hide-comments-when-hiding-all
2859@subsection Merge Commands 1276@vindex hs-isearch-open
2860 1277@vindex hs-special-modes-alist
2861 Here are the Merge commands for Fast mode; in Edit mode, precede them 1278 These user options exist for customizing Hideshow mode.
2862with @kbd{C-c C-c}:
2863
2864@table @kbd
2865@item p
2866Select the previous difference.
2867
2868@item n
2869Select the next difference.
2870
2871@item a
2872Choose the A version of this difference.
2873
2874@item b
2875Choose the B version of this difference.
2876
2877@item C-u @var{n} j
2878Select difference number @var{n}.
2879
2880@item .
2881Select the difference containing point. You can use this command in the
2882merge buffer or in the A or B buffer.
2883
2884@item q
2885Quit---finish the merge.
2886
2887@item C-]
2888Abort---exit merging and do not save the output.
2889
2890@item f
2891Go into Fast mode. (In Edit mode, this is actually @kbd{C-c C-c f}.)
2892
2893@item e
2894Go into Edit mode.
2895
2896@item l
2897Recenter (like @kbd{C-l}) all three windows.
2898
2899@item -
2900Specify part of a prefix numeric argument.
2901
2902@item @var{digit}
2903Also specify part of a prefix numeric argument.
2904
2905@item d a
2906Choose the A version as the default from here down in
2907the merge buffer.
2908
2909@item d b
2910Choose the B version as the default from here down in
2911the merge buffer.
2912
2913@item c a
2914Copy the A version of this difference into the kill ring.
2915
2916@item c b
2917Copy the B version of this difference into the kill ring.
2918
2919@item i a
2920Insert the A version of this difference at point.
2921
2922@item i b
2923Insert the B version of this difference at point.
2924
2925@item m
2926Put point and mark around the difference.
2927
2928@item ^
2929Scroll all three windows down (like @kbd{M-v}).
2930
2931@item v
2932Scroll all three windows up (like @kbd{C-v}).
2933
2934@item <
2935Scroll all three windows left (like @kbd{C-x <}).
2936
2937@item >
2938Scroll all three windows right (like @kbd{C-x >}).
2939
2940@item |
2941Reset horizontal scroll on all three windows.
2942
2943@item x 1
2944Shrink the merge window to one line. (Use @kbd{C-u l} to restore it
2945to full size.)
2946
2947@item x c
2948Combine the two versions of this difference (@pxref{Combining in
2949Emerge}).
2950
2951@item x f
2952Show the names of the files/buffers Emerge is operating on, in a Help
2953window. (Use @kbd{C-u l} to restore windows.)
2954
2955@item x j
2956Join this difference with the following one.
2957(@kbd{C-u x j} joins this difference with the previous one.)
2958
2959@item x s
2960Split this difference into two differences. Before you use this
2961command, position point in each of the three buffers at the place where
2962you want to split the difference.
2963 1279
2964@item x t 1280@table @code
2965Trim identical lines off the top and bottom of the difference. 1281@item hs-hide-comments-when-hiding-all
2966Such lines occur when the A and B versions are 1282Non-@code{nil} says that @kbd{hs-hide-all} should hide comments too.
2967identical but differ from the ancestor version. 1283@item hs-isearch-open
1284Specifies what kind of hidden blocks to open in Isearch mode.
1285@item hs-special-modes-alist
1286Specifies how to initialize Hideshow variables for different modes.
2968@end table 1287@end table
2969 1288
2970@node Exiting Emerge 1289@node Symbol Completion
2971@subsection Exiting Emerge 1290@section Completion for Symbol Names
1291@cindex completion (symbol names)
2972 1292
2973 The @kbd{q} command (@code{emerge-quit}) finishes the merge, storing 1293 Usually completion happens in the minibuffer. But one kind of completion
2974the results into the output file if you specified one. It restores the 1294is available in all buffers: completion for symbol names.
2975A and B buffers to their proper contents, or kills them if they were
2976created by Emerge and you haven't changed them. It also disables the
2977Emerge commands in the merge buffer, since executing them later could
2978damage the contents of the various buffers.
2979 1295
2980 @kbd{C-]} aborts the merge. This means exiting without writing the 1296@kindex M-TAB
2981output file. If you didn't specify an output file, then there is no 1297 The character @kbd{M-@key{TAB}} runs a command to complete the partial
2982real difference between aborting and finishing the merge. 1298symbol before point against the set of meaningful symbol names. Any
1299additional characters determined by the partial name are inserted at
1300point.
2983 1301
2984 If the Emerge command was called from another Lisp program, then its 1302 If the partial name in the buffer has more than one possible completion
2985return value is @code{t} for successful completion, or @code{nil} if you 1303and they have no additional characters in common, a list of all possible
2986abort. 1304completions is displayed in another window.
2987 1305
2988@node Combining in Emerge 1306@cindex tags-based completion
2989@subsection Combining the Two Versions 1307@cindex Info index completion
1308@findex complete-symbol
1309 In most programming language major modes, @kbd{M-@key{TAB}} runs the
1310command @code{complete-symbol}, which provides two kinds of completion.
1311Normally it does completion based on a tags table (@pxref{Tags}); with a
1312numeric argument (regardless of the value), it does completion based on
1313the names listed in the Info file indexes for your language. Thus, to
1314complete the name of a symbol defined in your own program, use
1315@kbd{M-@key{TAB}} with no argument; to complete the name of a standard
1316library function, use @kbd{C-u M-@key{TAB}}. Of course, Info-based
1317completion works only if there is an Info file for the standard library
1318functions of your language, and only if it is installed at your site.
2990 1319
2991 Sometimes you want to keep @emph{both} alternatives for a particular 1320@cindex Lisp symbol completion
2992difference. To do this, use @kbd{x c}, which edits the merge buffer 1321@cindex completion (Lisp symbols)
2993like this: 1322@findex lisp-complete-symbol
1323 In Emacs-Lisp mode, the name space for completion normally consists of
1324nontrivial symbols present in Emacs---those that have function
1325definitions, values or properties. However, if there is an
1326open-parenthesis immediately before the beginning of the partial symbol,
1327only symbols with function definitions are considered as completions.
1328The command which implements this is @code{lisp-complete-symbol}.
2994 1329
2995@example 1330 In Text mode and related modes, @kbd{M-@key{TAB}} completes words
2996@group 1331based on the spell-checker's dictionary. @xref{Spelling}.
2997#ifdef NEW
2998@var{version from A buffer}
2999#else /* not NEW */
3000@var{version from B buffer}
3001#endif /* not NEW */
3002@end group
3003@end example
3004 1332
3005@noindent 1333@node Glasses
3006@vindex emerge-combine-versions-template 1334@section Glasses minor mode
3007While this example shows C preprocessor conditionals delimiting the two 1335@cindex Glasses mode
3008alternative versions, you can specify the strings to use by setting 1336@cindex identifiers, making long ones readable
3009the variable @code{emerge-combine-versions-template} to a string of your 1337@cindex StudlyCaps, making them readable
3010choice. In the string, @samp{%a} says where to put version A, and 1338@findex glasses-mode
3011@samp{%b} says where to put version B. The default setting, which
3012produces the results shown above, looks like this:
3013 1339
3014@example 1340 Glasses minor mode makes @samp{unreadableIdentifiersLikeThis}
3015@group 1341readable by altering the display. It can do this in two different
3016"#ifdef NEW\n%a#else /* not NEW */\n%b#endif /* not NEW */\n" 1342ways: by displaying underscores between an lower-case letter and the
3017@end group 1343following capital letter, or by emboldening the capital letters. It
3018@end example 1344does not alter the buffer text, only the way they display, so you can
1345use it even on read-only buffers. You can use the command @kbd{M-x
1346glasses-mode} to enable or disable the mode; you can also add
1347@code{glasses-mode} to the mode hook of appropriate programming
1348language major modes.
3019 1349
3020@node Fine Points of Emerge 1350@node Misc for Programs
3021@subsection Fine Points of Emerge 1351@section Other Features Useful for Editing Programs
3022 1352
3023 During the merge, you mustn't try to edit the A and B buffers yourself. 1353 A number of Emacs commands that aren't designed specifically for
3024Emerge modifies them temporarily, but ultimately puts them back the way 1354editing programs are useful for it nonetheless.
3025they were.
3026 1355
3027 You can have any number of merges going at once---just don't use any one 1356 The Emacs commands that operate on words, sentences and paragraphs
3028buffer as input to more than one merge at once, since the temporary 1357are useful for editing code. Most symbols names contain words
3029changes made in these buffers would get in each other's way. 1358(@pxref{Words}); sentences can be found in strings and comments
1359(@pxref{Sentences}). Paragraphs in the strict sense may be found in
1360program code (in long comments), but the paragraph commands are useful
1361in other places too, because programming language major modes define
1362paragraphs to begin and end at blank lines (@pxref{Paragraphs}).
1363Judicious use of blank lines to make the program clearer will also
1364provide useful chunks of text for the paragraph commands to work on.
1365Auto Fill mode, if enabled in a programming language major mode,
1366indents the new lines which it creates.
3030 1367
3031 Starting Emerge can take a long time because it needs to compare the 1368 The selective display feature is useful for looking at the overall
3032files fully. Emacs can't do anything else until @code{diff} finishes. 1369structure of a function (@pxref{Selective Display}). This feature
3033Perhaps in the future someone will change Emerge to do the comparison in 1370hides the lines that are indented more than a specified amount.
3034the background when the input files are large---then you could keep on 1371Programming modes often support Outline minor mode (@pxref{Outline
3035doing other things with Emacs until Emerge is ready to accept 1372Mode}). The Foldout package provides folding-editor features
3036commands. 1373(@pxref{Foldout}).
3037 1374
3038@vindex emerge-startup-hook 1375 The ``automatic typing'' features may be useful for writing programs.
3039 After setting up the merge, Emerge runs the hook 1376@xref{Top,,Autotyping, autotype, Autotyping}.
3040@code{emerge-startup-hook} (@pxref{Hooks}).
3041 1377
3042@node C Modes 1378@node C Modes
3043@section C and Related Modes 1379@section C and Related Modes
@@ -3061,11 +1397,12 @@ ccmode, , CC Mode}, for a more extensive description of these modes
3061and their special features. 1397and their special features.
3062 1398
3063@menu 1399@menu
3064* Motion in C:: 1400* Motion in C:: Commands to move by C statements, etc.
3065* Electric C:: 1401* Electric C:: Colon and other chars can automatically reindent.
3066* Hungry Delete:: 1402* Hungry Delete:: A more powerful DEL command.
3067* Other C Commands:: 1403* Other C Commands:: Filling comments, viewing expansion of macros,
3068* Comments in C:: 1404 and other neat features.
1405* Comments in C:: Options for customizing comment style.
3069@end menu 1406@end menu
3070 1407
3071@node Motion in C 1408@node Motion in C