25829
|
1 @c This is part of the Emacs manual.
|
|
2 @c Copyright (C) 1985, 86, 87, 93, 94, 95, 1997 Free Software Foundation, Inc.
|
|
3 @c See file emacs.texi for copying conditions.
|
|
4 @node Programs, Building, Text, Top
|
|
5 @chapter Editing Programs
|
|
6 @cindex Lisp editing
|
|
7 @cindex C editing
|
|
8 @cindex program editing
|
|
9
|
|
10 Emacs has many commands designed to understand the syntax of programming
|
|
11 languages such as Lisp and C. These commands can
|
|
12
|
|
13 @itemize @bullet
|
|
14 @item
|
|
15 Move over or kill balanced expressions or @dfn{sexps} (@pxref{Lists}).
|
|
16 @item
|
|
17 Move over or mark top-level expressions---@dfn{defuns}, in Lisp;
|
|
18 functions, in C (@pxref{Defuns}).
|
|
19 @item
|
|
20 Show how parentheses balance (@pxref{Matching}).
|
|
21 @item
|
|
22 Insert, kill or align comments (@pxref{Comments}).
|
|
23 @item
|
|
24 Follow the usual indentation conventions of the language
|
|
25 (@pxref{Program Indent}).
|
|
26 @end itemize
|
|
27
|
|
28 The commands for words, sentences and paragraphs are very useful in
|
|
29 editing code even though their canonical application is for editing
|
|
30 human language text. Most symbols contain words (@pxref{Words});
|
|
31 sentences can be found in strings and comments (@pxref{Sentences}).
|
|
32 Paragraphs per se don't exist in code, but the paragraph commands are
|
|
33 useful anyway, because programming language major modes define
|
|
34 paragraphs to begin and end at blank lines (@pxref{Paragraphs}).
|
|
35 Judicious use of blank lines to make the program clearer will also
|
|
36 provide useful chunks of text for the paragraph commands to work
|
|
37 on.
|
|
38
|
|
39 The selective display feature is useful for looking at the overall
|
|
40 structure of a function (@pxref{Selective Display}). This feature causes
|
|
41 only the lines that are indented less than a specified amount to appear
|
|
42 on the screen.
|
|
43
|
|
44 @menu
|
|
45 * Program Modes:: Major modes for editing programs.
|
|
46 * Lists:: Expressions with balanced parentheses.
|
|
47 * List Commands:: The commands for working with list and sexps.
|
|
48 * Defuns:: Each program is made up of separate functions.
|
|
49 There are editing commands to operate on them.
|
|
50 * Program Indent:: Adjusting indentation to show the nesting.
|
|
51 * Matching:: Insertion of a close-delimiter flashes matching open.
|
|
52 * Comments:: Inserting, killing, and aligning comments.
|
|
53 * Balanced Editing:: Inserting two matching parentheses at once, etc.
|
|
54 * Symbol Completion:: Completion on symbol names of your program or language.
|
|
55 * Which Function:: Which Function mode shows which function you are in.
|
|
56 * Documentation:: Getting documentation of functions you plan to call.
|
|
57 * Change Log:: Maintaining a change history for your program.
|
|
58 * Tags:: Go direct to any function in your program in one
|
|
59 command. Tags remembers which file it is in.
|
|
60 * Emerge:: A convenient way of merging two versions of a program.
|
|
61 * C Modes:: Special commands of C, C++, Objective-C,
|
|
62 Java, and Pike modes.
|
|
63 * Fortran:: Fortran mode and its special features.
|
|
64 * Asm Mode:: Asm mode and its special features.
|
|
65 @end menu
|
|
66
|
|
67 @node Program Modes
|
|
68 @section Major Modes for Programming Languages
|
|
69
|
|
70 @cindex modes for programming languages
|
|
71 @cindex Perl mode
|
|
72 @cindex Icon mode
|
|
73 @cindex Awk mode
|
|
74 @cindex Makefile mode
|
|
75 @cindex Tcl mode
|
|
76 @cindex CPerl mode
|
|
77 Emacs also has major modes for the programming languages Lisp, Scheme
|
|
78 (a variant of Lisp), Awk, C, C++, Fortran, Icon, Java, Objective-C,
|
|
79 Pascal, Perl, Pike, CORBA IDL, and Tcl. There is also a major mode for
|
|
80 makefiles, called Makefile mode. An second alternative mode for Perl is
|
|
81 called CPerl mode.
|
|
82
|
|
83 Ideally, a major mode should be implemented for each programming
|
|
84 language that you might want to edit with Emacs; but often the mode for
|
|
85 one language can serve for other syntactically similar languages. The
|
|
86 language modes that exist are those that someone decided to take the
|
|
87 trouble to write.
|
|
88
|
|
89 There are several forms of Lisp mode, which differ in the way they
|
|
90 interface to Lisp execution. @xref{Executing Lisp}.
|
|
91
|
|
92 Each of the programming language major modes defines the @key{TAB} key
|
|
93 to run an indentation function that knows the indentation conventions of
|
|
94 that language and updates the current line's indentation accordingly.
|
|
95 For example, in C mode @key{TAB} is bound to @code{c-indent-line}.
|
|
96 @kbd{C-j} is normally defined to do @key{RET} followed by @key{TAB};
|
|
97 thus, it too indents in a mode-specific fashion.
|
|
98
|
|
99 @kindex DEL @r{(programming modes)}
|
|
100 @findex backward-delete-char-untabify
|
|
101 In most programming languages, indentation is likely to vary from line to
|
|
102 line. So the major modes for those languages rebind @key{DEL} to treat a
|
|
103 tab as if it were the equivalent number of spaces (using the command
|
|
104 @code{backward-delete-char-untabify}). This makes it possible to rub out
|
|
105 indentation one column at a time without worrying whether it is made up of
|
|
106 spaces or tabs. Use @kbd{C-b C-d} to delete a tab character before point,
|
|
107 in these modes.
|
|
108
|
|
109 Programming language modes define paragraphs to be separated only by
|
|
110 blank lines, so that the paragraph commands remain useful. Auto Fill mode,
|
|
111 if enabled in a programming language major mode, indents the new lines
|
|
112 which it creates.
|
|
113
|
|
114 @cindex mode hook
|
|
115 @vindex c-mode-hook
|
|
116 @vindex lisp-mode-hook
|
|
117 @vindex emacs-lisp-mode-hook
|
|
118 @vindex lisp-interaction-mode-hook
|
|
119 @vindex scheme-mode-hook
|
|
120 @vindex muddle-mode-hook
|
|
121 Turning on a major mode runs a normal hook called the @dfn{mode hook},
|
|
122 which is the value of a Lisp variable. Each major mode has a mode hook,
|
|
123 and the hook's name is always made from the mode command's name by
|
|
124 adding @samp{-hook}. For example, turning on C mode runs the hook
|
|
125 @code{c-mode-hook}, while turning on Lisp mode runs the hook
|
|
126 @code{lisp-mode-hook}. @xref{Hooks}.
|
|
127
|
|
128 @node Lists
|
|
129 @section Lists and Sexps
|
|
130
|
|
131 @cindex Control-Meta
|
|
132 By convention, Emacs keys for dealing with balanced expressions are
|
|
133 usually Control-Meta characters. They tend to be analogous in
|
|
134 function to their Control and Meta equivalents. These commands are
|
|
135 usually thought of as pertaining to expressions in programming
|
|
136 languages, but can be useful with any language in which some sort of
|
|
137 parentheses exist (including human languages).
|
|
138
|
|
139 @cindex list
|
|
140 @cindex sexp
|
|
141 @cindex expression
|
|
142 @cindex parentheses, moving across
|
|
143 @cindex matching parenthesis, moving to
|
|
144 These commands fall into two classes. Some deal only with @dfn{lists}
|
|
145 (parenthetical groupings). They see nothing except parentheses, brackets,
|
|
146 braces (whichever ones must balance in the language you are working with),
|
|
147 and escape characters that might be used to quote those.
|
|
148
|
|
149 The other commands deal with expressions or @dfn{sexps}. The word `sexp'
|
|
150 is derived from @dfn{s-expression}, the ancient term for an expression in
|
|
151 Lisp. But in Emacs, the notion of `sexp' is not limited to Lisp. It
|
|
152 refers to an expression in whatever language your program is written in.
|
|
153 Each programming language has its own major mode, which customizes the
|
|
154 syntax tables so that expressions in that language count as sexps.
|
|
155
|
|
156 Sexps typically include symbols, numbers, and string constants, as well
|
|
157 as anything contained in parentheses, brackets or braces.
|
|
158
|
|
159 In languages that use prefix and infix operators, such as C, it is not
|
|
160 possible for all expressions to be sexps. For example, C mode does not
|
|
161 recognize @samp{foo + bar} as a sexp, even though it @emph{is} a C expression;
|
|
162 it recognizes @samp{foo} as one sexp and @samp{bar} as another, with the
|
|
163 @samp{+} as punctuation between them. This is a fundamental ambiguity:
|
|
164 both @samp{foo + bar} and @samp{foo} are legitimate choices for the sexp to
|
|
165 move over if point is at the @samp{f}. Note that @samp{(foo + bar)} is a
|
|
166 single sexp in C mode.
|
|
167
|
|
168 Some languages have obscure forms of expression syntax that nobody
|
|
169 has bothered to make Emacs understand properly.
|
|
170
|
|
171 @node List Commands
|
|
172 @section List And Sexp Commands
|
|
173
|
|
174 @c doublewidecommands
|
|
175 @table @kbd
|
|
176 @item C-M-f
|
|
177 Move forward over a sexp (@code{forward-sexp}).
|
|
178 @item C-M-b
|
|
179 Move backward over a sexp (@code{backward-sexp}).
|
|
180 @item C-M-k
|
|
181 Kill sexp forward (@code{kill-sexp}).
|
|
182 @item C-M-@key{DEL}
|
|
183 Kill sexp backward (@code{backward-kill-sexp}).
|
|
184 @item C-M-u
|
|
185 Move up and backward in list structure (@code{backward-up-list}).
|
|
186 @item C-M-d
|
|
187 Move down and forward in list structure (@code{down-list}).
|
|
188 @item C-M-n
|
|
189 Move forward over a list (@code{forward-list}).
|
|
190 @item C-M-p
|
|
191 Move backward over a list (@code{backward-list}).
|
|
192 @item C-M-t
|
|
193 Transpose expressions (@code{transpose-sexps}).
|
|
194 @item C-M-@@
|
|
195 Put mark after following expression (@code{mark-sexp}).
|
|
196 @end table
|
|
197
|
|
198 @kindex C-M-f
|
|
199 @kindex C-M-b
|
|
200 @findex forward-sexp
|
|
201 @findex backward-sexp
|
|
202 To move forward over a sexp, use @kbd{C-M-f} (@code{forward-sexp}). If
|
|
203 the first significant character after point is an opening delimiter
|
|
204 (@samp{(} in Lisp; @samp{(}, @samp{[} or @samp{@{} in C), @kbd{C-M-f}
|
|
205 moves past the matching closing delimiter. If the character begins a
|
|
206 symbol, string, or number, @kbd{C-M-f} moves over that.
|
|
207
|
|
208 The command @kbd{C-M-b} (@code{backward-sexp}) moves backward over a
|
|
209 sexp. The detailed rules are like those above for @kbd{C-M-f}, but with
|
|
210 directions reversed. If there are any prefix characters (single-quote,
|
|
211 backquote and comma, in Lisp) preceding the sexp, @kbd{C-M-b} moves back
|
|
212 over them as well. The sexp commands move across comments as if they
|
|
213 were whitespace in most modes.
|
|
214
|
|
215 @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation the
|
|
216 specified number of times; with a negative argument, it moves in the
|
|
217 opposite direction.
|
|
218
|
|
219 @kindex C-M-k
|
|
220 @findex kill-sexp
|
|
221 @kindex C-M-DEL
|
|
222 @findex backward-kill-sexp
|
|
223 Killing a whole sexp can be done with @kbd{C-M-k} (@code{kill-sexp})
|
|
224 or @kbd{C-M-@key{DEL}} (@code{backward-kill-sexp}). @kbd{C-M-k} kills
|
|
225 the characters that @kbd{C-M-f} would move over, and @kbd{C-M-@key{DEL}}
|
|
226 kills the characters that @kbd{C-M-b} would move over.
|
|
227
|
|
228 @kindex C-M-n
|
|
229 @kindex C-M-p
|
|
230 @findex forward-list
|
|
231 @findex backward-list
|
|
232 The @dfn{list commands} move over lists, as the sexp commands do, but skip
|
|
233 blithely over any number of other kinds of sexps (symbols, strings, etc.).
|
|
234 They are @kbd{C-M-n} (@code{forward-list}) and @kbd{C-M-p}
|
|
235 (@code{backward-list}). The main reason they are useful is that they
|
|
236 usually ignore comments (since the comments usually do not contain any
|
|
237 lists).@refill
|
|
238
|
|
239 @kindex C-M-u
|
|
240 @kindex C-M-d
|
|
241 @findex backward-up-list
|
|
242 @findex down-list
|
|
243 @kbd{C-M-n} and @kbd{C-M-p} stay at the same level in parentheses, when
|
|
244 that's possible. To move @emph{up} one (or @var{n}) levels, use @kbd{C-M-u}
|
|
245 (@code{backward-up-list}).
|
|
246 @kbd{C-M-u} moves backward up past one unmatched opening delimiter. A
|
|
247 positive argument serves as a repeat count; a negative argument reverses
|
|
248 direction of motion and also requests repetition, so it moves forward and
|
|
249 up one or more levels.@refill
|
|
250
|
|
251 To move @emph{down} in list structure, use @kbd{C-M-d}
|
|
252 (@code{down-list}). In Lisp mode, where @samp{(} is the only opening
|
|
253 delimiter, this is nearly the same as searching for a @samp{(}. An
|
|
254 argument specifies the number of levels of parentheses to go down.
|
|
255
|
|
256 @cindex transposition
|
|
257 @kindex C-M-t
|
|
258 @findex transpose-sexps
|
|
259 A somewhat random-sounding command which is nevertheless handy is
|
|
260 @kbd{C-M-t} (@code{transpose-sexps}), which drags the previous sexp
|
|
261 across the next one. An argument serves as a repeat count, and a
|
|
262 negative argument drags backwards (thus canceling out the effect of
|
|
263 @kbd{C-M-t} with a positive argument). An argument of zero, rather than
|
|
264 doing nothing, transposes the sexps ending after point and the mark.
|
|
265
|
|
266 @kindex C-M-@@
|
|
267 @findex mark-sexp
|
|
268 To set the region around the next sexp in the buffer, use @kbd{C-M-@@}
|
|
269 (@code{mark-sexp}), which sets mark at the same place that @kbd{C-M-f}
|
|
270 would move to. @kbd{C-M-@@} takes arguments like @kbd{C-M-f}. In
|
|
271 particular, a negative argument is useful for putting the mark at the
|
|
272 beginning of the previous sexp.
|
|
273
|
|
274 The list and sexp commands' understanding of syntax is completely
|
|
275 controlled by the syntax table. Any character can, for example, be
|
|
276 declared to be an opening delimiter and act like an open parenthesis.
|
|
277 @xref{Syntax}.
|
|
278
|
|
279 @node Defuns
|
|
280 @section Defuns
|
|
281 @cindex defuns
|
|
282
|
|
283 In Emacs, a parenthetical grouping at the top level in the buffer is
|
|
284 called a @dfn{defun}. The name derives from the fact that most top-level
|
|
285 lists in a Lisp file are instances of the special form @code{defun}, but
|
|
286 any top-level parenthetical grouping counts as a defun in Emacs parlance
|
|
287 regardless of what its contents are, and regardless of the programming
|
|
288 language in use. For example, in C, the body of a function definition is a
|
|
289 defun.
|
|
290
|
|
291 @c doublewidecommands
|
|
292 @table @kbd
|
|
293 @item C-M-a
|
|
294 Move to beginning of current or preceding defun
|
|
295 (@code{beginning-of-defun}).
|
|
296 @item C-M-e
|
|
297 Move to end of current or following defun (@code{end-of-defun}).
|
|
298 @item C-M-h
|
|
299 Put region around whole current or following defun (@code{mark-defun}).
|
|
300 @end table
|
|
301
|
|
302 @kindex C-M-a
|
|
303 @kindex C-M-e
|
|
304 @kindex C-M-h
|
|
305 @findex beginning-of-defun
|
|
306 @findex end-of-defun
|
|
307 @findex mark-defun
|
|
308 The commands to move to the beginning and end of the current defun are
|
|
309 @kbd{C-M-a} (@code{beginning-of-defun}) and @kbd{C-M-e} (@code{end-of-defun}).
|
|
310
|
|
311 @findex c-mark-function
|
|
312 If you wish to operate on the current defun, use @kbd{C-M-h}
|
|
313 (@code{mark-defun}) which puts point at the beginning and mark at the end
|
|
314 of the current or next defun. For example, this is the easiest way to get
|
|
315 ready to move the defun to a different place in the text. In C mode,
|
|
316 @kbd{C-M-h} runs the function @code{c-mark-function}, which is almost the
|
|
317 same as @code{mark-defun}; the difference is that it backs up over the
|
|
318 argument declarations, function name and returned data type so that the
|
|
319 entire C function is inside the region. @xref{Marking Objects}.
|
|
320
|
|
321 Emacs assumes that any open-parenthesis found in the leftmost column
|
|
322 is the start of a defun. Therefore, @strong{never put an
|
|
323 open-parenthesis at the left margin in a Lisp file unless it is the
|
|
324 start of a top-level list. Never put an open-brace or other opening
|
|
325 delimiter at the beginning of a line of C code unless it starts the body
|
|
326 of a function.} The most likely problem case is when you want an
|
|
327 opening delimiter at the start of a line inside a string. To avoid
|
|
328 trouble, put an escape character (@samp{\}, in C and Emacs Lisp,
|
|
329 @samp{/} in some other Lisp dialects) before the opening delimiter. It
|
|
330 will not affect the contents of the string.
|
|
331
|
|
332 In the remotest past, the original Emacs found defuns by moving upward a
|
|
333 level of parentheses until there were no more levels to go up. This always
|
|
334 required scanning all the way back to the beginning of the buffer, even for
|
|
335 a small function. To speed up the operation, Emacs was changed to assume
|
|
336 that any @samp{(} (or other character assigned the syntactic class of
|
|
337 opening-delimiter) at the left margin is the start of a defun. This
|
|
338 heuristic is nearly always right and avoids the costly scan; however,
|
|
339 it mandates the convention described above.
|
|
340
|
|
341 @node Program Indent
|
|
342 @section Indentation for Programs
|
|
343 @cindex indentation for programs
|
|
344
|
|
345 The best way to keep a program properly indented is to use Emacs to
|
|
346 reindent it as you change it. Emacs has commands to indent properly
|
|
347 either a single line, a specified number of lines, or all of the lines
|
|
348 inside a single parenthetical grouping.
|
|
349
|
|
350 @menu
|
|
351 * Basic Indent:: Indenting a single line.
|
|
352 * Multi-line Indent:: Commands to reindent many lines at once.
|
|
353 * Lisp Indent:: Specifying how each Lisp function should be indented.
|
|
354 * C Indent:: Extra features for indenting C and related modes.
|
|
355 * Custom C Indent:: Controlling indentation style for C and related modes.
|
|
356 @end menu
|
|
357
|
|
358 Emacs also provides a Lisp pretty-printer in the library @code{pp}.
|
|
359 This program reformats a Lisp object with indentation chosen to look nice.
|
|
360
|
|
361 @node Basic Indent
|
|
362 @subsection Basic Program Indentation Commands
|
|
363
|
|
364 @c WideCommands
|
|
365 @table @kbd
|
|
366 @item @key{TAB}
|
|
367 Adjust indentation of current line.
|
|
368 @item C-j
|
|
369 Equivalent to @key{RET} followed by @key{TAB} (@code{newline-and-indent}).
|
|
370 @end table
|
|
371
|
|
372 @kindex TAB @r{(programming modes)}
|
|
373 @findex c-indent-line
|
|
374 @findex lisp-indent-line
|
|
375 The basic indentation command is @key{TAB}, which gives the current line
|
|
376 the correct indentation as determined from the previous lines. The
|
|
377 function that @key{TAB} runs depends on the major mode; it is @code{lisp-indent-line}
|
|
378 in Lisp mode, @code{c-indent-line} in C mode, etc. These functions
|
|
379 understand different syntaxes for different languages, but they all do
|
|
380 about the same thing. @key{TAB} in any programming-language major mode
|
|
381 inserts or deletes whitespace at the beginning of the current line,
|
|
382 independent of where point is in the line. If point is inside the
|
|
383 whitespace at the beginning of the line, @key{TAB} leaves it at the end of
|
|
384 that whitespace; otherwise, @key{TAB} leaves point fixed with respect to
|
|
385 the characters around it.
|
|
386
|
|
387 Use @kbd{C-q @key{TAB}} to insert a tab at point.
|
|
388
|
|
389 @kindex C-j
|
|
390 @findex newline-and-indent
|
|
391 When entering lines of new code, use @kbd{C-j} (@code{newline-and-indent}),
|
|
392 which is equivalent to a @key{RET} followed by a @key{TAB}. @kbd{C-j} creates
|
|
393 a blank line and then gives it the appropriate indentation.
|
|
394
|
|
395 @key{TAB} indents the second and following lines of the body of a
|
|
396 parenthetical grouping each under the preceding one; therefore, if you
|
|
397 alter one line's indentation to be nonstandard, the lines below will
|
|
398 tend to follow it. This behavior is convenient in cases where you have
|
|
399 overridden the standard result of @key{TAB} because you find it
|
|
400 unaesthetic for a particular line.
|
|
401
|
|
402 Remember that an open-parenthesis, open-brace or other opening delimiter
|
|
403 at the left margin is assumed by Emacs (including the indentation routines)
|
|
404 to be the start of a function. Therefore, you must never have an opening
|
|
405 delimiter in column zero that is not the beginning of a function, not even
|
|
406 inside a string. This restriction is vital for making the indentation
|
|
407 commands fast; you must simply accept it. @xref{Defuns}, for more
|
|
408 information on this.
|
|
409
|
|
410 @node Multi-line Indent
|
|
411 @subsection Indenting Several Lines
|
|
412
|
|
413 When you wish to reindent several lines of code which have been altered
|
|
414 or moved to a different level in the list structure, you have several
|
|
415 commands available.
|
|
416
|
|
417 @table @kbd
|
|
418 @item C-M-q
|
|
419 Reindent all the lines within one list (@code{indent-sexp}).
|
|
420 @item C-u @key{TAB}
|
|
421 Shift an entire list rigidly sideways so that its first line
|
|
422 is properly indented.
|
|
423 @item C-M-\
|
|
424 Reindent all lines in the region (@code{indent-region}).
|
|
425 @end table
|
|
426
|
|
427 @kindex C-M-q
|
|
428 @findex indent-sexp
|
|
429 You can reindent the contents of a single list by positioning point
|
|
430 before the beginning of it and typing @kbd{C-M-q} (@code{indent-sexp} in
|
|
431 Lisp mode, @code{c-indent-exp} in C mode; also bound to other suitable
|
|
432 commands in other modes). The indentation of the line the sexp starts on
|
|
433 is not changed; therefore, only the relative indentation within the list,
|
|
434 and not its position, is changed. To correct the position as well, type a
|
|
435 @key{TAB} before the @kbd{C-M-q}.
|
|
436
|
|
437 @kindex C-u TAB
|
|
438 If the relative indentation within a list is correct but the
|
|
439 indentation of its first line is not, go to that line and type @kbd{C-u
|
|
440 @key{TAB}}. @key{TAB} with a numeric argument reindents the current
|
|
441 line as usual, then reindents by the same amount all the lines in the
|
|
442 grouping starting on the current line. In other words, it reindents the
|
|
443 whole grouping rigidly as a unit. It is clever, though, and does not
|
|
444 alter lines that start inside strings, or C preprocessor lines when in C
|
|
445 mode.
|
|
446
|
|
447 Another way to specify the range to be reindented is with the region.
|
|
448 The command @kbd{C-M-\} (@code{indent-region}) applies @key{TAB} to
|
|
449 every line whose first character is between point and mark.
|
|
450
|
|
451 @node Lisp Indent
|
|
452 @subsection Customizing Lisp Indentation
|
|
453 @cindex customizing Lisp indentation
|
|
454
|
|
455 The indentation pattern for a Lisp expression can depend on the function
|
|
456 called by the expression. For each Lisp function, you can choose among
|
|
457 several predefined patterns of indentation, or define an arbitrary one with
|
|
458 a Lisp program.
|
|
459
|
|
460 The standard pattern of indentation is as follows: the second line of the
|
|
461 expression is indented under the first argument, if that is on the same
|
|
462 line as the beginning of the expression; otherwise, the second line is
|
|
463 indented underneath the function name. Each following line is indented
|
|
464 under the previous line whose nesting depth is the same.
|
|
465
|
|
466 @vindex lisp-indent-offset
|
|
467 If the variable @code{lisp-indent-offset} is non-@code{nil}, it overrides
|
|
468 the usual indentation pattern for the second line of an expression, so that
|
|
469 such lines are always indented @code{lisp-indent-offset} more columns than
|
|
470 the containing list.
|
|
471
|
|
472 @vindex lisp-body-indent
|
|
473 The standard pattern is overridden for certain functions. Functions
|
|
474 whose names start with @code{def} always indent the second line by
|
|
475 @code{lisp-body-indent} extra columns beyond the open-parenthesis
|
|
476 starting the expression.
|
|
477
|
|
478 The standard pattern can be overridden in various ways for individual
|
|
479 functions, according to the @code{lisp-indent-function} property of the
|
|
480 function name. There are four possibilities for this property:
|
|
481
|
|
482 @table @asis
|
|
483 @item @code{nil}
|
|
484 This is the same as no property; the standard indentation pattern is used.
|
|
485 @item @code{defun}
|
|
486 The pattern used for function names that start with @code{def} is used for
|
|
487 this function also.
|
|
488 @item a number, @var{number}
|
|
489 The first @var{number} arguments of the function are
|
|
490 @dfn{distinguished} arguments; the rest are considered the @dfn{body}
|
|
491 of the expression. A line in the expression is indented according to
|
|
492 whether the first argument on it is distinguished or not. If the
|
|
493 argument is part of the body, the line is indented @code{lisp-body-indent}
|
|
494 more columns than the open-parenthesis starting the containing
|
|
495 expression. If the argument is distinguished and is either the first
|
|
496 or second argument, it is indented @emph{twice} that many extra columns.
|
|
497 If the argument is distinguished and not the first or second argument,
|
|
498 the standard pattern is followed for that line.
|
|
499 @item a symbol, @var{symbol}
|
|
500 @var{symbol} should be a function name; that function is called to
|
|
501 calculate the indentation of a line within this expression. The
|
|
502 function receives two arguments:
|
|
503 @table @asis
|
|
504 @item @var{state}
|
|
505 The value returned by @code{parse-partial-sexp} (a Lisp primitive for
|
|
506 indentation and nesting computation) when it parses up to the
|
|
507 beginning of this line.
|
|
508 @item @var{pos}
|
|
509 The position at which the line being indented begins.
|
|
510 @end table
|
|
511 @noindent
|
|
512 It should return either a number, which is the number of columns of
|
|
513 indentation for that line, or a list whose car is such a number. The
|
|
514 difference between returning a number and returning a list is that a
|
|
515 number says that all following lines at the same nesting level should
|
|
516 be indented just like this one; a list says that following lines might
|
|
517 call for different indentations. This makes a difference when the
|
|
518 indentation is being computed by @kbd{C-M-q}; if the value is a
|
|
519 number, @kbd{C-M-q} need not recalculate indentation for the following
|
|
520 lines until the end of the list.
|
|
521 @end table
|
|
522
|
|
523 @node C Indent
|
|
524 @subsection Commands for C Indentation
|
|
525
|
|
526 Here are the commands for indentation in C mode and related modes:
|
|
527
|
|
528 @table @code
|
|
529 @item C-c C-q
|
|
530 @kindex C-c C-q @r{(C mode)}
|
|
531 @findex c-indent-defun
|
|
532 Reindent the current top-level function definition or aggregate type
|
|
533 declaration (@code{c-indent-defun}).
|
|
534
|
|
535 @item C-M-q
|
|
536 @kindex C-M-q @r{(C mode)}
|
|
537 @findex c-indent-exp
|
|
538 Reindent each line in the balanced expression that follows point
|
|
539 (@code{c-indent-exp}). A prefix argument inhibits error checking and
|
|
540 warning messages about invalid syntax.
|
|
541
|
|
542 @item @key{TAB}
|
|
543 @findex c-indent-command
|
|
544 Reindent the current line, and/or in some cases insert a tab character
|
|
545 (@code{c-indent-command}).
|
|
546
|
|
547 If @code{c-tab-always-indent} is @code{t}, this command always reindents
|
|
548 the current line and does nothing else. This is the default.
|
|
549
|
|
550 If that variable is @code{nil}, this command reindents the current line
|
|
551 only if point is at the left margin or in the line's indentation;
|
|
552 otherwise, it inserts a tab (or the equivalent number of spaces,
|
|
553 if @code{indent-tabs-mode} is @code{nil}).
|
|
554
|
|
555 Any other value (not @code{nil} or @code{t}) means always reindent the
|
|
556 line, and also insert a tab if within a comment, a string, or a
|
|
557 preprocessor directive.
|
|
558
|
|
559 @item C-u @key{TAB}
|
|
560 Reindent the current line according to its syntax; also rigidly reindent
|
|
561 any other lines of the expression that starts on the current line.
|
|
562 @xref{Multi-line Indent}.
|
|
563 @end table
|
|
564
|
|
565 To reindent the whole current buffer, type @kbd{C-x h C-M-\}. This
|
|
566 first selects the whole buffer as the region, then reindents that
|
|
567 region.
|
|
568
|
|
569 To reindent the current block, use @kbd{C-M-u C-M-q}. This moves
|
|
570 to the front of the block and then reindents it all.
|
|
571
|
|
572 @node Custom C Indent
|
|
573 @subsection Customizing C Indentation
|
|
574
|
|
575 C mode and related modes use a simple yet flexible mechanism for
|
|
576 customizing indentation. The mechanism works in two steps: first it
|
|
577 classifies the line syntactically according to its contents and context;
|
|
578 second, it associates each kind of syntactic construct with an
|
|
579 indentation offset which you can customize.
|
|
580
|
|
581 @menu
|
|
582 * Syntactic Analysis::
|
|
583 * Indentation Calculation::
|
|
584 * Changing Indent Style::
|
|
585 * Syntactic Symbols::
|
|
586 * Variables for C Indent::
|
|
587 * C Indent Styles::
|
|
588 @end menu
|
|
589
|
|
590 @node Syntactic Analysis
|
|
591 @subsubsection Step 1---Syntactic Analysis
|
|
592 @cindex syntactic analysis
|
|
593
|
|
594 In the first step, the C indentation mechanism looks at the line
|
|
595 before the one you are currently indenting and determines the syntactic
|
|
596 components of the construct on that line. It builds a list of these
|
|
597 syntactic components, each of which contains a @dfn{syntactic symbol}
|
|
598 and sometimes also a buffer position. Some syntactic symbols describe
|
|
599 grammatical elements, for example @code{statement} and
|
|
600 @code{substatement}; others describe locations amidst grammatical
|
|
601 elements, for example @code{class-open} and @code{knr-argdecl}.
|
|
602
|
|
603 Conceptually, a line of C code is always indented relative to the
|
|
604 indentation of some line higher up in the buffer. This is represented
|
|
605 by the buffer positions in the syntactic component list.
|
|
606
|
|
607 Here is an example. Suppose we have the following code in a C++ mode
|
|
608 buffer (the line numbers don't actually appear in the buffer):
|
|
609
|
|
610 @example
|
|
611 1: void swap (int& a, int& b)
|
|
612 2: @{
|
|
613 3: int tmp = a;
|
|
614 4: a = b;
|
|
615 5: b = tmp;
|
|
616 6: @}
|
|
617 @end example
|
|
618
|
|
619 If you type @kbd{C-c C-s} (which runs the command
|
|
620 @code{c-show-syntactic-information}) on line 4, it shows the result of
|
|
621 the indentation mechanism for that line:
|
|
622
|
|
623 @example
|
|
624 ((statement . 32))
|
|
625 @end example
|
|
626
|
|
627 This indicates that the line is a statement and it is indented
|
|
628 relative to buffer position 32, which happens to be the @samp{i} in
|
|
629 @code{int} on line 3. If you move the cursor to line 3 and type
|
|
630 @kbd{C-c C-s}, it displays this:
|
|
631
|
|
632 @example
|
|
633 ((defun-block-intro . 28))
|
|
634 @end example
|
|
635
|
|
636 This indicates that the @code{int} line is the first statement in a
|
|
637 block, and is indented relative to buffer position 28, which is the
|
|
638 brace just after the function header.
|
|
639
|
|
640 @noindent
|
|
641 Here is another example:
|
|
642
|
|
643 @example
|
|
644 1: int add (int val, int incr, int doit)
|
|
645 2: @{
|
|
646 3: if (doit)
|
|
647 4: @{
|
|
648 5: return (val + incr);
|
|
649 6: @}
|
|
650 7: return (val);
|
|
651 8: @}
|
|
652 @end example
|
|
653
|
|
654 @noindent
|
|
655 Typing @kbd{C-c C-s} on line 4 displays this:
|
|
656
|
|
657 @example
|
|
658 ((substatement-open . 43))
|
|
659 @end example
|
|
660
|
|
661 This says that the brace @emph{opens} a substatement block. By the
|
|
662 way, a @dfn{substatement} indicates the line after an @code{if},
|
|
663 @code{else}, @code{while}, @code{do}, @code{switch}, @code{for},
|
|
664 @code{try}, @code{catch}, @code{finally}, or @code{synchronized}
|
|
665 statement.
|
|
666
|
|
667 @cindex syntactic component
|
|
668 @cindex syntactic symbol
|
|
669 @vindex c-syntactic-context
|
|
670 Within the C indentation commands, after a line has been analyzed
|
|
671 syntactically for indentation, the variable @code{c-syntactic-context}
|
|
672 contains a list that describes the results. Each element in this list
|
|
673 is a @dfn{syntactic component}: a cons cell containing a syntactic
|
|
674 symbol and (optionally) its corresponding buffer position. There may be
|
|
675 several elements in a component list; typically only one element has a
|
|
676 buffer position.
|
|
677
|
|
678 @node Indentation Calculation
|
|
679 @subsubsection Step 2---Indentation Calculation
|
|
680 @cindex Indentation Calculation
|
|
681
|
|
682 The C indentation mechanism calculates the indentation for the current
|
|
683 line using the list of syntactic components, @code{c-syntactic-context},
|
|
684 derived from syntactic analysis. Each component is a cons cell that
|
|
685 contains a syntactic symbol and may also contain a buffer position.
|
|
686
|
|
687 Each component contributes to the final total indentation of the line
|
|
688 in two ways. First, the syntactic symbol identifies an element of
|
|
689 @code{c-offsets-alist}, which is an association list mapping syntactic
|
|
690 symbols into indentation offsets. Each syntactic symbol's offset adds
|
|
691 to the total indentation. Second, if the component includes a buffer
|
|
692 position, the column number of that position adds to the indentation.
|
|
693 All these offsets and column numbers, added together, give the total
|
|
694 indentation.
|
|
695
|
|
696 The following examples demonstrate the workings of the C indentation
|
|
697 mechanism:
|
|
698
|
|
699 @example
|
|
700 1: void swap (int& a, int& b)
|
|
701 2: @{
|
|
702 3: int tmp = a;
|
|
703 4: a = b;
|
|
704 5: b = tmp;
|
|
705 6: @}
|
|
706 @end example
|
|
707
|
|
708 Suppose that point is on line 3 and you type @key{TAB} to reindent the
|
|
709 line. As explained above (@pxref{Syntactic Analysis}), the syntactic
|
|
710 component list for that line is:
|
|
711
|
|
712 @example
|
|
713 ((defun-block-intro . 28))
|
|
714 @end example
|
|
715
|
|
716 In this case, the indentation calculation first looks up
|
|
717 @code{defun-block-intro} in the @code{c-offsets-alist} alist. Suppose
|
|
718 that it finds the integer 2; it adds this to the running total
|
|
719 (initialized to zero), yielding a updated total indentation of 2 spaces.
|
|
720
|
|
721 The next step is to find the column number of buffer position 28.
|
|
722 Since the brace at buffer position 28 is in column zero, this adds 0 to
|
|
723 the running total. Since this line has only one syntactic component,
|
|
724 the total indentation for the line is 2 spaces.
|
|
725
|
|
726 @example
|
|
727 1: int add (int val, int incr, int doit)
|
|
728 2: @{
|
|
729 3: if (doit)
|
|
730 4: @{
|
|
731 5: return(val + incr);
|
|
732 6: @}
|
|
733 7: return(val);
|
|
734 8: @}
|
|
735 @end example
|
|
736
|
|
737 If you type @key{TAB} on line 4, the same process is performed, but
|
|
738 with different data. The syntactic component list for this line is:
|
|
739
|
|
740 @example
|
|
741 ((substatement-open . 43))
|
|
742 @end example
|
|
743
|
|
744 Here, the indentation calculation's first job is to look up the
|
|
745 symbol @code{substatement-open} in @code{c-offsets-alist}. Let's assume
|
|
746 that the offset for this symbol is 2. At this point the running total
|
|
747 is 2 (0 + 2 = 2). Then it adds the column number of buffer position 43,
|
|
748 which is the @samp{i} in @code{if} on line 3. This character is in
|
|
749 column 2 on that line. Adding this yields a total indentation of 4
|
|
750 spaces.
|
|
751
|
|
752 @vindex c-strict-syntax-p
|
|
753 If a syntactic symbol in the analysis of a line does not appear in
|
|
754 @code{c-offsets-alist}, it is ignored; if in addition the variable
|
|
755 @code{c-strict-syntax-p} is non-@code{nil}, it is an error.
|
|
756
|
|
757 @node Changing Indent Style
|
|
758 @subsubsection Changing Indentation Style
|
|
759
|
|
760 There are two ways to customize the indentation style for the C-like
|
|
761 modes. First, you can select one of several predefined styles, each of
|
|
762 which specifies offsets for all the syntactic symbols. For more
|
|
763 flexibility, you can customize the handling of individual syntactic
|
|
764 symbols. @xref{Syntactic Symbols}, for a list of all defined syntactic
|
|
765 symbols.
|
|
766
|
|
767 @table @kbd
|
|
768 @item M-x c-set-style @key{RET} @var{style} @key{RET}
|
|
769 Select predefined indentation style @var{style}. Type @kbd{?} when
|
|
770 entering @var{style} to see a list of supported styles; to find out what
|
|
771 a style looks like, select it and reindent some C code.
|
|
772
|
|
773 @item C-c C-o @var{symbol} @key{RET} @var{offset} @key{RET}
|
|
774 Set the indentation offset for syntactic symbol @var{symbol}
|
|
775 (@code{c-set-offset}). The second argument @var{offset} specifies the
|
|
776 new indentation offset.
|
|
777 @end table
|
|
778
|
|
779 The @code{c-offsets-alist} variable controls the amount of
|
|
780 indentation to give to each syntactic symbol. Its value is an
|
|
781 association list, and each element of the list has the form
|
|
782 @code{(@var{syntactic-symbol} . @var{offset})}. By changing the offsets
|
|
783 for various syntactic symbols, you can customize indentation in fine
|
|
784 detail. To change this alist, use @code{c-set-offset} (see below).
|
|
785
|
|
786 Each offset value in @code{c-offsets-alist} can be an integer, a
|
|
787 function or variable name, a list, or one of the following symbols: @code{+},
|
|
788 @code{-}, @code{++}, @code{--}, @code{*}, or @code{/}, indicating positive or negative
|
|
789 multiples of the variable @code{c-basic-offset}. Thus, if you want to
|
|
790 change the levels of indentation to be 3 spaces instead of 2 spaces, set
|
|
791 @code{c-basic-offset} to 3.
|
|
792
|
|
793 Using a function as the offset value provides the ultimate flexibility
|
|
794 in customizing indentation. The function is called with a single
|
|
795 argument containing the @code{cons} of the syntactic symbol and
|
|
796 the buffer position, if any. The function should return an integer
|
|
797 offset.
|
|
798
|
|
799 If the offset value is a list, its elements are processed according
|
|
800 to the rules above until a non-@code{nil} value is found. That value is
|
|
801 then added to the total indentation in the normal manner. The primary
|
|
802 use for this is to combine the results of several functions.
|
|
803
|
|
804 @kindex C-c C-o @r{(C mode)}
|
|
805 @findex c-set-offset
|
|
806 The command @kbd{C-c C-o} (@code{c-set-offset}) is the easiest way to
|
|
807 set offsets, both interactively or in your @file{~/.emacs} file. First
|
|
808 specify the syntactic symbol, then the offset you want. @xref{Syntactic
|
|
809 Symbols}, for a list of valid syntactic symbols and their meanings.
|
|
810
|
|
811 @node Syntactic Symbols
|
|
812 @subsubsection Syntactic Symbols
|
|
813
|
|
814 Here is a table of valid syntactic symbols for indentation in C and
|
|
815 related modes, with their syntactic meanings. Normally, most of these
|
|
816 symbols are assigned offsets in @code{c-offsets-alist}.
|
|
817
|
|
818 @table @code
|
|
819 @item string
|
|
820 Inside a multi-line string.
|
|
821
|
|
822 @item c
|
|
823 Inside a multi-line C style block comment.
|
|
824
|
|
825 @item defun-open
|
|
826 On a brace that opens a function definition.
|
|
827
|
|
828 @item defun-close
|
|
829 On a brace that closes a function definition.
|
|
830
|
|
831 @item defun-block-intro
|
|
832 In the first line in a top-level defun.
|
|
833
|
|
834 @item class-open
|
|
835 On a brace that opens a class definition.
|
|
836
|
|
837 @item class-close
|
|
838 On a brace that closes a class definition.
|
|
839
|
|
840 @item inline-open
|
|
841 On a brace that opens an in-class inline method.
|
|
842
|
|
843 @item inline-close
|
|
844 On a brace that closes an in-class inline method.
|
|
845
|
|
846 @item extern-lang-open
|
|
847 On a brace that opens an external language block.
|
|
848
|
|
849 @item extern-lang-close
|
|
850 On a brace that closes an external language block.
|
|
851
|
|
852 @item func-decl-cont
|
|
853 The region between a function definition's argument list and the defun
|
|
854 opening brace (excluding K&R function definitions). In C, you cannot
|
|
855 put anything but whitespace and comments between them; in C++ and Java,
|
|
856 @code{throws} declarations and other things can appear in this context.
|
|
857
|
|
858 @item knr-argdecl-intro
|
|
859 On the first line of a K&R C argument declaration.
|
|
860
|
|
861 @item knr-argdecl
|
|
862 In one of the subsequent lines in a K&R C argument declaration.
|
|
863
|
|
864 @item topmost-intro
|
|
865 On the first line in a topmost construct definition.
|
|
866
|
|
867 @item topmost-intro-cont
|
|
868 On the topmost definition continuation lines.
|
|
869
|
|
870 @item member-init-intro
|
|
871 On the first line in a member initialization list.
|
|
872
|
|
873 @item member-init-cont
|
|
874 On one of the subsequent member initialization list lines.
|
|
875
|
|
876 @item inher-intro
|
|
877 On the first line of a multiple inheritance list.
|
|
878
|
|
879 @item inher-cont
|
|
880 On one of the subsequent multiple inheritance lines.
|
|
881
|
|
882 @item block-open
|
|
883 On a statement block open brace.
|
|
884
|
|
885 @item block-close
|
|
886 On a statement block close brace.
|
|
887
|
|
888 @item brace-list-open
|
|
889 On the opening brace of an @code{enum} or @code{static} array list.
|
|
890
|
|
891 @item brace-list-close
|
|
892 On the closing brace of an @code{enum} or @code{static} array list.
|
|
893
|
|
894 @item brace-list-intro
|
|
895 On the first line in an @code{enum} or @code{static} array list.
|
|
896
|
|
897 @item brace-list-entry
|
|
898 On one of the subsequent lines in an @code{enum} or @code{static} array
|
|
899 list.
|
|
900
|
|
901 @item brace-entry-open
|
|
902 On one of the subsequent lines in an @code{enum} or @code{static} array
|
|
903 list, when the line begins with an open brace.
|
|
904
|
|
905 @item statement
|
|
906 On an ordinary statement.
|
|
907
|
|
908 @item statement-cont
|
|
909 On a continuation line of a statement.
|
|
910
|
|
911 @item statement-block-intro
|
|
912 On the first line in a new statement block.
|
|
913
|
|
914 @item statement-case-intro
|
|
915 On the first line in a @code{case} ``block.''
|
|
916
|
|
917 @item statement-case-open
|
|
918 On the first line in a @code{case} block starting with brace.
|
|
919
|
|
920 @item inexpr-statement
|
|
921 On a statement block inside an expression. This is used for a GNU
|
|
922 extension to the C language, and for Pike special functions that take a
|
|
923 statement block as an argument.
|
|
924
|
|
925 @item inexpr-class
|
|
926 On a class definition inside an expression. This is used for anonymous
|
|
927 classes and anonymous array initializers in Java.
|
|
928
|
|
929 @item substatement
|
|
930 On the first line after an @code{if}, @code{while}, @code{for},
|
|
931 @code{do}, or @code{else}.
|
|
932
|
|
933 @item substatement-open
|
|
934 On the brace that opens a substatement block.
|
|
935
|
|
936 @item case-label
|
|
937 On a @code{case} or @code{default} label.
|
|
938
|
|
939 @item access-label
|
|
940 On a C++ @code{private}, @code{protected}, or @code{public} access label.
|
|
941
|
|
942 @item label
|
|
943 On any ordinary label.
|
|
944
|
|
945 @item do-while-closure
|
|
946 On the @code{while} that ends a @code{do}-@code{while} construct.
|
|
947
|
|
948 @item else-clause
|
|
949 On the @code{else} of an @code{if}-@code{else} construct.
|
|
950
|
|
951 @item catch-clause
|
|
952 On the @code{catch} and @code{finally} lines in
|
|
953 @code{try}@dots{}@code{catch} constructs in C++ and Java.
|
|
954
|
|
955 @item comment-intro
|
|
956 On a line containing only a comment introduction.
|
|
957
|
|
958 @item arglist-intro
|
|
959 On the first line in an argument list.
|
|
960
|
|
961 @item arglist-cont
|
|
962 On one of the subsequent argument list lines when no arguments follow on
|
|
963 the same line as the arglist opening parenthesis.
|
|
964
|
|
965 @item arglist-cont-nonempty
|
|
966 On one of the subsequent argument list lines when at least one argument
|
|
967 follows on the same line as the arglist opening parenthesis.
|
|
968
|
|
969 @item arglist-close
|
|
970 On the closing parenthesis of an argument list.
|
|
971
|
|
972 @item stream-op
|
|
973 On one of the lines continuing a stream operator construct.
|
|
974
|
|
975 @item inclass
|
|
976 On a construct that is nested inside a class definition. The
|
|
977 indentation is relative to the open brace of the class definition.
|
|
978
|
|
979 @item inextern-lang
|
|
980 On a construct that is nested inside an external language block.
|
|
981
|
|
982 @item inexpr-statement
|
|
983 On the first line of statement block inside an expression. This is used
|
|
984 for the GCC extension to C that uses the syntax @code{(@{ @dots{} @})}.
|
|
985 It is also used for the special functions that takes a statement block
|
|
986 as an argument in Pike.
|
|
987
|
|
988 @item inexpr-class
|
|
989 On the first line of a class definition inside an expression. This is
|
|
990 used for anonymous classes and anonymous array initializers in Java.
|
|
991
|
|
992 @item cpp-macro
|
|
993 On the start of a cpp macro.
|
|
994
|
|
995 @item friend
|
|
996 On a C++ @code{friend} declaration.
|
|
997
|
|
998 @item objc-method-intro
|
|
999 On the first line of an Objective-C method definition.
|
|
1000
|
|
1001 @item objc-method-args-cont
|
|
1002 On one of the lines continuing an Objective-C method definition.
|
|
1003
|
|
1004 @item objc-method-call-cont
|
|
1005 On one of the lines continuing an Objective-C method call.
|
|
1006
|
|
1007 @item inlambda
|
|
1008 Like @code{inclass}, but used inside lambda (i.e. anonymous) functions. Only
|
|
1009 used in Pike.
|
|
1010
|
|
1011 @item lambda-intro-cont
|
|
1012 On a line continuing the header of a lambda function, between the
|
|
1013 @code{lambda} keyword and the function body. Only used in Pike.
|
|
1014 @end table
|
|
1015
|
|
1016 @node Variables for C Indent
|
|
1017 @subsubsection Variables for C Indentation
|
|
1018
|
|
1019 This section describes additional variables which control the
|
|
1020 indentation behavior of C mode and related mode.
|
|
1021
|
|
1022 @table @code
|
|
1023 @item c-offsets-alist
|
|
1024 @vindex c-offsets-alist
|
|
1025 Association list of syntactic symbols and their indentation offsets.
|
|
1026 You should not set this directly, only with @code{c-set-offset}.
|
|
1027 @xref{Changing Indent Style}, for details.
|
|
1028
|
|
1029 @item c-style-alist
|
|
1030 @vindex c-style-alist
|
|
1031 Variable for defining indentation styles; see below.
|
|
1032
|
|
1033 @item c-basic-offset
|
|
1034 @vindex c-basic-offset
|
|
1035 Amount of basic offset used by @code{+} and @code{-} symbols in
|
|
1036 @code{c-offsets-alist}.@refill
|
|
1037
|
|
1038 @item c-special-indent-hook
|
|
1039 @vindex c-special-indent-hook
|
|
1040 Hook for user-defined special indentation adjustments. This hook is
|
|
1041 called after a line is indented by C mode and related modes.
|
|
1042 @end table
|
|
1043
|
|
1044 The variable @code{c-style-alist} specifies the predefined indentation
|
|
1045 styles. Each element has form @code{(@var{name}
|
|
1046 @var{variable-setting}@dots{})}, where @var{name} is the name of the
|
|
1047 style. Each @var{variable-setting} has the form @code{(@var{variable}
|
|
1048 . @var{value})}; @var{variable} is one of the customization variables
|
|
1049 used by C mode, and @var{value} is the value for that variable when
|
|
1050 using the selected style.
|
|
1051
|
|
1052 When @var{variable} is @code{c-offsets-alist}, that is a special case:
|
|
1053 @var{value} is appended to the front of the value of @code{c-offsets-alist}
|
|
1054 instead of replacing that value outright. Therefore, it is not necessary
|
|
1055 for @var{value} to specify each and every syntactic symbol---only those
|
|
1056 for which the style differs from the default.
|
|
1057
|
|
1058 The indentation of lines containing only comments is also affected by
|
|
1059 the variable @code{c-comment-only-line-offset} (@pxref{Comments in C}).
|
|
1060
|
|
1061 @node C Indent Styles
|
|
1062 @subsubsection C Indentation Styles
|
|
1063 @cindex c indentation styles
|
|
1064
|
|
1065 A @dfn{C style} is a collection of indentation style customizations.
|
|
1066 Emacs comes with several predefined indentation styles for C and related
|
|
1067 modes, including @code{gnu}, @code{k&r}, @code{bsd}, @code{stroustrup},
|
|
1068 @code{linux}, @code{python}, @code{java}, @code{whitesmith},
|
|
1069 @code{ellemtel}, and @code{cc-mode}. The default style is @code{gnu}.
|
|
1070
|
|
1071 @findex c-set-style
|
|
1072 @vindex c-default-style
|
|
1073 To choose the style you want, use the command @kbd{M-x c-set-style}.
|
|
1074 Specify a style name as an argument (case is not significant in C style
|
|
1075 names). The chosen style only affects newly visited buffers, not those
|
|
1076 you are already editing. You can also set the variable
|
|
1077 @code{c-default-style} to specify the style for various major modes.
|
|
1078 Its value should be an alist, in which each element specifies one major
|
|
1079 mode and which indentation style to use for it. For example,
|
|
1080
|
|
1081 @example
|
|
1082 (setq c-default-style
|
|
1083 '((java-mode . "java") (other . "gnu")))
|
|
1084 @end example
|
|
1085
|
|
1086 @noindent
|
|
1087 specifies an explicit choice for Java mode, and the default @samp{gnu}
|
|
1088 style for the other C-like modes.
|
|
1089
|
|
1090 @findex c-add-style
|
|
1091 To define a new C indentation style, call the function
|
|
1092 @code{c-add-style}:
|
|
1093
|
|
1094 @example
|
|
1095 (c-add-style @var{name} @var{values} @var{use-now})
|
|
1096 @end example
|
|
1097
|
|
1098 @noindent
|
|
1099 Here @var{name} is the name of the new style (a string), and
|
|
1100 @var{values} is an alist whose elements have the form
|
|
1101 @code{(@var{variable} . @var{value})}. The variables you specify should
|
|
1102 be among those documented in @ref{Variables for C Indent}.
|
|
1103
|
|
1104 If @var{use-now} is non-@code{nil}, @code{c-add-style} switches to the
|
|
1105 new style after defining it.
|
|
1106
|
|
1107 @node Matching
|
|
1108 @section Automatic Display Of Matching Parentheses
|
|
1109 @cindex matching parentheses
|
|
1110 @cindex parentheses, displaying matches
|
|
1111
|
|
1112 The Emacs parenthesis-matching feature is designed to show
|
|
1113 automatically how parentheses match in the text. Whenever you type a
|
|
1114 self-inserting character that is a closing delimiter, the cursor moves
|
|
1115 momentarily to the location of the matching opening delimiter, provided
|
|
1116 that is on the screen. If it is not on the screen, some text near it is
|
|
1117 displayed in the echo area. Either way, you can tell what grouping is
|
|
1118 being closed off.
|
|
1119
|
|
1120 In Lisp, automatic matching applies only to parentheses. In C, it
|
|
1121 applies to braces and brackets too. Emacs knows which characters to regard
|
|
1122 as matching delimiters based on the syntax table, which is set by the major
|
|
1123 mode. @xref{Syntax}.
|
|
1124
|
|
1125 If the opening delimiter and closing delimiter are mismatched---such as
|
|
1126 in @samp{[x)}---a warning message is displayed in the echo area. The
|
|
1127 correct matches are specified in the syntax table.
|
|
1128
|
|
1129 @vindex blink-matching-paren
|
|
1130 @vindex blink-matching-paren-distance
|
|
1131 @vindex blink-matching-delay
|
|
1132 Three variables control parenthesis match display.
|
|
1133 @code{blink-matching-paren} turns the feature on or off; @code{nil}
|
|
1134 turns it off, but the default is @code{t} to turn match display on.
|
|
1135 @code{blink-matching-delay} says how many seconds to wait; the default
|
|
1136 is 1, but on some systems it is useful to specify a fraction of a
|
|
1137 second. @code{blink-matching-paren-distance} specifies how many
|
|
1138 characters back to search to find the matching opening delimiter. If
|
|
1139 the match is not found in that far, scanning stops, and nothing is
|
|
1140 displayed. This is to prevent scanning for the matching delimiter from
|
|
1141 wasting lots of time when there is no match. The default is 12,000.
|
|
1142
|
|
1143 @cindex Show Paren mode
|
|
1144 @findex show-paren-mode
|
|
1145 When using X Windows, you can request a more powerful alternative kind
|
|
1146 of automatic parenthesis matching by enabling Show Paren mode. This
|
|
1147 mode turns off the usual kind of matching parenthesis display and
|
|
1148 instead uses highlighting to show what matches. Whenever point is after
|
|
1149 a close parenthesis, the close parenthesis and its matching open
|
|
1150 parenthesis are both highlighted; otherwise, if point is before an open
|
|
1151 parenthesis, the matching close parenthesis is highlighted. (There is
|
|
1152 no need to highlight the open parenthesis after point because the cursor
|
|
1153 appears on top of that character.) Use the command @kbd{M-x
|
|
1154 show-paren-mode} to enable or disable this mode.
|
|
1155
|
|
1156 @node Comments
|
|
1157 @section Manipulating Comments
|
|
1158 @cindex comments
|
|
1159
|
|
1160 Because comments are such an important part of programming, Emacs
|
|
1161 provides special commands for editing and inserting comments.
|
|
1162
|
|
1163 @menu
|
|
1164 * Comment Commands::
|
|
1165 * Multi-Line Comments::
|
|
1166 * Options for Comments::
|
|
1167 @end menu
|
|
1168
|
|
1169 @node Comment Commands
|
|
1170 @subsection Comment Commands
|
|
1171
|
|
1172 @kindex M-;
|
|
1173 @cindex indentation for comments
|
|
1174 @findex indent-for-comment
|
|
1175
|
|
1176 The comment commands insert, kill and align comments.
|
|
1177
|
|
1178 @c WideCommands
|
|
1179 @table @kbd
|
|
1180 @item M-;
|
|
1181 Insert or align comment (@code{indent-for-comment}).
|
|
1182 @item C-x ;
|
|
1183 Set comment column (@code{set-comment-column}).
|
|
1184 @item C-u - C-x ;
|
|
1185 Kill comment on current line (@code{kill-comment}).
|
|
1186 @item C-M-j
|
|
1187 Like @key{RET} followed by inserting and aligning a comment
|
|
1188 (@code{indent-new-comment-line}).
|
|
1189 @item M-x comment-region
|
|
1190 Add or remove comment delimiters on all the lines in the region.
|
|
1191 @end table
|
|
1192
|
|
1193 The command that creates a comment is @kbd{M-;} (@code{indent-for-comment}).
|
|
1194 If there is no comment already on the line, a new comment is created,
|
|
1195 aligned at a specific column called the @dfn{comment column}. The comment
|
|
1196 is created by inserting the string Emacs thinks comments should start with
|
|
1197 (the value of @code{comment-start}; see below). Point is left after that
|
|
1198 string. If the text of the line extends past the comment column, then the
|
|
1199 indentation is done to a suitable boundary (usually, at least one space is
|
|
1200 inserted). If the major mode has specified a string to terminate comments,
|
|
1201 that is inserted after point, to keep the syntax valid.
|
|
1202
|
|
1203 @kbd{M-;} can also be used to align an existing comment. If a line
|
|
1204 already contains the string that starts comments, then @kbd{M-;} just moves
|
|
1205 point after it and reindents it to the conventional place. Exception:
|
|
1206 comments starting in column 0 are not moved.
|
|
1207
|
|
1208 Some major modes have special rules for indenting certain kinds of
|
|
1209 comments in certain contexts. For example, in Lisp code, comments which
|
|
1210 start with two semicolons are indented as if they were lines of code,
|
|
1211 instead of at the comment column. Comments which start with three
|
|
1212 semicolons are supposed to start at the left margin. Emacs understands
|
|
1213 these conventions by indenting a double-semicolon comment using @key{TAB},
|
|
1214 and by not changing the indentation of a triple-semicolon comment at all.
|
|
1215
|
|
1216 @example
|
|
1217 ;; This function is just an example
|
|
1218 ;;; Here either two or three semicolons are appropriate.
|
|
1219 (defun foo (x)
|
|
1220 ;;; And now, the first part of the function:
|
|
1221 ;; The following line adds one.
|
|
1222 (1+ x)) ; This line adds one.
|
|
1223 @end example
|
|
1224
|
|
1225 In C code, a comment preceded on its line by nothing but whitespace
|
|
1226 is indented like a line of code.
|
|
1227
|
|
1228 Even when an existing comment is properly aligned, @kbd{M-;} is still
|
|
1229 useful for moving directly to the start of the comment.
|
|
1230
|
|
1231 @kindex C-u - C-x ;
|
|
1232 @findex kill-comment
|
|
1233 @kbd{C-u - C-x ;} (@code{kill-comment}) kills the comment on the current line,
|
|
1234 if there is one. The indentation before the start of the comment is killed
|
|
1235 as well. If there does not appear to be a comment in the line, nothing is
|
|
1236 done. To reinsert the comment on another line, move to the end of that
|
|
1237 line, do @kbd{C-y}, and then do @kbd{M-;} to realign it. Note that
|
|
1238 @kbd{C-u - C-x ;} is not a distinct key; it is @kbd{C-x ;} (@code{set-comment-column})
|
|
1239 with a negative argument. That command is programmed so that when it
|
|
1240 receives a negative argument it calls @code{kill-comment}. However,
|
|
1241 @code{kill-comment} is a valid command which you could bind directly to a
|
|
1242 key if you wanted to.
|
|
1243
|
|
1244 @node Multi-Line Comments
|
|
1245 @subsection Multiple Lines of Comments
|
|
1246
|
|
1247 @kindex C-M-j
|
|
1248 @cindex blank lines in programs
|
|
1249 @findex indent-new-comment-line
|
|
1250 If you are typing a comment and wish to continue it on another line,
|
|
1251 you can use the command @kbd{C-M-j} (@code{indent-new-comment-line}).
|
|
1252 This terminates the comment you are typing, creates a new blank line
|
|
1253 afterward, and begins a new comment indented under the old one. When
|
|
1254 Auto Fill mode is on, going past the fill column while typing a comment
|
|
1255 causes the comment to be continued in just this fashion. If point is
|
|
1256 not at the end of the line when @kbd{C-M-j} is typed, the text on
|
|
1257 the rest of the line becomes part of the new comment line.
|
|
1258
|
|
1259 @findex comment-region
|
|
1260 To turn existing lines into comment lines, use the @kbd{M-x
|
|
1261 comment-region} command. It adds comment delimiters to the lines that start
|
|
1262 in the region, thus commenting them out. With a negative argument, it
|
|
1263 does the opposite---it deletes comment delimiters from the lines in the
|
|
1264 region.
|
|
1265
|
|
1266 With a positive argument, @code{comment-region} duplicates the last
|
|
1267 character of the comment start sequence it adds; the argument specifies
|
|
1268 how many copies of the character to insert. Thus, in Lisp mode,
|
|
1269 @kbd{C-u 2 M-x comment-region} adds @samp{;;} to each line. Duplicating
|
|
1270 the comment delimiter is a way of calling attention to the comment. It
|
|
1271 can also affect how the comment is indented. In Lisp, for proper
|
|
1272 indentation, you should use an argument of two, if between defuns, and
|
|
1273 three, if within a defun.
|
|
1274
|
|
1275 @vindex comment-padding
|
|
1276 The variable @code{comment-padding} specifies how many spaces
|
|
1277 @code{comment-region} should insert on each line between the
|
|
1278 comment delimiter and the line's original text. The default is 1.
|
|
1279
|
|
1280 @node Options for Comments
|
|
1281 @subsection Options Controlling Comments
|
|
1282
|
|
1283 @vindex comment-column
|
|
1284 @kindex C-x ;
|
|
1285 @findex set-comment-column
|
|
1286 The comment column is stored in the variable @code{comment-column}. You
|
|
1287 can set it to a number explicitly. Alternatively, the command @kbd{C-x ;}
|
|
1288 (@code{set-comment-column}) sets the comment column to the column point is
|
|
1289 at. @kbd{C-u C-x ;} sets the comment column to match the last comment
|
|
1290 before point in the buffer, and then does a @kbd{M-;} to align the
|
|
1291 current line's comment under the previous one. Note that @kbd{C-u - C-x ;}
|
|
1292 runs the function @code{kill-comment} as described above.
|
|
1293
|
|
1294 The variable @code{comment-column} is per-buffer: setting the variable
|
|
1295 in the normal fashion affects only the current buffer, but there is a
|
|
1296 default value which you can change with @code{setq-default}.
|
|
1297 @xref{Locals}. Many major modes initialize this variable for the
|
|
1298 current buffer.
|
|
1299
|
|
1300 @vindex comment-start-skip
|
|
1301 The comment commands recognize comments based on the regular
|
|
1302 expression that is the value of the variable @code{comment-start-skip}.
|
|
1303 Make sure this regexp does not match the null string. It may match more
|
|
1304 than the comment starting delimiter in the strictest sense of the word;
|
|
1305 for example, in C mode the value of the variable is @code{@t{"/\\*+
|
|
1306 *"}}, which matches extra stars and spaces after the @samp{/*} itself.
|
|
1307 (Note that @samp{\\} is needed in Lisp syntax to include a @samp{\} in
|
|
1308 the string, which is needed to deny the first star its special meaning
|
|
1309 in regexp syntax. @xref{Regexps}.)
|
|
1310
|
|
1311 @vindex comment-start
|
|
1312 @vindex comment-end
|
|
1313 When a comment command makes a new comment, it inserts the value of
|
|
1314 @code{comment-start} to begin it. The value of @code{comment-end} is
|
|
1315 inserted after point, so that it will follow the text that you will insert
|
|
1316 into the comment. In C mode, @code{comment-start} has the value
|
|
1317 @w{@code{"/* "}} and @code{comment-end} has the value @w{@code{" */"}}.
|
|
1318
|
|
1319 @vindex comment-multi-line
|
|
1320 The variable @code{comment-multi-line} controls how @kbd{C-M-j}
|
|
1321 (@code{indent-new-comment-line}) behaves when used inside a comment. If
|
|
1322 @code{comment-multi-line} is @code{nil}, as it normally is, then the
|
|
1323 comment on the starting line is terminated and a new comment is started
|
|
1324 on the new following line. If @code{comment-multi-line} is not
|
|
1325 @code{nil}, then the new following line is set up as part of the same
|
|
1326 comment that was found on the starting line. This is done by not
|
|
1327 inserting a terminator on the old line, and not inserting a starter on
|
|
1328 the new line. In languages where multi-line comments work, the choice
|
|
1329 of value for this variable is a matter of taste.
|
|
1330
|
|
1331 @vindex comment-indent-function
|
|
1332 The variable @code{comment-indent-function} should contain a function
|
|
1333 that will be called to compute the indentation for a newly inserted
|
|
1334 comment or for aligning an existing comment. It is set differently by
|
|
1335 various major modes. The function is called with no arguments, but with
|
|
1336 point at the beginning of the comment, or at the end of a line if a new
|
|
1337 comment is to be inserted. It should return the column in which the
|
|
1338 comment ought to start. For example, in Lisp mode, the indent hook
|
|
1339 function bases its decision on how many semicolons begin an existing
|
|
1340 comment, and on the code in the preceding lines.
|
|
1341
|
|
1342 @node Balanced Editing
|
|
1343 @section Editing Without Unbalanced Parentheses
|
|
1344
|
|
1345 @table @kbd
|
|
1346 @item M-(
|
|
1347 Put parentheses around next sexp(s) (@code{insert-parentheses}).
|
|
1348 @item M-)
|
|
1349 Move past next close parenthesis and reindent
|
|
1350 (@code{move-past-close-and-reindent}).
|
|
1351 @end table
|
|
1352
|
|
1353 @kindex M-(
|
|
1354 @kindex M-)
|
|
1355 @findex insert-parentheses
|
|
1356 @findex move-past-close-and-reindent
|
|
1357 The commands @kbd{M-(} (@code{insert-parentheses}) and @kbd{M-)}
|
|
1358 (@code{move-past-close-and-reindent}) are designed to facilitate a style
|
|
1359 of editing which keeps parentheses balanced at all times. @kbd{M-(}
|
|
1360 inserts a pair of parentheses, either together as in @samp{()}, or, if
|
|
1361 given an argument, around the next several sexps. It leaves point after
|
|
1362 the open parenthesis. The command @kbd{M-)} moves past the close
|
|
1363 parenthesis, deleting any indentation preceding it, and indenting with
|
|
1364 @kbd{C-j} after it.
|
|
1365
|
|
1366 For example, instead of typing @kbd{( F O O )}, you can type @kbd{M-(
|
|
1367 F O O}, which has the same effect except for leaving the cursor before
|
|
1368 the close parenthesis.
|
|
1369
|
|
1370 @vindex parens-require-spaces
|
|
1371 @kbd{M-(} may insert a space before the open parenthesis, depending on
|
|
1372 the syntax class of the preceding character. Set
|
|
1373 @code{parens-require-spaces} to @code{nil} value if you wish to inhibit
|
|
1374 this.
|
|
1375
|
|
1376 @node Symbol Completion
|
|
1377 @section Completion for Symbol Names
|
|
1378 @cindex completion (symbol names)
|
|
1379
|
|
1380 Usually completion happens in the minibuffer. But one kind of completion
|
|
1381 is available in all buffers: completion for symbol names.
|
|
1382
|
|
1383 @kindex M-TAB
|
|
1384 The character @kbd{M-@key{TAB}} runs a command to complete the partial
|
|
1385 symbol before point against the set of meaningful symbol names. Any
|
|
1386 additional characters determined by the partial name are inserted at
|
|
1387 point.
|
|
1388
|
|
1389 If the partial name in the buffer has more than one possible completion
|
|
1390 and they have no additional characters in common, a list of all possible
|
|
1391 completions is displayed in another window.
|
|
1392
|
|
1393 @cindex completion using tags
|
|
1394 @cindex tags completion
|
|
1395 @cindex Info index completion
|
|
1396 @findex complete-symbol
|
|
1397 In most programming language major modes, @kbd{M-@key{TAB}} runs the
|
|
1398 command @code{complete-symbol}, which provides two kinds of completion.
|
|
1399 Normally it does completion based on a tags table (@pxref{Tags}); with a
|
|
1400 numeric argument (regardless of the value), it does completion based on
|
|
1401 the names listed in the Info file indexes for your language. Thus, to
|
|
1402 complete the name of a symbol defined in your own program, use
|
|
1403 @kbd{M-@key{TAB}} with no argument; to complete the name of a standard
|
|
1404 library function, use @kbd{C-u M-@key{TAB}}. Of course, Info-based
|
|
1405 completion works only if there is an Info file for the standard library
|
|
1406 functions of your language, and only if it is installed at your site.
|
|
1407
|
|
1408 @cindex Lisp symbol completion
|
|
1409 @cindex completion in Lisp
|
|
1410 @findex lisp-complete-symbol
|
|
1411 In Emacs-Lisp mode, the name space for completion normally consists of
|
|
1412 nontrivial symbols present in Emacs---those that have function
|
|
1413 definitions, values or properties. However, if there is an
|
|
1414 open-parenthesis immediately before the beginning of the partial symbol,
|
|
1415 only symbols with function definitions are considered as completions.
|
|
1416 The command which implements this is @code{lisp-complete-symbol}.
|
|
1417
|
|
1418 In Text mode and related modes, @kbd{M-@key{TAB}} completes words
|
|
1419 based on the spell-checker's dictionary. @xref{Spelling}.
|
|
1420
|
|
1421 @node Which Function
|
|
1422 @section Which Function Mode
|
|
1423
|
|
1424 Which Function mode is a minor mode that displays the current function
|
|
1425 name in the mode line, as you move around in a buffer.
|
|
1426
|
|
1427 @findex which-function-mode
|
|
1428 @vindex which-func-modes
|
|
1429 To enable (or disable) Which Function mode, use the command @kbd{M-x
|
|
1430 which-function-mode}. This command is global; it applies to all
|
|
1431 buffers, both existing ones and those yet to be created. However, this
|
|
1432 only affects certain major modes, those listed in the value of
|
|
1433 @code{which-func-modes}. (If the value is @code{t}, then Which Function
|
|
1434 mode applies to all major modes that know how to support it---which are
|
|
1435 the major modes that support Imenu.)
|
|
1436
|
|
1437 @node Documentation
|
|
1438 @section Documentation Commands
|
|
1439
|
|
1440 As you edit Lisp code to be run in Emacs, the commands @kbd{C-h f}
|
|
1441 (@code{describe-function}) and @kbd{C-h v} (@code{describe-variable}) can
|
|
1442 be used to print documentation of functions and variables that you want to
|
|
1443 call. These commands use the minibuffer to read the name of a function or
|
|
1444 variable to document, and display the documentation in a window.
|
|
1445
|
|
1446 For extra convenience, these commands provide default arguments based on
|
|
1447 the code in the neighborhood of point. @kbd{C-h f} sets the default to the
|
|
1448 function called in the innermost list containing point. @kbd{C-h v} uses
|
|
1449 the symbol name around or adjacent to point as its default.
|
|
1450
|
|
1451 @cindex Eldoc mode
|
|
1452 @findex eldoc-mode
|
|
1453 For Emacs Lisp code, you can also use Eldoc mode. This minor mode
|
|
1454 constantly displays in the echo area the argument list for the function
|
|
1455 being called at point. (In other words, it finds the function call that
|
|
1456 point is contained in, and displays the argument list of that function.)
|
|
1457 Eldoc mode applies in Emacs Lisp and Lisp Interaction modes only. Use
|
|
1458 the command @kbd{M-x eldoc-mode} to enable or disable this feature.
|
|
1459
|
|
1460 @findex info-lookup-symbol
|
|
1461 @findex info-lookup-file
|
|
1462 @kindex C-h C-i
|
|
1463 For C, Lisp, and other languages, you can use @kbd{C-h C-i}
|
|
1464 (@code{info-lookup-symbol}) to view the Info documentation for a symbol.
|
|
1465 You specify the symbol with the minibuffer; by default, it uses the
|
|
1466 symbol that appears in the buffer at point. The major mode determines
|
|
1467 where to look for documentation for the symbol---which Info files and
|
|
1468 which indices. You can also use @kbd{M-x info-lookup-file} to look for
|
|
1469 documentation for a file name.
|
|
1470
|
|
1471 @findex manual-entry
|
|
1472 You can read the ``man page'' for an operating system command, library
|
|
1473 function, or system call, with the @kbd{M-x manual-entry} command. It
|
|
1474 runs the @code{man} program to format the man page, and runs it
|
|
1475 asynchronously if your system permits, so that you can keep on editing
|
|
1476 while the page is being formatted. (MS-DOS and MS-Windows 3 do not
|
|
1477 permit asynchronous subprocesses, so on these systems you cannot edit
|
|
1478 while Emacs waits for @code{man} to exit.) The result goes in a buffer
|
|
1479 named @samp{*Man @var{topic}*}. These buffers use a special major mode,
|
|
1480 Man mode, that facilitates scrolling and examining other manual pages.
|
|
1481 For details, type @kbd{C-h m} while in a man page buffer.
|
|
1482
|
|
1483 @vindex Man-fontify-manpage-flag
|
|
1484 For a long man page, setting the faces properly can take substantial
|
|
1485 time. By default, Emacs uses faces in man pages if Emacs can display
|
|
1486 different fonts or colors. You can turn off use of faces in man pages
|
|
1487 by setting the variable @code{Man-fontify-manpage-flag} to @code{nil}.
|
|
1488
|
|
1489 @findex Man-fontify-manpage
|
|
1490 If you insert the text of a man page into an Emacs buffer in some
|
|
1491 other fashion, you can use the command @kbd{M-x Man-fontify-manpage} to
|
|
1492 perform the same conversions that @kbd{M-x manual-entry} does.
|
|
1493
|
|
1494 Eventually the GNU project hopes to replace most man pages with
|
|
1495 better-organized manuals that you can browse with Info. @xref{Misc
|
|
1496 Help}. Since this process is only partially completed, it is still
|
|
1497 useful to read manual pages.
|
|
1498
|
|
1499 @node Change Log
|
|
1500 @section Change Logs
|
|
1501
|
|
1502 @cindex change log
|
|
1503 @kindex C-x 4 a
|
|
1504 @findex add-change-log-entry-other-window
|
|
1505 The Emacs command @kbd{C-x 4 a} adds a new entry to the change log
|
|
1506 file for the file you are editing
|
|
1507 (@code{add-change-log-entry-other-window}).
|
|
1508
|
|
1509 A change log file contains a chronological record of when and why you
|
|
1510 have changed a program, consisting of a sequence of entries describing
|
|
1511 individual changes. Normally it is kept in a file called
|
|
1512 @file{ChangeLog} in the same directory as the file you are editing, or
|
|
1513 one of its parent directories. A single @file{ChangeLog} file can
|
|
1514 record changes for all the files in its directory and all its
|
|
1515 subdirectories.
|
|
1516
|
|
1517 A change log entry starts with a header line that contains your name,
|
|
1518 your email address (taken from the variable @code{user-mail-address}),
|
|
1519 and the current date and time. Aside from these header lines, every
|
|
1520 line in the change log starts with a space or a tab. The bulk of the
|
|
1521 entry consists of @dfn{items}, each of which starts with a line starting
|
|
1522 with whitespace and a star. Here are two entries, both dated in May
|
|
1523 1993, each with two items:
|
|
1524
|
|
1525 @iftex
|
|
1526 @medbreak
|
|
1527 @end iftex
|
|
1528 @smallexample
|
|
1529 1993-05-25 Richard Stallman <rms@@gnu.org>
|
|
1530
|
|
1531 * man.el: Rename symbols `man-*' to `Man-*'.
|
|
1532 (manual-entry): Make prompt string clearer.
|
|
1533
|
|
1534 * simple.el (blink-matching-paren-distance):
|
|
1535 Change default to 12,000.
|
|
1536
|
|
1537 1993-05-24 Richard Stallman <rms@@gnu.org>
|
|
1538
|
|
1539 * vc.el (minor-mode-map-alist): Don't use it if it's void.
|
|
1540 (vc-cancel-version): Doc fix.
|
|
1541 @end smallexample
|
|
1542
|
|
1543 @noindent
|
|
1544 (Previous Emacs versions used a different format for the date.)
|
|
1545
|
|
1546 One entry can describe several changes; each change should have its
|
|
1547 own item. Normally there should be a blank line between items. When
|
|
1548 items are related (parts of the same change, in different places), group
|
|
1549 them by leaving no blank line between them. The second entry above
|
|
1550 contains two items grouped in this way.
|
|
1551
|
|
1552 @kbd{C-x 4 a} visits the change log file and creates a new entry
|
|
1553 unless the most recent entry is for today's date and your name. It also
|
|
1554 creates a new item for the current file. For many languages, it can
|
|
1555 even guess the name of the function or other object that was changed.
|
|
1556
|
|
1557 @cindex Change Log mode
|
|
1558 @findex change-log-mode
|
|
1559 The change log file is visited in Change Log mode. In this major
|
|
1560 mode, each bunch of grouped items counts as one paragraph, and each
|
|
1561 entry is considered a page. This facilitates editing the entries.
|
|
1562 @kbd{C-j} and auto-fill indent each new line like the previous line;
|
|
1563 this is convenient for entering the contents of an entry.
|
|
1564
|
|
1565 Version control systems are another way to keep track of changes in your
|
|
1566 program and keep a change log. @xref{Log Buffer}.
|
|
1567
|
|
1568 @node Tags
|
|
1569 @section Tags Tables
|
|
1570 @cindex tags table
|
|
1571
|
|
1572 A @dfn{tags table} is a description of how a multi-file program is
|
|
1573 broken up into files. It lists the names of the component files and the
|
|
1574 names and positions of the functions (or other named subunits) in each
|
|
1575 file. Grouping the related files makes it possible to search or replace
|
|
1576 through all the files with one command. Recording the function names
|
|
1577 and positions makes possible the @kbd{M-.} command which finds the
|
|
1578 definition of a function by looking up which of the files it is in.
|
|
1579
|
|
1580 Tags tables are stored in files called @dfn{tags table files}. The
|
|
1581 conventional name for a tags table file is @file{TAGS}.
|
|
1582
|
|
1583 Each entry in the tags table records the name of one tag, the name of the
|
|
1584 file that the tag is defined in (implicitly), and the position in that file
|
|
1585 of the tag's definition.
|
|
1586
|
|
1587 Just what names from the described files are recorded in the tags table
|
|
1588 depends on the programming language of the described file. They
|
|
1589 normally include all functions and subroutines, and may also include
|
|
1590 global variables, data types, and anything else convenient. Each name
|
|
1591 recorded is called a @dfn{tag}.
|
|
1592
|
|
1593 @menu
|
|
1594 * Tag Syntax:: Tag syntax for various types of code and text files.
|
|
1595 * Create Tags Table:: Creating a tags table with @code{etags}.
|
|
1596 * Select Tags Table:: How to visit a tags table.
|
|
1597 * Find Tag:: Commands to find the definition of a specific tag.
|
|
1598 * Tags Search:: Using a tags table for searching and replacing.
|
|
1599 * List Tags:: Listing and finding tags defined in a file.
|
|
1600 @end menu
|
|
1601
|
|
1602 @node Tag Syntax
|
|
1603 @subsection Source File Tag Syntax
|
|
1604
|
|
1605 Here is how tag syntax is defined for the most popular languages:
|
|
1606
|
|
1607 @itemize @bullet
|
|
1608 @item
|
|
1609 In C code, any C function or typedef is a tag, and so are definitions of
|
|
1610 @code{struct}, @code{union} and @code{enum}. @code{#define} macro
|
|
1611 definitions and @code{enum} constants are also tags, unless you specify
|
|
1612 @samp{--no-defines} when making the tags table. Similarly, global
|
|
1613 variables are tags, unless you specify @samp{--no-globals}. Use of
|
|
1614 @samp{--no-globals} and @samp{--no-defines} can make the tags table file
|
|
1615 much smaller.
|
|
1616
|
|
1617 @item
|
|
1618 In C++ code, in addition to all the tag constructs of C code, member
|
|
1619 functions are also recognized, and optionally member variables if you
|
|
1620 use the @samp{--members} option. Tags for variables and functions in
|
|
1621 classes are named @samp{@var{class}::@var{variable}} and
|
|
1622 @samp{@var{class}::@var{function}}.
|
|
1623
|
|
1624 @item
|
|
1625 In Java code, tags include all the constructs recognized in C++, plus
|
|
1626 the @code{extends} and @code{implements} constructs. Tags for variables
|
|
1627 and functions in classes are named @samp{@var{class}.@var{variable}} and
|
|
1628 @samp{@var{class}.@var{function}}.
|
|
1629
|
|
1630 @item
|
|
1631 In La@TeX{} text, the argument of any of the commands @code{\chapter},
|
|
1632 @code{\section}, @code{\subsection}, @code{\subsubsection},
|
|
1633 @code{\eqno}, @code{\label}, @code{\ref}, @code{\cite}, @code{\bibitem},
|
|
1634 @code{\part}, @code{\appendix}, @code{\entry}, or @code{\index}, is a
|
|
1635 tag.@refill
|
|
1636
|
|
1637 Other commands can make tags as well, if you specify them in the
|
|
1638 environment variable @code{TEXTAGS} before invoking @code{etags}. The
|
|
1639 value of this environment variable should be a colon-separated list of
|
|
1640 command names. For example,
|
|
1641
|
|
1642 @example
|
|
1643 TEXTAGS="def:newcommand:newenvironment"
|
|
1644 export TEXTAGS
|
|
1645 @end example
|
|
1646
|
|
1647 @noindent
|
|
1648 specifies (using Bourne shell syntax) that the commands @samp{\def},
|
|
1649 @samp{\newcommand} and @samp{\newenvironment} also define tags.
|
|
1650
|
|
1651 @item
|
|
1652 In Lisp code, any function defined with @code{defun}, any variable
|
|
1653 defined with @code{defvar} or @code{defconst}, and in general the first
|
|
1654 argument of any expression that starts with @samp{(def} in column zero, is
|
|
1655 a tag.
|
|
1656
|
|
1657 @item
|
|
1658 In Scheme code, tags include anything defined with @code{def} or with a
|
|
1659 construct whose name starts with @samp{def}. They also include variables
|
|
1660 set with @code{set!} at top level in the file.
|
|
1661 @end itemize
|
|
1662
|
|
1663 Several other languages are also supported:
|
|
1664
|
|
1665 @itemize @bullet
|
|
1666 @item
|
|
1667 In assembler code, labels appearing at the beginning of a line,
|
|
1668 followed by a colon, are tags.
|
|
1669
|
|
1670 @item
|
|
1671 In Bison or Yacc input files, each rule defines as a tag the nonterminal
|
|
1672 it constructs. The portions of the file that contain C code are parsed
|
|
1673 as C code.
|
|
1674
|
|
1675 @item
|
|
1676 In Cobol code, tags are paragraph names; that is, any word starting in
|
|
1677 column 8 and followed by a period.
|
|
1678
|
|
1679 @item
|
|
1680 In Erlang code, the tags are the functions, records, and macros defined
|
|
1681 in the file.
|
|
1682
|
|
1683 @item
|
|
1684 In Fortran code, functions, subroutines and blockdata are tags.
|
|
1685
|
|
1686 @item
|
|
1687 In Objective C code, tags include Objective C definitions for classes,
|
|
1688 class categories, methods, and protocols.
|
|
1689
|
|
1690 @item
|
|
1691 In Pascal code, the tags are the functions and procedures defined in
|
|
1692 the file.
|
|
1693
|
|
1694 @item
|
|
1695 In Perl code, the tags are the procedures defined by the @code{sub}
|
|
1696 keyword.
|
|
1697
|
|
1698 @item
|
|
1699 In Postscript code, the tags are the functions.
|
|
1700
|
|
1701 @item
|
|
1702 In Prolog code, a tag name appears at the left margin.
|
|
1703 @end itemize
|
|
1704
|
|
1705 You can also generate tags based on regexp matching (@pxref{Create
|
|
1706 Tags Table}) to handle other formats and languages.
|
|
1707
|
|
1708 @node Create Tags Table
|
|
1709 @subsection Creating Tags Tables
|
|
1710 @cindex @code{etags} program
|
|
1711
|
|
1712 The @code{etags} program is used to create a tags table file. It knows
|
|
1713 the syntax of several languages, as described in
|
|
1714 @iftex
|
|
1715 the previous section.
|
|
1716 @end iftex
|
|
1717 @ifinfo
|
|
1718 @ref{Tag Syntax}.
|
|
1719 @end ifinfo
|
|
1720 Here is how to run @code{etags}:
|
|
1721
|
|
1722 @example
|
|
1723 etags @var{inputfiles}@dots{}
|
|
1724 @end example
|
|
1725
|
|
1726 @noindent
|
|
1727 The @code{etags} program reads the specified files, and writes a tags table
|
|
1728 named @file{TAGS} in the current working directory. @code{etags}
|
|
1729 recognizes the language used in an input file based on its file name and
|
|
1730 contents. You can specify the language with the
|
|
1731 @samp{--language=@var{name}} option, described below.
|
|
1732
|
|
1733 If the tags table data become outdated due to changes in the files
|
|
1734 described in the table, the way to update the tags table is the same way it
|
|
1735 was made in the first place. It is not necessary to do this often.
|
|
1736
|
|
1737 If the tags table fails to record a tag, or records it for the wrong
|
|
1738 file, then Emacs cannot possibly find its definition. However, if the
|
|
1739 position recorded in the tags table becomes a little bit wrong (due to
|
|
1740 some editing in the file that the tag definition is in), the only
|
|
1741 consequence is a slight delay in finding the tag. Even if the stored
|
|
1742 position is very wrong, Emacs will still find the tag, but it must
|
|
1743 search the entire file for it.
|
|
1744
|
|
1745 So you should update a tags table when you define new tags that you want
|
|
1746 to have listed, or when you move tag definitions from one file to another,
|
|
1747 or when changes become substantial. Normally there is no need to update
|
|
1748 the tags table after each edit, or even every day.
|
|
1749
|
|
1750 One tags table can effectively include another. Specify the included
|
|
1751 tags file name with the @samp{--include=@var{file}} option when creating
|
|
1752 the file that is to include it. The latter file then acts as if it
|
|
1753 contained all the files specified in the included file, as well as the
|
|
1754 files it directly contains.
|
|
1755
|
|
1756 If you specify the source files with relative file names when you run
|
|
1757 @code{etags}, the tags file will contain file names relative to the
|
|
1758 directory where the tags file was initially written. This way, you can
|
|
1759 move an entire directory tree containing both the tags file and the
|
|
1760 source files, and the tags file will still refer correctly to the source
|
|
1761 files.
|
|
1762
|
|
1763 If you specify absolute file names as arguments to @code{etags}, then
|
|
1764 the tags file will contain absolute file names. This way, the tags file
|
|
1765 will still refer to the same files even if you move it, as long as the
|
|
1766 source files remain in the same place. Absolute file names start with
|
|
1767 @samp{/}, or with @samp{@var{device}:/} on MS-DOS and MS-Windows.
|
|
1768
|
|
1769 When you want to make a tags table from a great number of files, you
|
|
1770 may have problems listing them on the command line, because some systems
|
|
1771 have a limit on its length. The simplest way to circumvent this limit
|
|
1772 is to tell @code{etags} to read the file names from its standard input,
|
|
1773 by typing a dash in place of the file names, like this:
|
|
1774
|
|
1775 @example
|
|
1776 find . -name "*.[chCH]" -print | etags -
|
|
1777 @end example
|
|
1778
|
|
1779 Use the option @samp{--language=@var{name}} to specify the language
|
|
1780 explicitly. You can intermix these options with file names; each one
|
|
1781 applies to the file names that follow it. Specify
|
|
1782 @samp{--language=auto} to tell @code{etags} to resume guessing the
|
|
1783 language from the file names and file contents. Specify
|
|
1784 @samp{--language=none} to turn off language-specific processing
|
|
1785 entirely; then @code{etags} recognizes tags by regexp matching alone.
|
|
1786 @samp{etags --help} prints the list of the languages @code{etags} knows,
|
|
1787 and the file name rules for guessing the language.
|
|
1788
|
|
1789 The @samp{--regex} option provides a general way of recognizing tags
|
|
1790 based on regexp matching. You can freely intermix it with file names.
|
|
1791 Each @samp{--regex} option adds to the preceding ones, and applies only
|
|
1792 to the following files. The syntax is:
|
|
1793
|
|
1794 @example
|
|
1795 --regex=/@var{tagregexp}[/@var{nameregexp}]/
|
|
1796 @end example
|
|
1797
|
|
1798 @noindent
|
|
1799 where @var{tagregexp} is used to match the lines to tag. It is always
|
|
1800 anchored, that is, it behaves as if preceded by @samp{^}. If you want
|
|
1801 to account for indentation, just match any initial number of blanks by
|
|
1802 beginning your regular expression with @samp{[ \t]*}. In the regular
|
|
1803 expressions, @samp{\} quotes the next character, and @samp{\t} stands
|
|
1804 for the tab character. Note that @code{etags} does not handle the other
|
|
1805 C escape sequences for special characters.
|
|
1806
|
|
1807 @cindex interval operator (in regexps)
|
|
1808 The syntax of regular expressions in @code{etags} is the same as in
|
|
1809 Emacs, augmented with the @dfn{interval operator}, which works as in
|
|
1810 @code{grep} and @code{ed}. The syntax of an interval operator is
|
|
1811 @samp{\@{@var{m},@var{n}\@}}, and its meaning is to match the preceding
|
|
1812 expression at least @var{m} times and up to @var{n} times.
|
|
1813
|
|
1814 You should not match more characters with @var{tagregexp} than that
|
|
1815 needed to recognize what you want to tag. If the match is such that
|
|
1816 more characters than needed are unavoidably matched by @var{tagregexp},
|
|
1817 you may find useful to add a @var{nameregexp}, in order to narrow the tag
|
|
1818 scope. You can find some examples below.
|
|
1819
|
|
1820 The @samp{-R} option deletes all the regexps defined with
|
|
1821 @samp{--regex} options. It applies to the file names following it, as
|
|
1822 you can see from the following example:
|
|
1823
|
|
1824 @example
|
|
1825 etags --regex=/@var{reg1}/ voo.doo --regex=/@var{reg2}/ \
|
|
1826 bar.ber -R --lang=lisp los.er
|
|
1827 @end example
|
|
1828
|
|
1829 @noindent
|
|
1830 Here @code{etags} chooses the parsing language for @file{voo.doo} and
|
|
1831 @file{bar.ber} according to their contents. @code{etags} also uses
|
|
1832 @var{reg1} to recognize additional tags in @file{voo.doo}, and both
|
|
1833 @var{reg1} and @var{reg2} to recognize additional tags in
|
|
1834 @file{bar.ber}. @code{etags} uses the Lisp tags rules, and no regexp
|
|
1835 matching, to recognize tags in @file{los.er}.
|
|
1836
|
|
1837 Here are some more examples. The regexps are quoted to protect them
|
|
1838 from shell interpretation.
|
|
1839
|
|
1840 @itemize @bullet
|
|
1841 @item
|
|
1842 Tag the @code{DEFVAR} macros in the emacs source files:
|
|
1843
|
|
1844 @smallexample
|
|
1845 --regex='/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
|
|
1846 @end smallexample
|
|
1847
|
|
1848 @item
|
|
1849 Tag VHDL files (this example is a single long line, broken here for
|
|
1850 formatting reasons):
|
|
1851
|
|
1852 @smallexample
|
|
1853 --language=none
|
|
1854 --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/'
|
|
1855 --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\
|
|
1856 \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
|
|
1857 @end smallexample
|
|
1858
|
|
1859 @item
|
|
1860 Tag Tcl files (this last example shows the usage of a @var{nameregexp}):
|
|
1861
|
|
1862 @smallexample
|
|
1863 --lang=none --regex='/proc[ \t]+\([^ \t]+\)/\1/'
|
|
1864 @end smallexample
|
|
1865 @end itemize
|
|
1866
|
|
1867 For a list of the other available @code{etags} options, execute
|
|
1868 @code{etags --help}.
|
|
1869
|
|
1870 @node Select Tags Table
|
|
1871 @subsection Selecting a Tags Table
|
|
1872
|
|
1873 @vindex tags-file-name
|
|
1874 @findex visit-tags-table
|
|
1875 Emacs has at any time one @dfn{selected} tags table, and all the commands
|
|
1876 for working with tags tables use the selected one. To select a tags table,
|
|
1877 type @kbd{M-x visit-tags-table}, which reads the tags table file name as an
|
|
1878 argument. The name @file{TAGS} in the default directory is used as the
|
|
1879 default file name.
|
|
1880
|
|
1881 All this command does is store the file name in the variable
|
|
1882 @code{tags-file-name}. Emacs does not actually read in the tags table
|
|
1883 contents until you try to use them. Setting this variable yourself is just
|
|
1884 as good as using @code{visit-tags-table}. The variable's initial value is
|
|
1885 @code{nil}; that value tells all the commands for working with tags tables
|
|
1886 that they must ask for a tags table file name to use.
|
|
1887
|
|
1888 Using @code{visit-tags-table} when a tags table is already loaded
|
|
1889 gives you a choice: you can add the new tags table to the current list
|
|
1890 of tags tables, or start a new list. The tags commands use all the tags
|
|
1891 tables in the current list. If you start a new list, the new tags table
|
|
1892 is used @emph{instead} of others. If you add the new table to the
|
|
1893 current list, it is used @emph{as well as} the others. When the tags
|
|
1894 commands scan the list of tags tables, they don't always start at the
|
|
1895 beginning of the list; they start with the first tags table (if any)
|
|
1896 that describes the current file, proceed from there to the end of the
|
|
1897 list, and then scan from the beginning of the list until they have
|
|
1898 covered all the tables in the list.
|
|
1899
|
|
1900 @vindex tags-table-list
|
|
1901 You can specify a precise list of tags tables by setting the variable
|
|
1902 @code{tags-table-list} to a list of strings, like this:
|
|
1903
|
|
1904 @c keep this on two lines for formatting in smallbook
|
|
1905 @example
|
|
1906 @group
|
|
1907 (setq tags-table-list
|
|
1908 '("~/emacs" "/usr/local/lib/emacs/src"))
|
|
1909 @end group
|
|
1910 @end example
|
|
1911
|
|
1912 @noindent
|
|
1913 This tells the tags commands to look at the @file{TAGS} files in your
|
|
1914 @file{~/emacs} directory and in the @file{/usr/local/lib/emacs/src}
|
|
1915 directory. The order depends on which file you are in and which tags
|
|
1916 table mentions that file, as explained above.
|
|
1917
|
|
1918 Do not set both @code{tags-file-name} and @code{tags-table-list}.
|
|
1919
|
|
1920 @node Find Tag
|
|
1921 @subsection Finding a Tag
|
|
1922
|
|
1923 The most important thing that a tags table enables you to do is to find
|
|
1924 the definition of a specific tag.
|
|
1925
|
|
1926 @table @kbd
|
|
1927 @item M-.@: @var{tag} @key{RET}
|
|
1928 Find first definition of @var{tag} (@code{find-tag}).
|
|
1929 @item C-u M-.
|
|
1930 Find next alternate definition of last tag specified.
|
|
1931 @item C-u - M-.
|
|
1932 Go back to previous tag found.
|
|
1933 @item C-M-. @var{pattern} @key{RET}
|
|
1934 Find a tag whose name matches @var{pattern} (@code{find-tag-regexp}).
|
|
1935 @item C-u C-M-.
|
|
1936 Find the next tag whose name matches the last pattern used.
|
|
1937 @item C-x 4 .@: @var{tag} @key{RET}
|
|
1938 Find first definition of @var{tag}, but display it in another window
|
|
1939 (@code{find-tag-other-window}).
|
|
1940 @item C-x 5 .@: @var{tag} @key{RET}
|
|
1941 Find first definition of @var{tag}, and create a new frame to select the
|
|
1942 buffer (@code{find-tag-other-frame}).
|
|
1943 @item M-*
|
|
1944 Pop back to where you previously invoked @kbd{M-.} and friends.
|
|
1945 @end table
|
|
1946
|
|
1947 @kindex M-.
|
|
1948 @findex find-tag
|
|
1949 @kbd{M-.}@: (@code{find-tag}) is the command to find the definition of
|
|
1950 a specified tag. It searches through the tags table for that tag, as a
|
|
1951 string, and then uses the tags table info to determine the file that the
|
|
1952 definition is in and the approximate character position in the file of
|
|
1953 the definition. Then @code{find-tag} visits that file, moves point to
|
|
1954 the approximate character position, and searches ever-increasing
|
|
1955 distances away to find the tag definition.
|
|
1956
|
|
1957 If an empty argument is given (just type @key{RET}), the sexp in the
|
|
1958 buffer before or around point is used as the @var{tag} argument.
|
|
1959 @xref{Lists}, for info on sexps.
|
|
1960
|
|
1961 You don't need to give @kbd{M-.} the full name of the tag; a part
|
|
1962 will do. This is because @kbd{M-.} finds tags in the table which
|
|
1963 contain @var{tag} as a substring. However, it prefers an exact match
|
|
1964 to a substring match. To find other tags that match the same
|
|
1965 substring, give @code{find-tag} a numeric argument, as in @kbd{C-u
|
|
1966 M-.}; this does not read a tag name, but continues searching the tags
|
|
1967 table's text for another tag containing the same substring last used.
|
|
1968 If you have a real @key{META} key, @kbd{M-0 M-.}@: is an easier
|
|
1969 alternative to @kbd{C-u M-.}.
|
|
1970
|
|
1971 @kindex C-x 4 .
|
|
1972 @findex find-tag-other-window
|
|
1973 @kindex C-x 5 .
|
|
1974 @findex find-tag-other-frame
|
|
1975 Like most commands that can switch buffers, @code{find-tag} has a
|
|
1976 variant that displays the new buffer in another window, and one that
|
|
1977 makes a new frame for it. The former is @kbd{C-x 4 .}, which invokes
|
|
1978 the command @code{find-tag-other-window}. The latter is @kbd{C-x 5 .},
|
|
1979 which invokes @code{find-tag-other-frame}.
|
|
1980
|
|
1981 To move back to places you've found tags recently, use @kbd{C-u -
|
|
1982 M-.}; more generally, @kbd{M-.} with a negative numeric argument. This
|
|
1983 command can take you to another buffer. @kbd{C-x 4 .} with a negative
|
|
1984 argument finds the previous tag location in another window.
|
|
1985
|
|
1986 @kindex M-*
|
|
1987 @findex pop-tag-mark
|
|
1988 @vindex find-tag-marker-ring-length
|
|
1989 As well as going back to places you've found tags recently, you can go
|
|
1990 back to places @emph{from where} you found them. Use @kbd{M-*}, which
|
|
1991 invokes the command @code{pop-tag-mark}, for this. Typically you would
|
|
1992 find and study the definition of something with @kbd{M-.} and then
|
|
1993 return to where you were with @kbd{M-*}.
|
|
1994
|
|
1995 Both @kbd{C-u - M-.} and @kbd{M-*} allow you to retrace your steps to
|
|
1996 a depth determined by the variable @code{find-tag-marker-ring-length}.
|
|
1997
|
|
1998 @findex find-tag-regexp
|
|
1999 @kindex C-M-.
|
|
2000 The command @kbd{C-M-.} (@code{find-tag-regexp}) visits the tags that
|
|
2001 match a specified regular expression. It is just like @kbd{M-.} except
|
|
2002 that it does regexp matching instead of substring matching.
|
|
2003
|
|
2004 @node Tags Search
|
|
2005 @subsection Searching and Replacing with Tags Tables
|
|
2006
|
|
2007 The commands in this section visit and search all the files listed in the
|
|
2008 selected tags table, one by one. For these commands, the tags table serves
|
|
2009 only to specify a sequence of files to search.
|
|
2010
|
|
2011 @table @kbd
|
|
2012 @item M-x tags-search @key{RET} @var{regexp} @key{RET}
|
|
2013 Search for @var{regexp} through the files in the selected tags
|
|
2014 table.
|
|
2015 @item M-x tags-query-replace @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
|
|
2016 Perform a @code{query-replace-regexp} on each file in the selected tags table.
|
|
2017 @item M-,
|
|
2018 Restart one of the commands above, from the current location of point
|
|
2019 (@code{tags-loop-continue}).
|
|
2020 @end table
|
|
2021
|
|
2022 @findex tags-search
|
|
2023 @kbd{M-x tags-search} reads a regexp using the minibuffer, then
|
|
2024 searches for matches in all the files in the selected tags table, one
|
|
2025 file at a time. It displays the name of the file being searched so you
|
|
2026 can follow its progress. As soon as it finds an occurrence,
|
|
2027 @code{tags-search} returns.
|
|
2028
|
|
2029 @kindex M-,
|
|
2030 @findex tags-loop-continue
|
|
2031 Having found one match, you probably want to find all the rest. To find
|
|
2032 one more match, type @kbd{M-,} (@code{tags-loop-continue}) to resume the
|
|
2033 @code{tags-search}. This searches the rest of the current buffer, followed
|
|
2034 by the remaining files of the tags table.@refill
|
|
2035
|
|
2036 @findex tags-query-replace
|
|
2037 @kbd{M-x tags-query-replace} performs a single
|
|
2038 @code{query-replace-regexp} through all the files in the tags table. It
|
|
2039 reads a regexp to search for and a string to replace with, just like
|
|
2040 ordinary @kbd{M-x query-replace-regexp}. It searches much like @kbd{M-x
|
|
2041 tags-search}, but repeatedly, processing matches according to your
|
|
2042 input. @xref{Replace}, for more information on query replace.
|
|
2043
|
|
2044 It is possible to get through all the files in the tags table with a
|
|
2045 single invocation of @kbd{M-x tags-query-replace}. But often it is
|
|
2046 useful to exit temporarily, which you can do with any input event that
|
|
2047 has no special query replace meaning. You can resume the query replace
|
|
2048 subsequently by typing @kbd{M-,}; this command resumes the last tags
|
|
2049 search or replace command that you did.
|
|
2050
|
|
2051 The commands in this section carry out much broader searches than the
|
|
2052 @code{find-tag} family. The @code{find-tag} commands search only for
|
|
2053 definitions of tags that match your substring or regexp. The commands
|
|
2054 @code{tags-search} and @code{tags-query-replace} find every occurrence
|
|
2055 of the regexp, as ordinary search commands and replace commands do in
|
|
2056 the current buffer.
|
|
2057
|
|
2058 These commands create buffers only temporarily for the files that they
|
|
2059 have to search (those which are not already visited in Emacs buffers).
|
|
2060 Buffers in which no match is found are quickly killed; the others
|
|
2061 continue to exist.
|
|
2062
|
|
2063 It may have struck you that @code{tags-search} is a lot like
|
|
2064 @code{grep}. You can also run @code{grep} itself as an inferior of
|
|
2065 Emacs and have Emacs show you the matching lines one by one. This works
|
|
2066 much like running a compilation; finding the source locations of the
|
|
2067 @code{grep} matches works like finding the compilation errors.
|
|
2068 @xref{Compilation}.
|
|
2069
|
|
2070 @node List Tags
|
|
2071 @subsection Tags Table Inquiries
|
|
2072
|
|
2073 @table @kbd
|
|
2074 @item M-x list-tags @key{RET} @var{file} @key{RET}
|
|
2075 Display a list of the tags defined in the program file @var{file}.
|
|
2076 @item M-x tags-apropos @key{RET} @var{regexp} @key{RET}
|
|
2077 Display a list of all tags matching @var{regexp}.
|
|
2078 @end table
|
|
2079
|
|
2080 @findex list-tags
|
|
2081 @kbd{M-x list-tags} reads the name of one of the files described by
|
|
2082 the selected tags table, and displays a list of all the tags defined in
|
|
2083 that file. The ``file name'' argument is really just a string to
|
|
2084 compare against the file names recorded in the tags table; it is read as
|
|
2085 a string rather than as a file name. Therefore, completion and
|
|
2086 defaulting are not available, and you must enter the file name the same
|
|
2087 way it appears in the tags table. Do not include a directory as part of
|
|
2088 the file name unless the file name recorded in the tags table includes a
|
|
2089 directory.
|
|
2090
|
|
2091 @findex tags-apropos
|
|
2092 @kbd{M-x tags-apropos} is like @code{apropos} for tags
|
|
2093 (@pxref{Apropos}). It reads a regexp, then finds all the tags in the
|
|
2094 selected tags table whose entries match that regexp, and displays the
|
|
2095 tag names found.
|
|
2096
|
|
2097 You can also perform completion in the buffer on the name space of tag
|
|
2098 names in the current tags tables. @xref{Symbol Completion}.
|
|
2099
|
|
2100 @node Emerge
|
|
2101 @section Merging Files with Emerge
|
|
2102 @cindex Emerge
|
|
2103 @cindex merging files
|
|
2104
|
|
2105 It's not unusual for programmers to get their signals crossed and modify
|
|
2106 the same program in two different directions. To recover from this
|
|
2107 confusion, you need to merge the two versions. Emerge makes this
|
|
2108 easier. See also @ref{Comparing Files}, for commands to compare
|
|
2109 in a more manual fashion, and @ref{Emerge,,, ediff, The Ediff Manual}.
|
|
2110
|
|
2111 @menu
|
|
2112 * Overview of Emerge:: How to start Emerge. Basic concepts.
|
|
2113 * Submodes of Emerge:: Fast mode vs. Edit mode.
|
|
2114 Skip Prefers mode and Auto Advance mode.
|
|
2115 * State of Difference:: You do the merge by specifying state A or B
|
|
2116 for each difference.
|
|
2117 * Merge Commands:: Commands for selecting a difference,
|
|
2118 changing states of differences, etc.
|
|
2119 * Exiting Emerge:: What to do when you've finished the merge.
|
|
2120 * Combining in Emerge:: How to keep both alternatives for a difference.
|
|
2121 * Fine Points of Emerge:: Misc.
|
|
2122 @end menu
|
|
2123
|
|
2124 @node Overview of Emerge
|
|
2125 @subsection Overview of Emerge
|
|
2126
|
|
2127 To start Emerge, run one of these four commands:
|
|
2128
|
|
2129 @table @kbd
|
|
2130 @item M-x emerge-files
|
|
2131 @findex emerge-files
|
|
2132 Merge two specified files.
|
|
2133
|
|
2134 @item M-x emerge-files-with-ancestor
|
|
2135 @findex emerge-files-with-ancestor
|
|
2136 Merge two specified files, with reference to a common ancestor.
|
|
2137
|
|
2138 @item M-x emerge-buffers
|
|
2139 @findex emerge-buffers
|
|
2140 Merge two buffers.
|
|
2141
|
|
2142 @item M-x emerge-buffers-with-ancestor
|
|
2143 @findex emerge-buffers-with-ancestor
|
|
2144 Merge two buffers with reference to a common ancestor in a third
|
|
2145 buffer.
|
|
2146 @end table
|
|
2147
|
|
2148 @cindex merge buffer (Emerge)
|
|
2149 @cindex A and B buffers (Emerge)
|
|
2150 The Emerge commands compare two files or buffers, and display the
|
|
2151 comparison in three buffers: one for each input text (the @dfn{A buffer}
|
|
2152 and the @dfn{B buffer}), and one (the @dfn{merge buffer}) where merging
|
|
2153 takes place. The merge buffer shows the full merged text, not just the
|
|
2154 differences. Wherever the two input texts differ, you can choose which
|
|
2155 one of them to include in the merge buffer.
|
|
2156
|
|
2157 The Emerge commands that take input from existing buffers use only the
|
|
2158 accessible portions of those buffers, if they are narrowed
|
|
2159 (@pxref{Narrowing}).
|
|
2160
|
|
2161 If a common ancestor version is available, from which the two texts to
|
|
2162 be merged were both derived, Emerge can use it to guess which
|
|
2163 alternative is right. Wherever one current version agrees with the
|
|
2164 ancestor, Emerge presumes that the other current version is a deliberate
|
|
2165 change which should be kept in the merged version. Use the
|
|
2166 @samp{with-ancestor} commands if you want to specify a common ancestor
|
|
2167 text. These commands read three file or buffer names---variant A,
|
|
2168 variant B, and the common ancestor.
|
|
2169
|
|
2170 After the comparison is done and the buffers are prepared, the
|
|
2171 interactive merging starts. You control the merging by typing special
|
|
2172 @dfn{merge commands} in the merge buffer. The merge buffer shows you a
|
|
2173 full merged text, not just differences. For each run of differences
|
|
2174 between the input texts, you can choose which one of them to keep, or
|
|
2175 edit them both together.
|
|
2176
|
|
2177 The merge buffer uses a special major mode, Emerge mode, with commands
|
|
2178 for making these choices. But you can also edit the buffer with
|
|
2179 ordinary Emacs commands.
|
|
2180
|
|
2181 At any given time, the attention of Emerge is focused on one
|
|
2182 particular difference, called the @dfn{selected} difference. This
|
|
2183 difference is marked off in the three buffers like this:
|
|
2184
|
|
2185 @example
|
|
2186 vvvvvvvvvvvvvvvvvvvv
|
|
2187 @var{text that differs}
|
|
2188 ^^^^^^^^^^^^^^^^^^^^
|
|
2189 @end example
|
|
2190
|
|
2191 @noindent
|
|
2192 Emerge numbers all the differences sequentially and the mode
|
|
2193 line always shows the number of the selected difference.
|
|
2194
|
|
2195 Normally, the merge buffer starts out with the A version of the text.
|
|
2196 But when the A version of a difference agrees with the common ancestor,
|
|
2197 then the B version is initially preferred for that difference.
|
|
2198
|
|
2199 Emerge leaves the merged text in the merge buffer when you exit. At
|
|
2200 that point, you can save it in a file with @kbd{C-x C-w}. If you give a
|
|
2201 numeric argument to @code{emerge-files} or
|
|
2202 @code{emerge-files-with-ancestor}, it reads the name of the output file
|
|
2203 using the minibuffer. (This is the last file name those commands read.)
|
|
2204 Then exiting from Emerge saves the merged text in the output file.
|
|
2205
|
|
2206 Normally, Emerge commands save the output buffer in its file when you
|
|
2207 exit. If you abort Emerge with @kbd{C-]}, the Emerge command does not
|
|
2208 save the output buffer, but you can save it yourself if you wish.
|
|
2209
|
|
2210 @node Submodes of Emerge
|
|
2211 @subsection Submodes of Emerge
|
|
2212
|
|
2213 You can choose between two modes for giving merge commands: Fast mode
|
|
2214 and Edit mode. In Fast mode, basic merge commands are single
|
|
2215 characters, but ordinary Emacs commands are disabled. This is
|
|
2216 convenient if you use only merge commands. In Edit mode, all merge
|
|
2217 commands start with the prefix key @kbd{C-c C-c}, and the normal Emacs
|
|
2218 commands are also available. This allows editing the merge buffer, but
|
|
2219 slows down Emerge operations.
|
|
2220
|
|
2221 Use @kbd{e} to switch to Edit mode, and @kbd{C-c C-c f} to switch to
|
|
2222 Fast mode. The mode line indicates Edit and Fast modes with @samp{E}
|
|
2223 and @samp{F}.
|
|
2224
|
|
2225 Emerge has two additional submodes that affect how particular merge
|
|
2226 commands work: Auto Advance mode and Skip Prefers mode.
|
|
2227
|
|
2228 If Auto Advance mode is in effect, the @kbd{a} and @kbd{b} commands
|
|
2229 advance to the next difference. This lets you go through the merge
|
|
2230 faster as long as you simply choose one of the alternatives from the
|
|
2231 input. The mode line indicates Auto Advance mode with @samp{A}.
|
|
2232
|
|
2233 If Skip Prefers mode is in effect, the @kbd{n} and @kbd{p} commands
|
|
2234 skip over differences in states prefer-A and prefer-B (@pxref{State of
|
|
2235 Difference}). Thus you see only differences for which neither version
|
|
2236 is presumed ``correct.'' The mode line indicates Skip Prefers mode with
|
|
2237 @samp{S}.
|
|
2238
|
|
2239 @findex emerge-auto-advance-mode
|
|
2240 @findex emerge-skip-prefers-mode
|
|
2241 Use the command @kbd{s a} (@code{emerge-auto-advance-mode}) to set or
|
|
2242 clear Auto Advance mode. Use @kbd{s s}
|
|
2243 (@code{emerge-skip-prefers-mode}) to set or clear Skip Prefers mode.
|
|
2244 These commands turn on the mode with a positive argument, turns it off
|
|
2245 with a negative or zero argument, and toggle the mode with no argument.
|
|
2246
|
|
2247 @node State of Difference
|
|
2248 @subsection State of a Difference
|
|
2249
|
|
2250 In the merge buffer, a difference is marked with lines of @samp{v} and
|
|
2251 @samp{^} characters. Each difference has one of these seven states:
|
|
2252
|
|
2253 @table @asis
|
|
2254 @item A
|
|
2255 The difference is showing the A version. The @kbd{a} command always
|
|
2256 produces this state; the mode line indicates it with @samp{A}.
|
|
2257
|
|
2258 @item B
|
|
2259 The difference is showing the B version. The @kbd{b} command always
|
|
2260 produces this state; the mode line indicates it with @samp{B}.
|
|
2261
|
|
2262 @item default-A
|
|
2263 @itemx default-B
|
|
2264 The difference is showing the A or the B state by default, because you
|
|
2265 haven't made a choice. All differences start in the default-A state
|
|
2266 (and thus the merge buffer is a copy of the A buffer), except those for
|
|
2267 which one alternative is ``preferred'' (see below).
|
|
2268
|
|
2269 When you select a difference, its state changes from default-A or
|
|
2270 default-B to plain A or B. Thus, the selected difference never has
|
|
2271 state default-A or default-B, and these states are never displayed in
|
|
2272 the mode line.
|
|
2273
|
|
2274 The command @kbd{d a} chooses default-A as the default state, and @kbd{d
|
|
2275 b} chooses default-B. This chosen default applies to all differences
|
|
2276 which you haven't ever selected and for which no alternative is preferred.
|
|
2277 If you are moving through the merge sequentially, the differences you
|
|
2278 haven't selected are those following the selected one. Thus, while
|
|
2279 moving sequentially, you can effectively make the A version the default
|
|
2280 for some sections of the merge buffer and the B version the default for
|
|
2281 others by using @kbd{d a} and @kbd{d b} between sections.
|
|
2282
|
|
2283 @item prefer-A
|
|
2284 @itemx prefer-B
|
|
2285 The difference is showing the A or B state because it is
|
|
2286 @dfn{preferred}. This means that you haven't made an explicit choice,
|
|
2287 but one alternative seems likely to be right because the other
|
|
2288 alternative agrees with the common ancestor. Thus, where the A buffer
|
|
2289 agrees with the common ancestor, the B version is preferred, because
|
|
2290 chances are it is the one that was actually changed.
|
|
2291
|
|
2292 These two states are displayed in the mode line as @samp{A*} and @samp{B*}.
|
|
2293
|
|
2294 @item combined
|
|
2295 The difference is showing a combination of the A and B states, as a
|
|
2296 result of the @kbd{x c} or @kbd{x C} commands.
|
|
2297
|
|
2298 Once a difference is in this state, the @kbd{a} and @kbd{b} commands
|
|
2299 don't do anything to it unless you give them a numeric argument.
|
|
2300
|
|
2301 The mode line displays this state as @samp{comb}.
|
|
2302 @end table
|
|
2303
|
|
2304 @node Merge Commands
|
|
2305 @subsection Merge Commands
|
|
2306
|
|
2307 Here are the Merge commands for Fast mode; in Edit mode, precede them
|
|
2308 with @kbd{C-c C-c}:
|
|
2309
|
|
2310 @table @kbd
|
|
2311 @item p
|
|
2312 Select the previous difference.
|
|
2313
|
|
2314 @item n
|
|
2315 Select the next difference.
|
|
2316
|
|
2317 @item a
|
|
2318 Choose the A version of this difference.
|
|
2319
|
|
2320 @item b
|
|
2321 Choose the B version of this difference.
|
|
2322
|
|
2323 @item C-u @var{n} j
|
|
2324 Select difference number @var{n}.
|
|
2325
|
|
2326 @item .
|
|
2327 Select the difference containing point. You can use this command in the
|
|
2328 merge buffer or in the A or B buffer.
|
|
2329
|
|
2330 @item q
|
|
2331 Quit---finish the merge.
|
|
2332
|
|
2333 @item C-]
|
|
2334 Abort---exit merging and do not save the output.
|
|
2335
|
|
2336 @item f
|
|
2337 Go into Fast mode. (In Edit mode, this is actually @kbd{C-c C-c f}.)
|
|
2338
|
|
2339 @item e
|
|
2340 Go into Edit mode.
|
|
2341
|
|
2342 @item l
|
|
2343 Recenter (like @kbd{C-l}) all three windows.
|
|
2344
|
|
2345 @item -
|
|
2346 Specify part of a prefix numeric argument.
|
|
2347
|
|
2348 @item @var{digit}
|
|
2349 Also specify part of a prefix numeric argument.
|
|
2350
|
|
2351 @item d a
|
|
2352 Choose the A version as the default from here down in
|
|
2353 the merge buffer.
|
|
2354
|
|
2355 @item d b
|
|
2356 Choose the B version as the default from here down in
|
|
2357 the merge buffer.
|
|
2358
|
|
2359 @item c a
|
|
2360 Copy the A version of this difference into the kill ring.
|
|
2361
|
|
2362 @item c b
|
|
2363 Copy the B version of this difference into the kill ring.
|
|
2364
|
|
2365 @item i a
|
|
2366 Insert the A version of this difference at point.
|
|
2367
|
|
2368 @item i b
|
|
2369 Insert the B version of this difference at point.
|
|
2370
|
|
2371 @item m
|
|
2372 Put point and mark around the difference.
|
|
2373
|
|
2374 @item ^
|
|
2375 Scroll all three windows down (like @kbd{M-v}).
|
|
2376
|
|
2377 @item v
|
|
2378 Scroll all three windows up (like @kbd{C-v}).
|
|
2379
|
|
2380 @item <
|
|
2381 Scroll all three windows left (like @kbd{C-x <}).
|
|
2382
|
|
2383 @item >
|
|
2384 Scroll all three windows right (like @kbd{C-x >}).
|
|
2385
|
|
2386 @item |
|
|
2387 Reset horizontal scroll on all three windows.
|
|
2388
|
|
2389 @item x 1
|
|
2390 Shrink the merge window to one line. (Use @kbd{C-u l} to restore it
|
|
2391 to full size.)
|
|
2392
|
|
2393 @item x c
|
|
2394 Combine the two versions of this difference (@pxref{Combining in
|
|
2395 Emerge}).
|
|
2396
|
|
2397 @item x f
|
|
2398 Show the names of the files/buffers Emerge is operating on, in a Help
|
|
2399 window. (Use @kbd{C-u l} to restore windows.)
|
|
2400
|
|
2401 @item x j
|
|
2402 Join this difference with the following one.
|
|
2403 (@kbd{C-u x j} joins this difference with the previous one.)
|
|
2404
|
|
2405 @item x s
|
|
2406 Split this difference into two differences. Before you use this
|
|
2407 command, position point in each of the three buffers at the place where
|
|
2408 you want to split the difference.
|
|
2409
|
|
2410 @item x t
|
|
2411 Trim identical lines off the top and bottom of the difference.
|
|
2412 Such lines occur when the A and B versions are
|
|
2413 identical but differ from the ancestor version.
|
|
2414 @end table
|
|
2415
|
|
2416 @node Exiting Emerge
|
|
2417 @subsection Exiting Emerge
|
|
2418
|
|
2419 The @kbd{q} command (@code{emerge-quit}) finishes the merge, storing
|
|
2420 the results into the output file if you specified one. It restores the
|
|
2421 A and B buffers to their proper contents, or kills them if they were
|
|
2422 created by Emerge and you haven't changed them. It also disables the
|
|
2423 Emerge commands in the merge buffer, since executing them later could
|
|
2424 damage the contents of the various buffers.
|
|
2425
|
|
2426 @kbd{C-]} aborts the merge. This means exiting without writing the
|
|
2427 output file. If you didn't specify an output file, then there is no
|
|
2428 real difference between aborting and finishing the merge.
|
|
2429
|
|
2430 If the Emerge command was called from another Lisp program, then its
|
|
2431 return value is @code{t} for successful completion, or @code{nil} if you
|
|
2432 abort.
|
|
2433
|
|
2434 @node Combining in Emerge
|
|
2435 @subsection Combining the Two Versions
|
|
2436
|
|
2437 Sometimes you want to keep @emph{both} alternatives for a particular
|
|
2438 difference. To do this, use @kbd{x c}, which edits the merge buffer
|
|
2439 like this:
|
|
2440
|
|
2441 @example
|
|
2442 @group
|
|
2443 #ifdef NEW
|
|
2444 @var{version from A buffer}
|
|
2445 #else /* not NEW */
|
|
2446 @var{version from B buffer}
|
|
2447 #endif /* not NEW */
|
|
2448 @end group
|
|
2449 @end example
|
|
2450
|
|
2451 @noindent
|
|
2452 @vindex emerge-combine-versions-template
|
|
2453 While this example shows C preprocessor conditionals delimiting the two
|
|
2454 alternative versions, you can specify the strings to use by setting
|
|
2455 the variable @code{emerge-combine-versions-template} to a string of your
|
|
2456 choice. In the string, @samp{%a} says where to put version A, and
|
|
2457 @samp{%b} says where to put version B. The default setting, which
|
|
2458 produces the results shown above, looks like this:
|
|
2459
|
|
2460 @example
|
|
2461 @group
|
|
2462 "#ifdef NEW\n%a#else /* not NEW */\n%b#endif /* not NEW */\n"
|
|
2463 @end group
|
|
2464 @end example
|
|
2465
|
|
2466 @node Fine Points of Emerge
|
|
2467 @subsection Fine Points of Emerge
|
|
2468
|
|
2469 During the merge, you mustn't try to edit the A and B buffers yourself.
|
|
2470 Emerge modifies them temporarily, but ultimately puts them back the way
|
|
2471 they were.
|
|
2472
|
|
2473 You can have any number of merges going at once---just don't use any one
|
|
2474 buffer as input to more than one merge at once, since the temporary
|
|
2475 changes made in these buffers would get in each other's way.
|
|
2476
|
|
2477 Starting Emerge can take a long time because it needs to compare the
|
|
2478 files fully. Emacs can't do anything else until @code{diff} finishes.
|
|
2479 Perhaps in the future someone will change Emerge to do the comparison in
|
|
2480 the background when the input files are large---then you could keep on
|
|
2481 doing other things with Emacs until Emerge is ready to accept
|
|
2482 commands.
|
|
2483
|
|
2484 @vindex emerge-startup-hook
|
|
2485 After setting up the merge, Emerge runs the hook
|
|
2486 @code{emerge-startup-hook} (@pxref{Hooks}).
|
|
2487
|
|
2488 @node C Modes
|
|
2489 @section C and Related Modes
|
|
2490 @cindex C mode
|
|
2491 @cindex Java mode
|
|
2492 @cindex Pike mode
|
|
2493 @cindex IDL mode
|
|
2494 @cindex CORBA IDL mode
|
|
2495 @cindex Objective C mode
|
|
2496 @cindex C++ mode
|
|
2497 @cindex mode, Java
|
|
2498 @cindex mode, C
|
|
2499 @cindex mode, Objective C
|
|
2500 @cindex mode, CORBA IDL
|
|
2501 @cindex mode, Pike
|
|
2502
|
|
2503 This section describes special features available in C, C++,
|
|
2504 Objective-C, Java, CORBA IDL, and Pike modes. When we say ``C mode and
|
|
2505 related modes,'' those are the modes we mean.
|
|
2506
|
|
2507 @menu
|
|
2508 * Motion in C::
|
|
2509 * Electric C::
|
|
2510 * Hungry Delete::
|
|
2511 * Other C Commands::
|
|
2512 * Comments in C::
|
|
2513 @end menu
|
|
2514
|
|
2515 @node Motion in C
|
|
2516 @subsection C Mode Motion Commands
|
|
2517
|
|
2518 This section describes commands for moving point, in C mode and
|
|
2519 related modes.
|
|
2520
|
|
2521 @table @code
|
|
2522 @item C-c C-u
|
|
2523 @kindex C-c C-u @r{(C mode)}
|
|
2524 @findex c-up-conditional
|
|
2525 Move point back to the containing preprocessor conditional, leaving the
|
|
2526 mark behind. A prefix argument acts as a repeat count. With a negative
|
|
2527 argument, move point forward to the end of the containing
|
|
2528 preprocessor conditional. When going backwards, @code{#elif} is treated
|
|
2529 like @code{#else} followed by @code{#if}. When going forwards,
|
|
2530 @code{#elif} is ignored.@refill
|
|
2531
|
|
2532 @item C-c C-p
|
|
2533 @kindex C-c C-p @r{(C mode)}
|
|
2534 @findex c-backward-conditional
|
|
2535 Move point back over a preprocessor conditional, leaving the mark
|
|
2536 behind. A prefix argument acts as a repeat count. With a negative
|
|
2537 argument, move forward.
|
|
2538
|
|
2539 @item C-c C-n
|
|
2540 @kindex C-c C-n @r{(C mode)}
|
|
2541 @findex c-forward-conditional
|
|
2542 Move point forward across a preprocessor conditional, leaving the mark
|
|
2543 behind. A prefix argument acts as a repeat count. With a negative
|
|
2544 argument, move backward.
|
|
2545
|
|
2546 @item M-a
|
|
2547 @kindex ESC a
|
|
2548 @findex c-beginning-of-statement
|
|
2549 Move point to the beginning of the innermost C statement
|
|
2550 (@code{c-beginning-of-statement}). If point is already at the beginning
|
|
2551 of a statement, move to the beginning of the preceding statement. With
|
|
2552 prefix argument @var{n}, move back @var{n} @minus{} 1 statements.
|
|
2553
|
|
2554 If point is within a string or comment, or next to a comment (only
|
|
2555 whitespace between them), this command moves by sentences instead of
|
|
2556 statements.
|
|
2557
|
|
2558 When called from a program, this function takes three optional
|
|
2559 arguments: the numeric prefix argument, a buffer position limit
|
|
2560 (don't move back before that place), and a flag that controls whether
|
|
2561 to do sentence motion when inside of a comment.
|
|
2562
|
|
2563 @item M-e
|
|
2564 @kindex ESC e
|
|
2565 @findex c-end-of-statement
|
|
2566 Move point to the end of the innermost C statement; like @kbd{M-a}
|
|
2567 except that it moves in the other direction (@code{c-end-of-statement}).
|
|
2568
|
|
2569 @item M-x c-backward-into-nomenclature
|
|
2570 @findex c-backward-into-nomenclature
|
|
2571 Move point backward to beginning of a C++ nomenclature section or word.
|
|
2572 With prefix argument @var{n}, move @var{n} times. If @var{n} is
|
|
2573 negative, move forward. C++ nomenclature means a symbol name in the
|
|
2574 style of NamingSymbolsWithMixedCaseAndNoUnderlines; each capital letter
|
|
2575 begins a section or word.
|
|
2576
|
|
2577 In the GNU project, we recommend using underscores to separate words
|
|
2578 within an identifier in C or C++, rather than using case distinctions.
|
|
2579
|
|
2580 @item M-x c-forward-into-nomenclature
|
|
2581 @findex c-forward-into-nomenclature
|
|
2582 Move point forward to end of a C++ nomenclature section or word.
|
|
2583 With prefix argument @var{n}, move @var{n} times.
|
|
2584 @end table
|
|
2585
|
|
2586 @node Electric C
|
|
2587 @subsection Electric C Characters
|
|
2588
|
|
2589 In C mode and related modes, certain printing characters are
|
|
2590 ``electric''---in addition to inserting themselves, they also reindent
|
|
2591 the current line and may insert newlines. This feature is controlled by
|
|
2592 the variable @code{c-auto-newline}. The ``electric'' characters are
|
|
2593 @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#}, @kbd{;}, @kbd{,}, @kbd{<},
|
|
2594 @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and @kbd{)}.
|
|
2595
|
|
2596 Electric characters insert newlines only when the @dfn{auto-newline}
|
|
2597 feature is enabled (indicated by @samp{/a} in the mode line after the
|
|
2598 mode name). This feature is controlled by the variable
|
|
2599 @code{c-auto-newline}. You can turn this feature on or off with the
|
|
2600 command @kbd{C-c C-a}:
|
|
2601
|
|
2602 @table @kbd
|
|
2603 @item C-c C-a
|
|
2604 @kindex C-c C-a @r{(C mode)}
|
|
2605 @findex c-toggle-auto-state
|
|
2606 Toggle the auto-newline feature (@code{c-toggle-auto-state}). With a
|
|
2607 prefix argument, this command turns the auto-newline feature on if the
|
|
2608 argument is positive, and off if it is negative.
|
|
2609 @end table
|
|
2610
|
|
2611 The colon character is electric because that is appropriate for a
|
|
2612 single colon. But when you want to insert a double colon in C++, the
|
|
2613 electric behavior of colon is inconvenient. You can insert a double
|
|
2614 colon with no reindentation or newlines by typing @kbd{C-c :}:
|
|
2615
|
|
2616 @table @kbd
|
|
2617 @item C-c :
|
|
2618 @kindex C-c : @r{(C mode)}
|
|
2619 @findex c-scope-operator
|
|
2620 Insert a double colon scope operator at point, without reindenting the
|
|
2621 line or adding any newlines (@code{c-scope-operator}).
|
|
2622 @end table
|
|
2623
|
|
2624 The electric @kbd{#} key reindents the line if it appears to be the
|
|
2625 beginning of a preprocessor directive. This happens when the value of
|
|
2626 @code{c-electric-pound-behavior} is @code{(alignleft)}. You can turn
|
|
2627 this feature off by setting @code{c-electric-pound-behavior} to
|
|
2628 @code{nil}.
|
|
2629
|
|
2630 The variable @code{c-hanging-braces-alist} controls the insertion of
|
|
2631 newlines before and after inserted braces. It is an association list
|
|
2632 with elements of the following form: @code{(@var{syntactic-symbol}
|
|
2633 . @var{nl-list})}. Most of the syntactic symbols that appear in
|
|
2634 @code{c-offsets-alist} are meaningful here as well.
|
|
2635
|
|
2636 The list @var{nl-list} may contain either of the symbols
|
|
2637 @code{before} or @code{after}, or both; or it may be @code{nil}. When a
|
|
2638 brace is inserted, the syntactic context it defines is looked up in
|
|
2639 @code{c-hanging-braces-alist}; if it is found, the @var{nl-list} is used
|
|
2640 to determine where newlines are inserted: either before the brace,
|
|
2641 after, or both. If not found, the default is to insert a newline both
|
|
2642 before and after braces.
|
|
2643
|
|
2644 The variable @code{c-hanging-colons-alist} controls the insertion of
|
|
2645 newlines before and after inserted colons. It is an association list
|
|
2646 with elements of the following form: @code{(@var{syntactic-symbol}
|
|
2647 . @var{nl-list})}. The list @var{nl-list} may contain either of the
|
|
2648 symbols @code{before} or @code{after}, or both; or it may be @code{nil}.
|
|
2649
|
|
2650 When a colon is inserted, the syntactic symbol it defines is looked
|
|
2651 up in this list, and if found, the @var{nl-list} is used to determine
|
|
2652 where newlines are inserted: either before the brace, after, or both.
|
|
2653 If the syntactic symbol is not found in this list, no newlines are
|
|
2654 inserted.
|
|
2655
|
|
2656 Electric characters can also delete newlines automatically when the
|
|
2657 auto-newline feature is enabled. This feature makes auto-newline more
|
|
2658 acceptable, by deleting the newlines in the most common cases where you
|
|
2659 do not want them. Emacs can recognize several cases in which deleting a
|
|
2660 newline might be desirable; by setting the variable
|
|
2661 @code{c-cleanup-list}, you can specify @emph{which} of these cases that
|
|
2662 should happen. The variable's value is a list of symbols, each
|
|
2663 describing one case for possible deletion of a newline. Here are the
|
|
2664 meaningful symbols, and their meanings:
|
|
2665
|
|
2666 @table @code
|
|
2667 @item brace-catch-brace
|
|
2668 Clean up @samp{@} catch (@var{condition}) @{} constructs by placing the
|
|
2669 entire construct on a single line. The clean-up occurs when you type
|
|
2670 the @samp{@{}, if there is nothing between the braces aside from
|
|
2671 @code{catch} and @var{condition}.
|
|
2672
|
|
2673 @item brace-else-brace
|
|
2674 Clean up @samp{@} else @{} constructs by placing the entire construct on
|
|
2675 a single line. The clean-up occurs when you type the @samp{@{} after
|
|
2676 the @code{else}, but only if there is nothing but white space between
|
|
2677 the braces and the @code{else}.
|
|
2678
|
|
2679 @item brace-elseif-brace
|
|
2680 Clean up @samp{@} else if (@dots{}) @{} constructs by placing the entire
|
|
2681 construct on a single line. The clean-up occurs when you type the
|
|
2682 @samp{@{}, if there is nothing but white space between the @samp{@}} and
|
|
2683 @samp{@{} aside from the keywords and the @code{if}-condition.
|
|
2684
|
|
2685 @item empty-defun-braces
|
|
2686 Clean up empty defun braces by placing the braces on the same
|
|
2687 line. Clean-up occurs when you type the closing brace.
|
|
2688
|
|
2689 @item defun-close-semi
|
|
2690 Clean up the semicolon after a @code{struct} or similar type
|
|
2691 declaration, by placing the semicolon on the same line as the closing
|
|
2692 brace. Clean-up occurs when you type the semicolon.
|
|
2693
|
|
2694 @item list-close-comma
|
|
2695 Clean up commas following braces in array and aggregate
|
|
2696 initializers. Clean-up occurs when you type the comma.
|
|
2697
|
|
2698 @item scope-operator
|
|
2699 Clean up double colons which may designate a C++ scope operator, by
|
|
2700 placing the colons together. Clean-up occurs when you type the second
|
|
2701 colon, but only when the two colons are separated by nothing but
|
|
2702 whitespace.
|
|
2703 @end table
|
|
2704
|
|
2705 @node Hungry Delete
|
|
2706 @subsection Hungry Delete Feature in C
|
|
2707
|
|
2708 When the @dfn{hungry-delete} feature is enabled (indicated by
|
|
2709 @samp{/h} or @samp{/ah} in the mode line after the mode name), a single
|
|
2710 @key{DEL} command deletes all preceding whitespace, not just one space.
|
|
2711 To turn this feature on or off, use @kbd{C-c C-d}:
|
|
2712
|
|
2713 @table @kbd
|
|
2714 @item C-c C-d
|
|
2715 @kindex C-c C-d @r{(C mode)}
|
|
2716 @findex c-toggle-hungry-state
|
|
2717 Toggle the hungry-delete feature (@code{c-toggle-hungry-state}). With a
|
|
2718 prefix argument, this command turns the hungry-delete feature on if the
|
|
2719 argument is positive, and off if it is negative.
|
|
2720
|
|
2721 @item C-c C-t
|
|
2722 @kindex C-c C-t @r{(C mode)}
|
|
2723 @findex c-toggle-auto-hungry-state
|
|
2724 Toggle the auto-newline and hungry-delete features, both at once
|
|
2725 (@code{c-toggle-auto-hungry-state}).
|
|
2726 @end table
|
|
2727
|
|
2728 @vindex c-hungry-delete-key
|
|
2729 The variable @code{c-hungry-delete-key} controls whether the
|
|
2730 hungry-delete feature is enabled.
|
|
2731
|
|
2732 @node Other C Commands
|
|
2733 @subsection Other Commands for C Mode
|
|
2734
|
|
2735 @table @kbd
|
|
2736 @item C-M-h
|
|
2737 @findex c-mark-function
|
|
2738 @kindex C-M-h @r{(C mode)}
|
|
2739 Put mark at the end of a function definition, and put point at the
|
|
2740 beginning (@code{c-mark-function}).
|
|
2741
|
|
2742 @item M-q
|
|
2743 @kindex M-q @r{(C mode)}
|
|
2744 @findex c-fill-paragraph
|
|
2745 Fill a paragraph, handling C and C++ comments (@code{c-fill-paragraph}).
|
|
2746 If any part of the current line is a comment or within a comment, this
|
|
2747 command fills the comment or the paragraph of it that point is in,
|
|
2748 preserving the comment indentation and comment delimiters.
|
|
2749
|
|
2750 @item C-c C-e
|
|
2751 @cindex macro expansion in C
|
|
2752 @cindex expansion of C macros
|
|
2753 @findex c-macro-expand
|
|
2754 @kindex C-c C-e @r{(C mode)}
|
|
2755 Run the C preprocessor on the text in the region, and show the result,
|
|
2756 which includes the expansion of all the macro calls
|
|
2757 (@code{c-macro-expand}). The buffer text before the region is also
|
|
2758 included in preprocessing, for the sake of macros defined there, but the
|
|
2759 output from this part isn't shown.
|
|
2760
|
|
2761 When you are debugging C code that uses macros, sometimes it is hard to
|
|
2762 figure out precisely how the macros expand. With this command, you
|
|
2763 don't have to figure it out; you can see the expansions.
|
|
2764
|
|
2765 @item C-c C-\
|
|
2766 @findex c-backslash-region
|
|
2767 @kindex C-c C-\ @r{(C mode)}
|
|
2768 Insert or align @samp{\} characters at the ends of the lines of the
|
|
2769 region (@code{c-backslash-region}). This is useful after writing or
|
|
2770 editing a C macro definition.
|
|
2771
|
|
2772 If a line already ends in @samp{\}, this command adjusts the amount of
|
|
2773 whitespace before it. Otherwise, it inserts a new @samp{\}. However,
|
|
2774 the last line in the region is treated specially; no @samp{\} is
|
|
2775 inserted on that line, and any @samp{\} there is deleted.
|
|
2776
|
|
2777 @item M-x cpp-highlight-buffer
|
|
2778 @cindex preprocessor highlighting
|
|
2779 @findex cpp-highlight-buffer
|
|
2780 Highlight parts of the text according to its preprocessor conditionals.
|
|
2781 This command displays another buffer named @samp{*CPP Edit*}, which
|
|
2782 serves as a graphic menu for selecting how to display particular kinds
|
|
2783 of conditionals and their contents. After changing various settings,
|
|
2784 click on @samp{[A]pply these settings} (or go to that buffer and type
|
|
2785 @kbd{a}) to rehighlight the C mode buffer accordingly.
|
|
2786
|
|
2787 @item C-c C-s
|
|
2788 @findex c-show-syntactic-information
|
|
2789 @kindex C-c C-s @r{(C mode)}
|
|
2790 Display the syntactic information about the current source line
|
|
2791 (@code{c-show-syntactic-information}). This is the information that
|
|
2792 directs how the line is indented.
|
|
2793 @end table
|
|
2794
|
|
2795 @node Comments in C
|
|
2796 @subsection Comments in C Modes
|
|
2797
|
|
2798 C mode and related modes use a number of variables for controlling
|
|
2799 comment format.
|
|
2800
|
|
2801 @table @code
|
|
2802 @item c-comment-only-line-offset
|
|
2803 @vindex c-comment-only-line-offset
|
|
2804 Extra offset for line which contains only the start of a comment. It
|
|
2805 can be either an integer or a cons cell of the form
|
|
2806 @code{(@var{non-anchored-offset} . @var{anchored-offset})}, where
|
|
2807 @var{non-anchored-offset} is the amount of offset given to
|
|
2808 non-column-zero anchored comment-only lines, and @var{anchored-offset}
|
|
2809 is the amount of offset to give column-zero anchored comment-only lines.
|
|
2810 Just an integer as value is equivalent to @code{(@var{val} . 0)}.
|
|
2811
|
|
2812 @item c-comment-start-regexp
|
|
2813 @vindex c-comment-start-regexp
|
|
2814 This buffer-local variable specifies how to recognize the start of a comment.
|
|
2815
|
|
2816 @item c-hanging-comment-ender-p
|
|
2817 @vindex c-hanging-comment-ender-p
|
|
2818 If this variable is @code{nil}, @code{c-fill-paragraph} leaves the
|
|
2819 comment terminator of a block comment on a line by itself. The default
|
|
2820 value is @code{t}, which puts the comment-end delimiter @samp{*/} at the
|
|
2821 end of the last line of the comment text.
|
|
2822
|
|
2823 @item c-hanging-comment-starter-p
|
|
2824 @vindex c-hanging-comment-starter-p
|
|
2825 If this variable is @code{nil}, @code{c-fill-paragraph} leaves the
|
|
2826 starting delimiter of a block comment on a line by itself. The default
|
|
2827 value is @code{t}, which puts the comment-start delimiter @samp{/*} at
|
|
2828 the beginning of the first line of the comment text.
|
|
2829 @end table
|
|
2830
|
|
2831 @node Fortran
|
|
2832 @section Fortran Mode
|
|
2833 @cindex Fortran mode
|
|
2834 @cindex mode, Fortran
|
|
2835
|
|
2836 Fortran mode provides special motion commands for Fortran statements and
|
|
2837 subprograms, and indentation commands that understand Fortran conventions
|
|
2838 of nesting, line numbers and continuation statements. Fortran mode has
|
|
2839 its own Auto Fill mode that breaks long lines into proper Fortran
|
|
2840 continuation lines.
|
|
2841
|
|
2842 Special commands for comments are provided because Fortran comments
|
|
2843 are unlike those of other languages. Built-in abbrevs optionally save
|
|
2844 typing when you insert Fortran keywords.
|
|
2845
|
|
2846 @findex fortran-mode
|
|
2847 Use @kbd{M-x fortran-mode} to switch to this major mode. This command
|
|
2848 runs the hook @code{fortran-mode-hook} (@pxref{Hooks}).
|
|
2849
|
|
2850 @menu
|
|
2851 * Motion: Fortran Motion. Moving point by statements or subprograms.
|
|
2852 * Indent: Fortran Indent. Indentation commands for Fortran.
|
|
2853 * Comments: Fortran Comments. Inserting and aligning comments.
|
|
2854 * Autofill: Fortran Autofill. Auto fill minor mode for Fortran.
|
|
2855 * Columns: Fortran Columns. Measuring columns for valid Fortran.
|
|
2856 * Abbrev: Fortran Abbrev. Built-in abbrevs for Fortran keywords.
|
|
2857 * Misc: Fortran Misc. Other Fortran mode features.
|
|
2858 @end menu
|
|
2859
|
|
2860 @node Fortran Motion
|
|
2861 @subsection Motion Commands
|
|
2862
|
|
2863 Fortran mode provides special commands to move by subprograms (functions
|
|
2864 and subroutines) and by statements. There is also a command to put the
|
|
2865 region around one subprogram, convenient for killing it or moving it.
|
|
2866
|
|
2867 @kindex C-M-a @r{(Fortran mode)}
|
|
2868 @kindex C-M-e @r{(Fortran mode)}
|
|
2869 @kindex C-M-h @r{(Fortran mode)}
|
|
2870 @kindex C-c C-p @r{(Fortran mode)}
|
|
2871 @kindex C-c C-n @r{(Fortran mode)}
|
|
2872 @findex beginning-of-fortran-subprogram
|
|
2873 @findex end-of-fortran-subprogram
|
|
2874 @findex mark-fortran-subprogram
|
|
2875 @findex fortran-previous-statement
|
|
2876 @findex fortran-next-statement
|
|
2877
|
|
2878 @table @kbd
|
|
2879 @item C-M-a
|
|
2880 Move to beginning of subprogram
|
|
2881 (@code{beginning-of-fortran-subprogram}).
|
|
2882 @item C-M-e
|
|
2883 Move to end of subprogram (@code{end-of-fortran-subprogram}).
|
|
2884 @item C-M-h
|
|
2885 Put point at beginning of subprogram and mark at end
|
|
2886 (@code{mark-fortran-subprogram}).
|
|
2887 @item C-c C-n
|
|
2888 Move to beginning of current or next statement
|
|
2889 (@code{fortran-next-statement}).
|
|
2890 @item C-c C-p
|
|
2891 Move to beginning of current or previous statement
|
|
2892 (@code{fortran-previous-statement}).
|
|
2893 @end table
|
|
2894
|
|
2895 @node Fortran Indent
|
|
2896 @subsection Fortran Indentation
|
|
2897
|
|
2898 Special commands and features are needed for indenting Fortran code in
|
|
2899 order to make sure various syntactic entities (line numbers, comment line
|
|
2900 indicators and continuation line flags) appear in the columns that are
|
|
2901 required for standard Fortran.
|
|
2902
|
|
2903 @menu
|
|
2904 * Commands: ForIndent Commands. Commands for indenting Fortran.
|
|
2905 * Contline: ForIndent Cont. How continuation lines indent.
|
|
2906 * Numbers: ForIndent Num. How line numbers auto-indent.
|
|
2907 * Conv: ForIndent Conv. Conventions you must obey to avoid trouble.
|
|
2908 * Vars: ForIndent Vars. Variables controlling Fortran indent style.
|
|
2909 @end menu
|
|
2910
|
|
2911 @node ForIndent Commands
|
|
2912 @subsubsection Fortran Indentation Commands
|
|
2913
|
|
2914 @table @kbd
|
|
2915 @item @key{TAB}
|
|
2916 Indent the current line (@code{fortran-indent-line}).
|
|
2917 @item C-j
|
|
2918 Indent the current and start a new indented line
|
|
2919 (@code{fortran-indent-new-line}).
|
|
2920 @item C-M-j
|
|
2921 Break the current line and set up a continuation line.
|
|
2922 @item M-^
|
|
2923 Join this line to the previous line.
|
|
2924 @item C-M-q
|
|
2925 Indent all the lines of the subprogram point is in
|
|
2926 (@code{fortran-indent-subprogram}).
|
|
2927 @end table
|
|
2928
|
|
2929 @findex fortran-indent-line
|
|
2930 Fortran mode redefines @key{TAB} to reindent the current line for
|
|
2931 Fortran (@code{fortran-indent-line}). This command indents line numbers
|
|
2932 and continuation markers to their required columns, and independently
|
|
2933 indents the body of the statement based on its nesting in the program.
|
|
2934
|
|
2935 @kindex C-j @r{(Fortran mode)}
|
|
2936 @findex fortran-indent-new-line
|
|
2937 The key @kbd{C-j} runs the command @code{fortran-indent-new-line},
|
|
2938 which reindents the current line then makes and indents a new line.
|
|
2939 This command is useful to reindent the closing statement of @samp{do}
|
|
2940 loops and other blocks before starting a new line.
|
|
2941
|
|
2942 @kindex C-M-q @r{(Fortran mode)}
|
|
2943 @findex fortran-indent-subprogram
|
|
2944 The key @kbd{C-M-q} runs @code{fortran-indent-subprogram}, a command
|
|
2945 to reindent all the lines of the Fortran subprogram (function or
|
|
2946 subroutine) containing point.
|
|
2947
|
|
2948 @kindex C-M-j @r{(Fortran mode)}
|
|
2949 @findex fortran-split-line
|
|
2950 The key @kbd{C-M-j} runs @code{fortran-split-line}, which splits
|
|
2951 a line in the appropriate fashion for Fortran. In a non-comment line,
|
|
2952 the second half becomes a continuation line and is indented
|
|
2953 accordingly. In a comment line, both halves become separate comment
|
|
2954 lines.
|
|
2955
|
|
2956 @kindex M-^ @r{(Fortran mode)}
|
|
2957 @findex fortran-join-line
|
|
2958 @kbd{M-^} runs the command @code{fortran-join-line}, which is more or
|
|
2959 less the inverse of @code{fortran-split-line}. It joins the current
|
|
2960 line to the previous line in a suitable way for Fortran code.
|
|
2961
|
|
2962 @node ForIndent Cont
|
|
2963 @subsubsection Continuation Lines
|
|
2964 @cindex Fortran continuation lines
|
|
2965
|
|
2966 @vindex fortran-continuation-string
|
|
2967 Most modern Fortran compilers allow two ways of writing continuation
|
|
2968 lines. If the first non-space character on a line is in column 5, then
|
|
2969 that line is a continuation of the previous line. We call this
|
|
2970 @dfn{fixed format}. (In GNU Emacs we always count columns from 0.) The
|
|
2971 variable @code{fortran-continuation-string} specifies what character to
|
|
2972 put on column 5. A line that starts with a tab character followed by
|
|
2973 any digit except @samp{0} is also a continuation line. We call this
|
|
2974 style of continuation @dfn{tab format}.
|
|
2975
|
|
2976 @vindex indent-tabs-mode @r{(Fortran mode)}
|
|
2977 Fortran mode can make either style of continuation line, but you
|
|
2978 must specify which one you prefer. The value of the variable
|
|
2979 @code{indent-tabs-mode} controls the choice: @code{nil} for fixed
|
|
2980 format, and non-@code{nil} for tab format. You can tell which style
|
|
2981 is presently in effect by the presence or absence of the string
|
|
2982 @samp{Tab} in the mode line.
|
|
2983
|
|
2984 If the text on a line starts with the conventional Fortran
|
|
2985 continuation marker @samp{$}, or if it begins with any non-whitespace
|
|
2986 character in column 5, Fortran mode treats it as a continuation line.
|
|
2987 When you indent a continuation line with @key{TAB}, it converts the line
|
|
2988 to the current continuation style. When you split a Fortran statement
|
|
2989 with @kbd{C-M-j}, the continuation marker on the newline is created
|
|
2990 according to the continuation style.
|
|
2991
|
|
2992 The setting of continuation style affects several other aspects of
|
|
2993 editing in Fortran mode. In fixed format mode, the minimum column
|
|
2994 number for the body of a statement is 6. Lines inside of Fortran
|
|
2995 blocks that are indented to larger column numbers always use only the
|
|
2996 space character for whitespace. In tab format mode, the minimum
|
|
2997 column number for the statement body is 8, and the whitespace before
|
|
2998 column 8 must always consist of one tab character.
|
|
2999
|
|
3000 @vindex fortran-tab-mode-default
|
|
3001 @vindex fortran-analyze-depth
|
|
3002 When you enter Fortran mode for an existing file, it tries to deduce the
|
|
3003 proper continuation style automatically from the file contents. The first
|
|
3004 line that begins with either a tab character or six spaces determines the
|
|
3005 choice. The variable @code{fortran-analyze-depth} specifies how many lines
|
|
3006 to consider (at the beginning of the file); if none of those lines
|
|
3007 indicates a style, then the variable @code{fortran-tab-mode-default}
|
|
3008 specifies the style. If it is @code{nil}, that specifies fixed format, and
|
|
3009 non-@code{nil} specifies tab format.
|
|
3010
|
|
3011 @node ForIndent Num
|
|
3012 @subsubsection Line Numbers
|
|
3013
|
|
3014 If a number is the first non-whitespace in the line, Fortran
|
|
3015 indentation assumes it is a line number and moves it to columns 0
|
|
3016 through 4. (Columns always count from 0 in GNU Emacs.)
|
|
3017
|
|
3018 @vindex fortran-line-number-indent
|
|
3019 Line numbers of four digits or less are normally indented one space.
|
|
3020 The variable @code{fortran-line-number-indent} controls this; it
|
|
3021 specifies the maximum indentation a line number can have. Line numbers
|
|
3022 are indented to right-justify them to end in column 4 unless that would
|
|
3023 require more than this maximum indentation. The default value of the
|
|
3024 variable is 1.
|
|
3025
|
|
3026 @vindex fortran-electric-line-number
|
|
3027 Simply inserting a line number is enough to indent it according to
|
|
3028 these rules. As each digit is inserted, the indentation is recomputed.
|
|
3029 To turn off this feature, set the variable
|
|
3030 @code{fortran-electric-line-number} to @code{nil}. Then inserting line
|
|
3031 numbers is like inserting anything else.
|
|
3032
|
|
3033 @node ForIndent Conv
|
|
3034 @subsubsection Syntactic Conventions
|
|
3035
|
|
3036 Fortran mode assumes that you follow certain conventions that simplify
|
|
3037 the task of understanding a Fortran program well enough to indent it
|
|
3038 properly:
|
|
3039
|
|
3040 @itemize @bullet
|
|
3041 @item
|
|
3042 Two nested @samp{do} loops never share a @samp{continue} statement.
|
|
3043
|
|
3044 @item
|
|
3045 Fortran keywords such as @samp{if}, @samp{else}, @samp{then}, @samp{do}
|
|
3046 and others are written without embedded whitespace or line breaks.
|
|
3047
|
|
3048 Fortran compilers generally ignore whitespace outside of string
|
|
3049 constants, but Fortran mode does not recognize these keywords if they
|
|
3050 are not contiguous. Constructs such as @samp{else if} or @samp{end do}
|
|
3051 are acceptable, but the second word should be on the same line as the
|
|
3052 first and not on a continuation line.
|
|
3053 @end itemize
|
|
3054
|
|
3055 @noindent
|
|
3056 If you fail to follow these conventions, the indentation commands may
|
|
3057 indent some lines unaesthetically. However, a correct Fortran program
|
|
3058 retains its meaning when reindented even if the conventions are not
|
|
3059 followed.
|
|
3060
|
|
3061 @node ForIndent Vars
|
|
3062 @subsubsection Variables for Fortran Indentation
|
|
3063
|
|
3064 @vindex fortran-do-indent
|
|
3065 @vindex fortran-if-indent
|
|
3066 @vindex fortran-structure-indent
|
|
3067 @vindex fortran-continuation-indent
|
|
3068 @vindex fortran-check-all-num@dots{}
|
|
3069 @vindex fortran-minimum-statement-indent@dots{}
|
|
3070 Several additional variables control how Fortran indentation works:
|
|
3071
|
|
3072 @table @code
|
|
3073 @item fortran-do-indent
|
|
3074 Extra indentation within each level of @samp{do} statement (default 3).
|
|
3075
|
|
3076 @item fortran-if-indent
|
|
3077 Extra indentation within each level of @samp{if} statement (default 3).
|
|
3078 This value is also used for extra indentation within each level of the
|
|
3079 Fortran 90 @samp{where} statement.
|
|
3080
|
|
3081 @item fortran-structure-indent
|
|
3082 Extra indentation within each level of @samp{structure}, @samp{union}, or
|
|
3083 @samp{map} statements (default 3).
|
|
3084
|
|
3085 @item fortran-continuation-indent
|
|
3086 Extra indentation for bodies of continuation lines (default 5).
|
|
3087
|
|
3088 @item fortran-check-all-num-for-matching-do
|
|
3089 If this is @code{nil}, indentation assumes that each @samp{do} statement
|
|
3090 ends on a @samp{continue} statement. Therefore, when computing
|
|
3091 indentation for a statement other than @samp{continue}, it can save time
|
|
3092 by not checking for a @samp{do} statement ending there. If this is
|
|
3093 non-@code{nil}, indenting any numbered statement must check for a
|
|
3094 @samp{do} that ends there. The default is @code{nil}.
|
|
3095
|
|
3096 @item fortran-blink-matching-if
|
|
3097 If this is @code{t}, indenting an @samp{endif} statement moves the
|
|
3098 cursor momentarily to the matching @samp{if} statement to show where it
|
|
3099 is. The default is @code{nil}.
|
|
3100
|
|
3101 @item fortran-minimum-statement-indent-fixed
|
|
3102 Minimum indentation for fortran statements when using fixed format
|
|
3103 continuation line style. Statement bodies are never indented less than
|
|
3104 this much. The default is 6.
|
|
3105
|
|
3106 @item fortran-minimum-statement-indent-tab
|
|
3107 Minimum indentation for fortran statements for tab format continuation line
|
|
3108 style. Statement bodies are never indented less than this much. The
|
|
3109 default is 8.
|
|
3110 @end table
|
|
3111
|
|
3112 @node Fortran Comments
|
|
3113 @subsection Fortran Comments
|
|
3114
|
|
3115 The usual Emacs comment commands assume that a comment can follow a line
|
|
3116 of code. In Fortran, the standard comment syntax requires an entire line
|
|
3117 to be just a comment. Therefore, Fortran mode replaces the standard Emacs
|
|
3118 comment commands and defines some new variables.
|
|
3119
|
|
3120 Fortran mode can also handle a nonstandard comment syntax where comments
|
|
3121 start with @samp{!} and can follow other text. Because only some Fortran
|
|
3122 compilers accept this syntax, Fortran mode will not insert such comments
|
|
3123 unless you have said in advance to do so. To do this, set the variable
|
|
3124 @code{comment-start} to @samp{"!"} (@pxref{Variables}).
|
|
3125
|
|
3126 @table @kbd
|
|
3127 @item M-;
|
|
3128 Align comment or insert new comment (@code{fortran-comment-indent}).
|
|
3129
|
|
3130 @item C-x ;
|
|
3131 Applies to nonstandard @samp{!} comments only.
|
|
3132
|
|
3133 @item C-c ;
|
|
3134 Turn all lines of the region into comments, or (with argument) turn them back
|
|
3135 into real code (@code{fortran-comment-region}).
|
|
3136 @end table
|
|
3137
|
|
3138 @kbd{M-;} in Fortran mode is redefined as the command
|
|
3139 @code{fortran-comment-indent}. Like the usual @kbd{M-;} command, this
|
|
3140 recognizes any kind of existing comment and aligns its text appropriately;
|
|
3141 if there is no existing comment, a comment is inserted and aligned. But
|
|
3142 inserting and aligning comments are not the same in Fortran mode as in
|
|
3143 other modes.
|
|
3144
|
|
3145 When a new comment must be inserted, if the current line is blank, a
|
|
3146 full-line comment is inserted. On a non-blank line, a nonstandard @samp{!}
|
|
3147 comment is inserted if you have said you want to use them. Otherwise a
|
|
3148 full-line comment is inserted on a new line before the current line.
|
|
3149
|
|
3150 Nonstandard @samp{!} comments are aligned like comments in other
|
|
3151 languages, but full-line comments are different. In a standard full-line
|
|
3152 comment, the comment delimiter itself must always appear in column zero.
|
|
3153 What can be aligned is the text within the comment. You can choose from
|
|
3154 three styles of alignment by setting the variable
|
|
3155 @code{fortran-comment-indent-style} to one of these values:
|
|
3156
|
|
3157 @vindex fortran-comment-indent-style
|
|
3158 @vindex fortran-comment-line-extra-indent
|
|
3159 @table @code
|
|
3160 @item fixed
|
|
3161 Align the text at a fixed column, which is the sum of
|
|
3162 @code{fortran-comment-line-extra-indent} and the minimum statement
|
|
3163 indentation. This is the default.
|
|
3164
|
|
3165 The minimum statement indentation is
|
|
3166 @code{fortran-minimum-statement-indent-fixed} for fixed format
|
|
3167 continuation line style and @code{fortran-minimum-statement-indent-tab}
|
|
3168 for tab format style.
|
|
3169
|
|
3170 @item relative
|
|
3171 Align the text as if it were a line of code, but with an additional
|
|
3172 @code{fortran-comment-line-extra-indent} columns of indentation.
|
|
3173
|
|
3174 @item nil
|
|
3175 Don't move text in full-line comments automatically at all.
|
|
3176 @end table
|
|
3177
|
|
3178 @vindex fortran-comment-indent-char
|
|
3179 In addition, you can specify the character to be used to indent within
|
|
3180 full-line comments by setting the variable
|
|
3181 @code{fortran-comment-indent-char} to the single-character string you want
|
|
3182 to use.
|
|
3183
|
|
3184 @vindex comment-line-start
|
|
3185 @vindex comment-line-start-skip
|
|
3186 Fortran mode introduces two variables @code{comment-line-start} and
|
|
3187 @code{comment-line-start-skip}, which play for full-line comments the same
|
|
3188 roles played by @code{comment-start} and @code{comment-start-skip} for
|
|
3189 ordinary text-following comments. Normally these are set properly by
|
|
3190 Fortran mode, so you do not need to change them.
|
|
3191
|
|
3192 The normal Emacs comment command @kbd{C-x ;} has not been redefined. If
|
|
3193 you use @samp{!} comments, this command can be used with them. Otherwise
|
|
3194 it is useless in Fortran mode.
|
|
3195
|
|
3196 @kindex C-c ; @r{(Fortran mode)}
|
|
3197 @findex fortran-comment-region
|
|
3198 @vindex fortran-comment-region
|
|
3199 The command @kbd{C-c ;} (@code{fortran-comment-region}) turns all the
|
|
3200 lines of the region into comments by inserting the string @samp{C$$$} at
|
|
3201 the front of each one. With a numeric argument, it turns the region
|
|
3202 back into live code by deleting @samp{C$$$} from the front of each line
|
|
3203 in it. The string used for these comments can be controlled by setting
|
|
3204 the variable @code{fortran-comment-region}. Note that here we have an
|
|
3205 example of a command and a variable with the same name; these two uses
|
|
3206 of the name never conflict because in Lisp and in Emacs it is always
|
|
3207 clear from the context which one is meant.
|
|
3208
|
|
3209 @node Fortran Autofill
|
|
3210 @subsection Fortran Auto Fill Mode
|
|
3211
|
|
3212 Fortran Auto Fill mode is a minor mode which automatically splits
|
|
3213 Fortran statements as you insert them when they become too wide.
|
|
3214 Splitting a statement involves making continuation lines using
|
|
3215 @code{fortran-continuation-string} (@pxref{ForIndent Cont}). This
|
|
3216 splitting happens when you type @key{SPC}, @key{RET}, or @key{TAB}, and
|
|
3217 also in the Fortran indentation commands.
|
|
3218
|
|
3219 @findex fortran-auto-fill-mode
|
|
3220 @kbd{M-x fortran-auto-fill-mode} turns Fortran Auto Fill mode on if it
|
|
3221 was off, or off if it was on. This command works the same as @kbd{M-x
|
|
3222 auto-fill-mode} does for normal Auto Fill mode (@pxref{Filling}). A
|
|
3223 positive numeric argument turns Fortran Auto Fill mode on, and a
|
|
3224 negative argument turns it off. You can see when Fortran Auto Fill mode
|
|
3225 is in effect by the presence of the word @samp{Fill} in the mode line,
|
|
3226 inside the parentheses. Fortran Auto Fill mode is a minor mode, turned
|
|
3227 on or off for each buffer individually. @xref{Minor Modes}.
|
|
3228
|
|
3229 @vindex fortran-break-before-delimiters
|
|
3230 Fortran Auto Fill mode breaks lines at spaces or delimiters when the
|
|
3231 lines get longer than the desired width (the value of @code{fill-column}).
|
|
3232 The delimiters that Fortran Auto Fill mode may break at are @samp{,},
|
|
3233 @samp{'}, @samp{+}, @samp{-}, @samp{/}, @samp{*}, @samp{=}, and @samp{)}.
|
|
3234 The line break comes after the delimiter if the variable
|
|
3235 @code{fortran-break-before-delimiters} is @code{nil}. Otherwise (and by
|
|
3236 default), the break comes before the delimiter.
|
|
3237
|
|
3238 By default, Fortran Auto Fill mode is not enabled. If you want this
|
|
3239 feature turned on permanently, add a hook function to
|
|
3240 @code{fortran-mode-hook} to execute @code{(fortran-auto-fill-mode 1)}.
|
|
3241 @xref{Hooks}.
|
|
3242
|
|
3243 @node Fortran Columns
|
|
3244 @subsection Checking Columns in Fortran
|
|
3245
|
|
3246 @table @kbd
|
|
3247 @item C-c C-r
|
|
3248 Display a ``column ruler'' momentarily above the current line
|
|
3249 (@code{fortran-column-ruler}).
|
|
3250 @item C-c C-w
|
|
3251 Split the current window horizontally temporarily so that it is 72
|
|
3252 columns wide. This may help you avoid making lines longer than the
|
|
3253 72-character limit that some Fortran compilers impose
|
|
3254 (@code{fortran-window-create-momentarily}).
|
|
3255 @end table
|
|
3256
|
|
3257 @kindex C-c C-r @r{(Fortran mode)}
|
|
3258 @findex fortran-column-ruler
|
|
3259 @vindex fortran-column-ruler
|
|
3260 The command @kbd{C-c C-r} (@code{fortran-column-ruler}) shows a column
|
|
3261 ruler momentarily above the current line. The comment ruler is two lines
|
|
3262 of text that show you the locations of columns with special significance in
|
|
3263 Fortran programs. Square brackets show the limits of the columns for line
|
|
3264 numbers, and curly brackets show the limits of the columns for the
|
|
3265 statement body. Column numbers appear above them.
|
|
3266
|
|
3267 Note that the column numbers count from zero, as always in GNU Emacs.
|
|
3268 As a result, the numbers may be one less than those you are familiar
|
|
3269 with; but the positions they indicate in the line are standard for
|
|
3270 Fortran.
|
|
3271
|
|
3272 The text used to display the column ruler depends on the value of
|
|
3273 the variable @code{indent-tabs-mode}. If @code{indent-tabs-mode} is
|
|
3274 @code{nil}, then the value of the variable
|
|
3275 @code{fortran-column-ruler-fixed} is used as the column ruler.
|
|
3276 Otherwise, the variable @code{fortran-column-ruler-tab} is displayed.
|
|
3277 By changing these variables, you can change the column ruler display.
|
|
3278
|
|
3279 @kindex C-c C-w @r{(Fortran mode)}
|
|
3280 @findex fortran-window-create
|
|
3281 For even more help, use @kbd{C-c C-w} (@code{fortran-window-create}), a
|
|
3282 command which splits the current window horizontally, making a window 72
|
|
3283 columns wide. By editing in this window you can immediately see when you
|
|
3284 make a line too wide to be correct Fortran.
|
|
3285
|
|
3286 @node Fortran Abbrev
|
|
3287 @subsection Fortran Keyword Abbrevs
|
|
3288
|
|
3289 Fortran mode provides many built-in abbrevs for common keywords and
|
|
3290 declarations. These are the same sort of abbrev that you can define
|
|
3291 yourself. To use them, you must turn on Abbrev mode. @xref{Abbrevs}.
|
|
3292
|
|
3293 The built-in abbrevs are unusual in one way: they all start with a
|
|
3294 semicolon. You cannot normally use semicolon in an abbrev, but Fortran
|
|
3295 mode makes this possible by changing the syntax of semicolon to ``word
|
|
3296 constituent.''
|
|
3297
|
|
3298 For example, one built-in Fortran abbrev is @samp{;c} for
|
|
3299 @samp{continue}. If you insert @samp{;c} and then insert a punctuation
|
|
3300 character such as a space or a newline, the @samp{;c} expands automatically
|
|
3301 to @samp{continue}, provided Abbrev mode is enabled.@refill
|
|
3302
|
|
3303 Type @samp{;?} or @samp{;C-h} to display a list of all the built-in
|
|
3304 Fortran abbrevs and what they stand for.
|
|
3305
|
|
3306 @node Fortran Misc
|
|
3307 @subsection Other Fortran Mode Commands
|
|
3308
|
|
3309 @table @kbd
|
|
3310 @item C-x n d
|
|
3311 Narrow to the current Fortran subprogram.
|
|
3312 @end table
|
|
3313
|
|
3314 @kindex C-x n d @r{(Fortran mode)}
|
|
3315 @findex fortran-narrow-to-subprogram
|
|
3316 Fortran mode redefines the key @kbd{C-x n d} to run the command
|
|
3317 @code{fortran-narrow-to-subprogram}, which is the Fortran analogue
|
|
3318 of the key's usual definition. It narrows the buffer to the subprogram
|
|
3319 containing point.
|
|
3320
|
|
3321 @node Asm Mode
|
|
3322 @section Asm Mode
|
|
3323
|
|
3324 @cindex Asm mode
|
|
3325 Asm mode is a major mode for editing files of assembler code. It
|
|
3326 defines these commands:
|
|
3327
|
|
3328 @table @kbd
|
|
3329 @item @key{TAB}
|
|
3330 @code{tab-to-tab-stop}.
|
|
3331 @item C-j
|
|
3332 Insert a newline and then indent using @code{tab-to-tab-stop}.
|
|
3333 @item :
|
|
3334 Insert a colon and then remove the indentation from before the label
|
|
3335 preceding colon. Then do @code{tab-to-tab-stop}.
|
|
3336 @item ;
|
|
3337 Insert or align a comment.
|
|
3338 @end table
|
|
3339
|
|
3340 The variable @code{asm-comment-char} specifies which character
|
|
3341 starts comments in assembler syntax.
|