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