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