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