Commit | Line | Data |
---|---|---|
f00366c2 RS |
1 | @c This is part of the Emacs manual. |
2 | @c Copyright (C) 1985,86,87,93,94,95,97,99,00,2001 Free Software Foundation, Inc. | |
3 | @c See file emacs.texi for copying conditions. | |
4 | @node Maintaining, Abbrevs, Building, Top | |
5 | @chapter Maintaining Programs | |
6 | @cindex Lisp editing | |
7 | @cindex C editing | |
8 | @cindex program editing | |
9 | ||
10 | This chapter describes Emacs features for maintaining programs. The | |
d7ed11cd RS |
11 | version control features (@pxref{Version Control}) are also |
12 | particularly useful for this purpose. | |
f00366c2 RS |
13 | |
14 | @menu | |
15 | * Change Log:: Maintaining a change history for your program. | |
f00366c2 RS |
16 | * Tags:: Go direct to any function in your program in one |
17 | command. Tags remembers which file it is in. | |
18 | * Emerge:: A convenient way of merging two versions of a program. | |
19 | @end menu | |
20 | ||
21 | @node Change Log | |
22 | @section Change Logs | |
23 | ||
24 | @cindex change log | |
25 | @kindex C-x 4 a | |
26 | @findex add-change-log-entry-other-window | |
27 | The Emacs command @kbd{C-x 4 a} adds a new entry to the change log | |
28 | file for the file you are editing | |
29 | (@code{add-change-log-entry-other-window}). If that file is actually | |
30 | a backup file, it makes an entry appropriate for the file's | |
31 | parent---that is useful for making log entries for functions that | |
32 | have been deleted in the current version. | |
33 | ||
34 | A change log file contains a chronological record of when and why you | |
35 | have changed a program, consisting of a sequence of entries describing | |
36 | individual changes. Normally it is kept in a file called | |
37 | @file{ChangeLog} in the same directory as the file you are editing, or | |
38 | one of its parent directories. A single @file{ChangeLog} file can | |
39 | record changes for all the files in its directory and all its | |
40 | subdirectories. | |
41 | ||
1e4cb307 RS |
42 | You should put a copyright notice and permission notice at the |
43 | end of the change log file. Here is an example: | |
44 | ||
45 | @example | |
46 | Copyright 1997, 1998 Free Software Foundation, Inc. | |
47 | Copying and distribution of this file, with or without modification, are | |
48 | permitted provided the copyright notice and this notice are preserved. | |
49 | @end example | |
50 | ||
51 | @noindent | |
52 | Of course, you should substitute the proper years and copyright holder. | |
53 | ||
f00366c2 RS |
54 | A change log entry starts with a header line that contains the |
55 | current date, your name, and your email address (taken from the | |
56 | variable @code{user-mail-address}). Aside from these header lines, | |
57 | every line in the change log starts with a space or a tab. The bulk | |
58 | of the entry consists of @dfn{items}, each of which starts with a line | |
59 | starting with whitespace and a star. Here are two entries, both dated | |
60 | in May 1993, each with two items: | |
61 | ||
62 | @iftex | |
63 | @medbreak | |
64 | @end iftex | |
65 | @smallexample | |
66 | 1993-05-25 Richard Stallman <rms@@gnu.org> | |
67 | ||
68 | * man.el: Rename symbols `man-*' to `Man-*'. | |
69 | (manual-entry): Make prompt string clearer. | |
70 | ||
71 | * simple.el (blink-matching-paren-distance): | |
72 | Change default to 12,000. | |
73 | ||
74 | 1993-05-24 Richard Stallman <rms@@gnu.org> | |
75 | ||
76 | * vc.el (minor-mode-map-alist): Don't use it if it's void. | |
77 | (vc-cancel-version): Doc fix. | |
78 | @end smallexample | |
79 | ||
80 | One entry can describe several changes; each change should have its | |
81 | own item. Normally there should be a blank line between items. When | |
82 | items are related (parts of the same change, in different places), group | |
83 | them by leaving no blank line between them. The second entry above | |
84 | contains two items grouped in this way. | |
85 | ||
86 | @kbd{C-x 4 a} visits the change log file and creates a new entry | |
87 | unless the most recent entry is for today's date and your name. It | |
88 | also creates a new item for the current file. For many languages, it | |
89 | can even guess the name of the function or other object that was | |
90 | changed. | |
91 | ||
92 | @vindex add-log-keep-changes-together | |
93 | When the option @code{add-log-keep-changes-together} is | |
94 | non-@code{nil}, @kbd{C-x 4 a} adds to any existing entry for the file | |
95 | rather than starting a new entry. | |
96 | ||
97 | @vindex change-log-version-info-enabled | |
98 | @vindex change-log-version-number-regexp-list | |
99 | @cindex file version in change log entries | |
100 | If the value of the variable @code{change-log-version-info-enabled} | |
101 | is non-@code{nil}, @kbd{C-x 4 a} adds the file's version number to the | |
102 | change log entry. It finds the version number by searching the first | |
103 | ten percent of the file, using regular expressions from the variable | |
104 | @code{change-log-version-number-regexp-list}. | |
105 | ||
106 | @cindex Change Log mode | |
107 | @findex change-log-mode | |
108 | The change log file is visited in Change Log mode. In this major | |
109 | mode, each bunch of grouped items counts as one paragraph, and each | |
110 | entry is considered a page. This facilitates editing the entries. | |
111 | @kbd{C-j} and auto-fill indent each new line like the previous line; | |
112 | this is convenient for entering the contents of an entry. | |
113 | ||
114 | @findex change-log-merge | |
115 | You can use the command @kbd{M-x change-log-merge} to merge other | |
116 | log files into a buffer in Change Log Mode, preserving the date | |
117 | ordering of entries. | |
118 | ||
119 | @findex change-log-redate | |
120 | @cindex converting change log date style | |
121 | Versions of Emacs before 20.1 used a different format for the time of | |
122 | the change log entry: | |
123 | ||
124 | @smallexample | |
125 | Fri May 25 11:23:23 1993 Richard Stallman <rms@@gnu.org> | |
126 | @end smallexample | |
127 | ||
128 | @noindent | |
129 | The @kbd{M-x change-log-redate} command converts all the old-style | |
130 | date entries in the change log file visited in the current buffer to | |
131 | the new format, to make the file uniform in style. This is handy when | |
132 | entries are contributed by many different people, some of whom use old | |
133 | versions of Emacs. | |
134 | ||
135 | Version control systems are another way to keep track of changes in your | |
136 | program and keep a change log. @xref{Log Buffer}. | |
137 | ||
e4059eed RS |
138 | @ignore |
139 | @c This is commented out because the command is specific | |
140 | @c to maintenance of Emacs itself. | |
141 | ||
f00366c2 RS |
142 | @node Authors |
143 | @section @file{AUTHORS} files | |
144 | @cindex @file{AUTHORS} file | |
145 | ||
146 | Programs which have many contributors usually include a file named | |
147 | @file{AUTHORS} in their distribution, which lists the individual | |
148 | contributions. Emacs has a special command for maintaining the | |
149 | @file{AUTHORS} file that is part of the Emacs distribution. | |
150 | ||
151 | @findex authors | |
152 | The @kbd{M-x authors} command prompts for the name of the root of the | |
9cd6acef | 153 | Emacs source directory. It then scans @file{ChangeLog} files and Lisp |
f00366c2 | 154 | source files under that directory for information about authors of |
d7ed11cd | 155 | individual packages, and people who made changes in source files, and |
f00366c2 RS |
156 | puts the information it gleans into a buffer named @samp{*Authors*}. |
157 | You can then edit the contents of that buffer and merge it with the | |
24cc235a | 158 | existing @file{AUTHORS} file. |
f00366c2 RS |
159 | |
160 | Do not assume that this command finds all the contributors; don't | |
161 | assume that a person not listed in the output was not a contributor. | |
162 | If you merged in someone's contribution and did not put his name | |
163 | in the change log, he won't show up in @kbd{M-x authors} either. | |
e4059eed | 164 | @end ignore |
f00366c2 RS |
165 | |
166 | @node Tags | |
167 | @section Tags Tables | |
168 | @cindex tags table | |
169 | ||
170 | A @dfn{tags table} is a description of how a multi-file program is | |
171 | broken up into files. It lists the names of the component files and the | |
172 | names and positions of the functions (or other named subunits) in each | |
173 | file. Grouping the related files makes it possible to search or replace | |
174 | through all the files with one command. Recording the function names | |
175 | and positions makes possible the @kbd{M-.} command which finds the | |
176 | definition of a function by looking up which of the files it is in. | |
177 | ||
178 | Tags tables are stored in files called @dfn{tags table files}. The | |
179 | conventional name for a tags table file is @file{TAGS}. | |
180 | ||
181 | Each entry in the tags table records the name of one tag, the name of the | |
bf8dd4e3 FP |
182 | file that the tag is defined in (implicitly), and the position in that |
183 | file of the tag's definition. When a file parsed by @code{etags} is | |
0f5401a8 FP |
184 | generated from a different source file, like a C file generated from a |
185 | Cweb source file, the tags of the parsed file reference the source | |
186 | file. | |
f00366c2 RS |
187 | |
188 | Just what names from the described files are recorded in the tags table | |
189 | depends on the programming language of the described file. They | |
190 | normally include all file names, functions and subroutines, and may | |
191 | also include global variables, data types, and anything else | |
192 | convenient. Each name recorded is called a @dfn{tag}. | |
193 | ||
194 | @cindex C++ class browser, tags | |
195 | @cindex tags, C++ | |
196 | @cindex class browser, C++ | |
197 | @cindex Ebrowse | |
198 | See also the Ebrowse facility, which is tailored for C++. | |
199 | @xref{Top,, Ebrowse, ebrowse, Ebrowse User's Manual}. | |
200 | ||
201 | @menu | |
202 | * Tag Syntax:: Tag syntax for various types of code and text files. | |
203 | * Create Tags Table:: Creating a tags table with @code{etags}. | |
204 | * Etags Regexps:: Create arbitrary tags using regular expressions. | |
205 | * Select Tags Table:: How to visit a tags table. | |
206 | * Find Tag:: Commands to find the definition of a specific tag. | |
207 | * Tags Search:: Using a tags table for searching and replacing. | |
208 | * List Tags:: Listing and finding tags defined in a file. | |
209 | @end menu | |
210 | ||
211 | @node Tag Syntax | |
212 | @subsection Source File Tag Syntax | |
213 | ||
214 | Here is how tag syntax is defined for the most popular languages: | |
215 | ||
216 | @itemize @bullet | |
217 | @item | |
218 | In C code, any C function or typedef is a tag, and so are definitions of | |
219 | @code{struct}, @code{union} and @code{enum}. | |
220 | @code{#define} macro definitions and @code{enum} constants are also | |
221 | tags, unless you specify @samp{--no-defines} when making the tags table. | |
222 | Similarly, global variables are tags, unless you specify | |
223 | @samp{--no-globals}. Use of @samp{--no-globals} and @samp{--no-defines} | |
224 | can make the tags table file much smaller. | |
225 | ||
226 | You can tag function declarations and external variables in addition | |
227 | to function definitions by giving the @samp{--declarations} option to | |
228 | @code{etags}. | |
229 | ||
230 | @item | |
231 | In C++ code, in addition to all the tag constructs of C code, member | |
232 | functions are also recognized, and optionally member variables if you | |
233 | use the @samp{--members} option. Tags for variables and functions in | |
234 | classes are named @samp{@var{class}::@var{variable}} and | |
235 | @samp{@var{class}::@var{function}}. @code{operator} definitions have | |
236 | tag names like @samp{operator+}. | |
237 | ||
238 | @item | |
239 | In Java code, tags include all the constructs recognized in C++, plus | |
240 | the @code{interface}, @code{extends} and @code{implements} constructs. | |
241 | Tags for variables and functions in classes are named | |
242 | @samp{@var{class}.@var{variable}} and @samp{@var{class}.@var{function}}. | |
243 | ||
244 | @item | |
245 | In La@TeX{} text, the argument of any of the commands @code{\chapter}, | |
246 | @code{\section}, @code{\subsection}, @code{\subsubsection}, | |
e4a1e8d9 FP |
247 | @code{\eqno}, @code{\label}, @code{\ref}, @code{\cite}, |
248 | @code{\bibitem}, @code{\part}, @code{\appendix}, @code{\entry}, | |
249 | @code{\index}, @code{\def}, @code{\newcomand}, @code{\renewcommand}, | |
250 | @code{\newenvironment} or @code{\renewenvironment} is a tag.@refill | |
f00366c2 RS |
251 | |
252 | Other commands can make tags as well, if you specify them in the | |
253 | environment variable @env{TEXTAGS} before invoking @code{etags}. The | |
254 | value of this environment variable should be a colon-separated list of | |
255 | command names. For example, | |
256 | ||
257 | @example | |
e4a1e8d9 | 258 | TEXTAGS="mycommand:myothercommand" |
f00366c2 RS |
259 | export TEXTAGS |
260 | @end example | |
261 | ||
262 | @noindent | |
e4a1e8d9 FP |
263 | specifies (using Bourne shell syntax) that the commands |
264 | @samp{\mycommand} and @samp{\myothercommand} also define tags. | |
f00366c2 RS |
265 | |
266 | @item | |
267 | In Lisp code, any function defined with @code{defun}, any variable | |
268 | defined with @code{defvar} or @code{defconst}, and in general the first | |
269 | argument of any expression that starts with @samp{(def} in column zero, is | |
270 | a tag. | |
271 | ||
272 | @item | |
273 | In Scheme code, tags include anything defined with @code{def} or with a | |
274 | construct whose name starts with @samp{def}. They also include variables | |
275 | set with @code{set!} at top level in the file. | |
276 | @end itemize | |
277 | ||
278 | Several other languages are also supported: | |
279 | ||
280 | @itemize @bullet | |
281 | ||
282 | @item | |
283 | In Ada code, functions, procedures, packages, tasks, and types are | |
284 | tags. Use the @samp{--packages-only} option to create tags for | |
285 | packages only. | |
286 | ||
287 | In Ada, the same name can be used for different kinds of entity | |
288 | (e.g.@:, for a procedure and for a function). Also, for things like | |
289 | packages, procedures and functions, there is the spec (i.e.@: the | |
290 | interface) and the body (i.e.@: the implementation). To make it | |
291 | easier to pick the definition you want, Ada tag name have suffixes | |
292 | indicating the type of entity: | |
293 | ||
294 | @table @samp | |
295 | @item /b | |
296 | package body. | |
297 | @item /f | |
298 | function. | |
299 | @item /k | |
300 | task. | |
301 | @item /p | |
302 | procedure. | |
303 | @item /s | |
304 | package spec. | |
305 | @item /t | |
306 | type. | |
307 | @end table | |
308 | ||
309 | Thus, @kbd{M-x find-tag @key{RET} bidule/b @key{RET}} will go | |
310 | directly to the body of the package @code{bidule}, while @kbd{M-x | |
311 | find-tag @key{RET} bidule @key{RET}} will just search for any tag | |
312 | @code{bidule}. | |
313 | ||
314 | @item | |
315 | In assembler code, labels appearing at the beginning of a line, | |
316 | followed by a colon, are tags. | |
317 | ||
318 | @item | |
319 | In Bison or Yacc input files, each rule defines as a tag the nonterminal | |
320 | it constructs. The portions of the file that contain C code are parsed | |
321 | as C code. | |
322 | ||
323 | @item | |
324 | In Cobol code, tags are paragraph names; that is, any word starting in | |
325 | column 8 and followed by a period. | |
326 | ||
327 | @item | |
328 | In Erlang code, the tags are the functions, records, and macros defined | |
329 | in the file. | |
330 | ||
331 | @item | |
47d7776c | 332 | In Fortran code, functions, subroutines and block data are tags. |
f00366c2 RS |
333 | |
334 | @item | |
335 | In makefiles, targets are tags. | |
336 | ||
337 | @item | |
338 | In Objective C code, tags include Objective C definitions for classes, | |
3e7eaab2 FP |
339 | class categories, methods, and protocols. Tags for variables and |
340 | functions in classes are named @samp{@var{class}::@var{variable}} and | |
341 | @samp{@var{class}::@var{function}}. | |
f00366c2 RS |
342 | |
343 | @item | |
344 | In Pascal code, the tags are the functions and procedures defined in | |
345 | the file. | |
346 | ||
347 | @item | |
3e7eaab2 FP |
348 | In Perl code, the tags are the packages, subroutines and variables |
349 | defined by the @code{package}, @code{sub}, @code{my} and @code{local} | |
350 | keywords. Use @samp{--globals} if you want to tag global variables. | |
351 | Tags for subroutines are named @samp{@var{package}::@var{sub}}. The | |
352 | name for subroutines defined in the default package is | |
353 | @samp{main::@var{sub}}. | |
f00366c2 | 354 | |
e94a3679 FP |
355 | @item |
356 | In PHP code, tags are functions, classes and defines. When using the | |
357 | @samp{--members} option, vars are tags too. | |
358 | ||
f00366c2 RS |
359 | @item |
360 | In PostScript code, the tags are the functions. | |
361 | ||
362 | @item | |
e94a3679 FP |
363 | In Prolog code, tags are predicates and rules at the beginning of |
364 | line. | |
f00366c2 RS |
365 | |
366 | @item | |
367 | In Python code, @code{def} or @code{class} at the beginning of a line | |
368 | generate a tag. | |
369 | @end itemize | |
370 | ||
371 | You can also generate tags based on regexp matching (@pxref{Etags | |
372 | Regexps}) to handle other formats and languages. | |
373 | ||
374 | @node Create Tags Table | |
375 | @subsection Creating Tags Tables | |
376 | @cindex @code{etags} program | |
377 | ||
378 | The @code{etags} program is used to create a tags table file. It knows | |
379 | the syntax of several languages, as described in | |
380 | @iftex | |
381 | the previous section. | |
382 | @end iftex | |
383 | @ifinfo | |
384 | @ref{Tag Syntax}. | |
385 | @end ifinfo | |
386 | Here is how to run @code{etags}: | |
387 | ||
388 | @example | |
389 | etags @var{inputfiles}@dots{} | |
390 | @end example | |
391 | ||
392 | @noindent | |
393 | The @code{etags} program reads the specified files, and writes a tags | |
394 | table named @file{TAGS} in the current working directory. | |
395 | ||
396 | If the specified files don't exist, @code{etags} looks for | |
397 | compressed versions of them and uncompresses them to read them. Under | |
398 | MS-DOS, @code{etags} also looks for file names like @file{mycode.cgz} | |
399 | if it is given @samp{mycode.c} on the command line and @file{mycode.c} | |
400 | does not exist. | |
401 | ||
402 | @code{etags} recognizes the language used in an input file based on | |
403 | its file name and contents. You can specify the language with the | |
404 | @samp{--language=@var{name}} option, described below. | |
405 | ||
406 | If the tags table data become outdated due to changes in the files | |
407 | described in the table, the way to update the tags table is the same | |
55d3737d RS |
408 | way it was made in the first place. If the tags table fails to record |
409 | a tag, or records it for the wrong file, then Emacs cannot possibly | |
410 | find its definition until you update the tags table. However, if the | |
f00366c2 | 411 | position recorded in the tags table becomes a little bit wrong (due to |
55d3737d RS |
412 | other editing), the only consequence is a slight delay in finding the |
413 | tag. Even if the stored position is very far wrong, Emacs will still | |
414 | find the tag, after searching most of the file for it. Even that | |
415 | delay is hardly noticeable with today's computers. | |
f00366c2 RS |
416 | |
417 | So you should update a tags table when you define new tags that you want | |
418 | to have listed, or when you move tag definitions from one file to another, | |
419 | or when changes become substantial. Normally there is no need to update | |
420 | the tags table after each edit, or even every day. | |
421 | ||
422 | One tags table can virtually include another. Specify the included | |
423 | tags file name with the @samp{--include=@var{file}} option when | |
424 | creating the file that is to include it. The latter file then acts as | |
425 | if it covered all the source files specified in the included file, as | |
426 | well as the files it directly contains. | |
427 | ||
428 | If you specify the source files with relative file names when you run | |
429 | @code{etags}, the tags file will contain file names relative to the | |
430 | directory where the tags file was initially written. This way, you can | |
431 | move an entire directory tree containing both the tags file and the | |
432 | source files, and the tags file will still refer correctly to the source | |
433 | files. | |
434 | ||
435 | If you specify absolute file names as arguments to @code{etags}, then | |
436 | the tags file will contain absolute file names. This way, the tags file | |
437 | will still refer to the same files even if you move it, as long as the | |
438 | source files remain in the same place. Absolute file names start with | |
439 | @samp{/}, or with @samp{@var{device}:/} on MS-DOS and MS-Windows. | |
440 | ||
441 | When you want to make a tags table from a great number of files, you | |
442 | may have problems listing them on the command line, because some systems | |
443 | have a limit on its length. The simplest way to circumvent this limit | |
444 | is to tell @code{etags} to read the file names from its standard input, | |
445 | by typing a dash in place of the file names, like this: | |
446 | ||
447 | @smallexample | |
448 | find . -name "*.[chCH]" -print | etags - | |
449 | @end smallexample | |
450 | ||
451 | Use the option @samp{--language=@var{name}} to specify the language | |
452 | explicitly. You can intermix these options with file names; each one | |
453 | applies to the file names that follow it. Specify | |
454 | @samp{--language=auto} to tell @code{etags} to resume guessing the | |
455 | language from the file names and file contents. Specify | |
456 | @samp{--language=none} to turn off language-specific processing | |
457 | entirely; then @code{etags} recognizes tags by regexp matching alone | |
458 | (@pxref{Etags Regexps}). | |
459 | ||
e4a1e8d9 FP |
460 | The option @samp{--parse-stdin=@var{file}} is mostly useful when |
461 | calling @code{etags} from programs. It can be used (only once) in | |
462 | place of a file name on the command line. @code{Etags} will read from | |
463 | standard input and mark the produced tags as belonging to the file | |
464 | @var{file}. | |
465 | ||
f00366c2 RS |
466 | @samp{etags --help} prints the list of the languages @code{etags} |
467 | knows, and the file name rules for guessing the language. It also prints | |
468 | a list of all the available @code{etags} options, together with a short | |
469 | explanation. | |
470 | ||
471 | @node Etags Regexps | |
472 | @subsection Etags Regexps | |
473 | ||
474 | The @samp{--regex} option provides a general way of recognizing tags | |
475 | based on regexp matching. You can freely intermix it with file names. | |
476 | Each @samp{--regex} option adds to the preceding ones, and applies only | |
477 | to the following files. The syntax is: | |
478 | ||
479 | @smallexample | |
cc76b311 FP |
480 | --regex=[@var{@{language@}}]/@var{tagregexp}/[@var{nameregexp}/]@var{modifiers} |
481 | @end smallexample | |
482 | ||
648ed8f4 FP |
483 | @noindent |
484 | or else: | |
cc76b311 FP |
485 | |
486 | @smallexample | |
487 | --regex=@@@var{regexfile} | |
f00366c2 RS |
488 | @end smallexample |
489 | ||
490 | @noindent | |
648ed8f4 FP |
491 | where @var{tagregexp} is a regular expression used to find the tags. |
492 | It is always | |
f00366c2 RS |
493 | anchored, that is, it behaves as if preceded by @samp{^}. If you want |
494 | to account for indentation, just match any initial number of blanks by | |
495 | beginning your regular expression with @samp{[ \t]*}. In the regular | |
b4b39c67 FP |
496 | expressions, @samp{\} quotes the next character, and all the |
497 | @code{gcc} character escape sequences are supported. Here is the list | |
498 | of the character escape sequences: | |
499 | ||
500 | @table @samp | |
501 | @item \a | |
502 | BEL (bell). | |
503 | @item \b | |
504 | BS (back space). | |
505 | @item \d | |
506 | DEL (delete). | |
507 | @item \e | |
508 | ESC (delete). | |
509 | @item \f | |
510 | FF (form feed). | |
511 | @item \n | |
512 | NL (new line). | |
513 | @item \r | |
514 | CR (carriage return). | |
515 | @item \t | |
516 | TAB (horizontal tab). | |
517 | @item \v | |
518 | VT (vertical tab). | |
519 | @end table | |
f00366c2 | 520 | |
648ed8f4 FP |
521 | @noindent |
522 | The syntax of regular expressions in @code{etags} is the same as in | |
e30fbfef | 523 | Emacs. |
f00366c2 RS |
524 | |
525 | You should not match more characters with @var{tagregexp} than that | |
526 | needed to recognize what you want to tag. If the match is such that | |
527 | more characters than needed are unavoidably matched by @var{tagregexp} | |
cc76b311 | 528 | (as will sometimes be the case), you should add a @var{nameregexp}, to |
f00366c2 RS |
529 | pick out just the tag. This will enable Emacs to find tags more |
530 | accurately and to do completion on tag names more reliably. You can | |
531 | find some examples below. | |
532 | ||
648ed8f4 FP |
533 | The suggested separator character used to delimit @var{tagregexp} |
534 | and @var{nameregex} is @samp{/}, as in the example above. However, | |
535 | you can use any other character as a separator, as long as it is | |
536 | different from space, tab, braces or the @samp{@@} character. If you | |
537 | need to use the separator as part of the regular expression, you must | |
538 | precede it by the @samp{\} character. | |
cc76b311 FP |
539 | |
540 | The @var{modifiers} are a sequence of 0 or more characters that | |
648ed8f4 FP |
541 | modify the way @code{etags} does the matching for that particular |
542 | @samp{--regex} option. Without modifiers, the regular expression | |
543 | is applied sequentially to each line of the input file, in | |
cc76b311 FP |
544 | a case-sensitive way. The modifiers and their meanings are: |
545 | ||
546 | @table @samp | |
547 | @item i | |
548 | ignore case when matching. | |
549 | @item m | |
648ed8f4 FP |
550 | do not match line by line; rather, match this regular expression |
551 | against the whole file, so that multi-line matches are possible. | |
cc76b311 FP |
552 | @item s |
553 | implies @samp{m}, and causes dots in @var{tagregexp} to match newlines | |
554 | as well. | |
555 | @end table | |
556 | ||
b8fc5a9c FP |
557 | A @var{regexfile} is the name of a file where you can store the |
558 | arguments of @samp{--regex} options, one per line. The syntax is the | |
648ed8f4 | 559 | same as the one used for the @samp{--regex} option, without the |
b8fc5a9c FP |
560 | initial @samp{--regex=} part. @code{etags} ignores the lines that |
561 | begin with space or tab: you can use them to include comments in the | |
562 | @var{regexfile}. | |
f00366c2 RS |
563 | |
564 | The @samp{-R} option deletes all the regexps defined with | |
565 | @samp{--regex} options. It applies to the file names following it, as | |
566 | you can see from the following example: | |
567 | ||
568 | @smallexample | |
648ed8f4 | 569 | etags --regex=/@var{reg1}/i voo.doo --regex=/@var{reg2}/m \ |
f00366c2 RS |
570 | bar.ber -R --lang=lisp los.er |
571 | @end smallexample | |
572 | ||
573 | @noindent | |
574 | Here @code{etags} chooses the parsing language for @file{voo.doo} and | |
575 | @file{bar.ber} according to their contents. @code{etags} also uses | |
576 | @var{reg1} to recognize additional tags in @file{voo.doo}, and both | |
577 | @var{reg1} and @var{reg2} to recognize additional tags in | |
648ed8f4 FP |
578 | @file{bar.ber}. @var{reg1} is checked against each line of |
579 | @file{voo.doo} and @file{bar.ber}, in a case-insensitive way, while | |
580 | @var{reg2} is checked against the whole @file{bar.ber} file, | |
581 | permitting multi-line matches, in a case-sensitive way. @code{etags} | |
582 | uses the Lisp tags rules, and no regexp matching, to recognize tags in | |
583 | @file{los.er}. | |
f00366c2 | 584 | |
b8fc5a9c FP |
585 | You can restrict a @samp{--regex} option to match only files of a |
586 | given language by using the optional prefix @var{@{language@}}. | |
648ed8f4 FP |
587 | (@samp{etags --help} prints the list of languages recognized by |
588 | @code{etags}.) This is particularly useful when storing many | |
589 | predefined regular expressions for @code{etags} in a file. The | |
f00366c2 RS |
590 | following example tags the @code{DEFVAR} macros in the Emacs source |
591 | files, for the C language only: | |
592 | ||
593 | @smallexample | |
594 | --regex='@{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/' | |
595 | @end smallexample | |
596 | ||
597 | @noindent | |
598 | This feature is particularly useful when you store a list of regular | |
599 | expressions in a file. The following option syntax instructs | |
600 | @code{etags} to read two files of regular expressions. The regular | |
601 | expressions contained in the second file are matched without regard to | |
602 | case. | |
603 | ||
604 | @smallexample | |
605 | --regex=@@first-file --ignore-case-regex=@@second-file | |
606 | @end smallexample | |
607 | ||
608 | @noindent | |
609 | A regex file contains one regular expressions per line. Empty lines, | |
610 | and lines beginning with space or tab are ignored. When the first | |
611 | character in a line is @samp{@@}, @code{etags} assumes that the rest | |
612 | of the line is the name of a file of regular expressions; thus, one | |
613 | such file can include another file. All the other lines are taken to | |
614 | be regular expressions. If the first non-whitespace text on the line | |
615 | is @samp{--}, that line is a comment. | |
616 | ||
617 | For example, one can create a file called @samp{emacs.tags} with the | |
618 | following contents: | |
619 | ||
620 | @smallexample | |
621 | -- This is for GNU Emacs C source files | |
622 | @{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/\1/ | |
623 | @end smallexample | |
624 | ||
625 | @noindent | |
626 | and then use it like this: | |
627 | ||
628 | @smallexample | |
629 | etags --regex=@@emacs.tags *.[ch] */*.[ch] | |
630 | @end smallexample | |
631 | ||
632 | Here are some more examples. The regexps are quoted to protect them | |
633 | from shell interpretation. | |
634 | ||
635 | @itemize @bullet | |
636 | ||
637 | @item | |
638 | Tag Octave files: | |
639 | ||
640 | @smallexample | |
641 | etags --language=none \ | |
642 | --regex='/[ \t]*function.*=[ \t]*\([^ \t]*\)[ \t]*(/\1/' \ | |
643 | --regex='/###key \(.*\)/\1/' \ | |
644 | --regex='/[ \t]*global[ \t].*/' \ | |
645 | *.m | |
646 | @end smallexample | |
647 | ||
648 | @noindent | |
649 | Note that tags are not generated for scripts, so that you have to add | |
650 | a line by yourself of the form @samp{###key @var{scriptname}} if you | |
651 | want to jump to it. | |
652 | ||
653 | @item | |
654 | Tag Tcl files: | |
655 | ||
656 | @smallexample | |
657 | etags --language=none --regex='/proc[ \t]+\([^ \t]+\)/\1/' *.tcl | |
658 | @end smallexample | |
659 | ||
660 | @item | |
661 | Tag VHDL files: | |
662 | ||
663 | @smallexample | |
664 | etags --language=none \ | |
665 | --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/' \ | |
666 | --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\ | |
667 | \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/' | |
668 | @end smallexample | |
669 | @end itemize | |
670 | ||
671 | @node Select Tags Table | |
672 | @subsection Selecting a Tags Table | |
673 | ||
674 | @vindex tags-file-name | |
675 | @findex visit-tags-table | |
676 | Emacs has at any time one @dfn{selected} tags table, and all the commands | |
677 | for working with tags tables use the selected one. To select a tags table, | |
678 | type @kbd{M-x visit-tags-table}, which reads the tags table file name as an | |
679 | argument. The name @file{TAGS} in the default directory is used as the | |
680 | default file name. | |
681 | ||
682 | All this command does is store the file name in the variable | |
683 | @code{tags-file-name}. Emacs does not actually read in the tags table | |
684 | contents until you try to use them. Setting this variable yourself is just | |
685 | as good as using @code{visit-tags-table}. The variable's initial value is | |
686 | @code{nil}; that value tells all the commands for working with tags tables | |
687 | that they must ask for a tags table file name to use. | |
688 | ||
689 | Using @code{visit-tags-table} when a tags table is already loaded | |
690 | gives you a choice: you can add the new tags table to the current list | |
691 | of tags tables, or start a new list. The tags commands use all the tags | |
692 | tables in the current list. If you start a new list, the new tags table | |
693 | is used @emph{instead} of others. If you add the new table to the | |
694 | current list, it is used @emph{as well as} the others. When the tags | |
695 | commands scan the list of tags tables, they don't always start at the | |
696 | beginning of the list; they start with the first tags table (if any) | |
697 | that describes the current file, proceed from there to the end of the | |
698 | list, and then scan from the beginning of the list until they have | |
699 | covered all the tables in the list. | |
700 | ||
701 | @vindex tags-table-list | |
702 | You can specify a precise list of tags tables by setting the variable | |
703 | @code{tags-table-list} to a list of strings, like this: | |
704 | ||
705 | @c keep this on two lines for formatting in smallbook | |
706 | @example | |
707 | @group | |
708 | (setq tags-table-list | |
709 | '("~/emacs" "/usr/local/lib/emacs/src")) | |
710 | @end group | |
711 | @end example | |
712 | ||
713 | @noindent | |
714 | This tells the tags commands to look at the @file{TAGS} files in your | |
715 | @file{~/emacs} directory and in the @file{/usr/local/lib/emacs/src} | |
716 | directory. The order depends on which file you are in and which tags | |
717 | table mentions that file, as explained above. | |
718 | ||
719 | Do not set both @code{tags-file-name} and @code{tags-table-list}. | |
720 | ||
721 | @node Find Tag | |
722 | @subsection Finding a Tag | |
723 | ||
724 | The most important thing that a tags table enables you to do is to find | |
725 | the definition of a specific tag. | |
726 | ||
727 | @table @kbd | |
728 | @item M-.@: @var{tag} @key{RET} | |
729 | Find first definition of @var{tag} (@code{find-tag}). | |
730 | @item C-u M-. | |
731 | Find next alternate definition of last tag specified. | |
732 | @item C-u - M-. | |
733 | Go back to previous tag found. | |
734 | @item C-M-. @var{pattern} @key{RET} | |
735 | Find a tag whose name matches @var{pattern} (@code{find-tag-regexp}). | |
736 | @item C-u C-M-. | |
737 | Find the next tag whose name matches the last pattern used. | |
738 | @item C-x 4 .@: @var{tag} @key{RET} | |
739 | Find first definition of @var{tag}, but display it in another window | |
740 | (@code{find-tag-other-window}). | |
741 | @item C-x 5 .@: @var{tag} @key{RET} | |
742 | Find first definition of @var{tag}, and create a new frame to select the | |
743 | buffer (@code{find-tag-other-frame}). | |
744 | @item M-* | |
745 | Pop back to where you previously invoked @kbd{M-.} and friends. | |
746 | @end table | |
747 | ||
748 | @kindex M-. | |
749 | @findex find-tag | |
750 | @kbd{M-.}@: (@code{find-tag}) is the command to find the definition of | |
751 | a specified tag. It searches through the tags table for that tag, as a | |
752 | string, and then uses the tags table info to determine the file that the | |
753 | definition is in and the approximate character position in the file of | |
754 | the definition. Then @code{find-tag} visits that file, moves point to | |
755 | the approximate character position, and searches ever-increasing | |
756 | distances away to find the tag definition. | |
757 | ||
758 | If an empty argument is given (just type @key{RET}), the balanced | |
759 | expression in the buffer before or around point is used as the | |
760 | @var{tag} argument. @xref{Expressions}. | |
761 | ||
762 | You don't need to give @kbd{M-.} the full name of the tag; a part | |
763 | will do. This is because @kbd{M-.} finds tags in the table which | |
764 | contain @var{tag} as a substring. However, it prefers an exact match | |
765 | to a substring match. To find other tags that match the same | |
766 | substring, give @code{find-tag} a numeric argument, as in @kbd{C-u | |
767 | M-.}; this does not read a tag name, but continues searching the tags | |
768 | table's text for another tag containing the same substring last used. | |
769 | If you have a real @key{META} key, @kbd{M-0 M-.}@: is an easier | |
770 | alternative to @kbd{C-u M-.}. | |
771 | ||
772 | @kindex C-x 4 . | |
773 | @findex find-tag-other-window | |
774 | @kindex C-x 5 . | |
775 | @findex find-tag-other-frame | |
776 | Like most commands that can switch buffers, @code{find-tag} has a | |
777 | variant that displays the new buffer in another window, and one that | |
778 | makes a new frame for it. The former is @kbd{C-x 4 .}, which invokes | |
779 | the command @code{find-tag-other-window}. The latter is @kbd{C-x 5 .}, | |
780 | which invokes @code{find-tag-other-frame}. | |
781 | ||
782 | To move back to places you've found tags recently, use @kbd{C-u - | |
783 | M-.}; more generally, @kbd{M-.} with a negative numeric argument. This | |
784 | command can take you to another buffer. @kbd{C-x 4 .} with a negative | |
785 | argument finds the previous tag location in another window. | |
786 | ||
787 | @kindex M-* | |
788 | @findex pop-tag-mark | |
789 | @vindex find-tag-marker-ring-length | |
790 | As well as going back to places you've found tags recently, you can go | |
791 | back to places @emph{from where} you found them. Use @kbd{M-*}, which | |
792 | invokes the command @code{pop-tag-mark}, for this. Typically you would | |
793 | find and study the definition of something with @kbd{M-.} and then | |
794 | return to where you were with @kbd{M-*}. | |
795 | ||
796 | Both @kbd{C-u - M-.} and @kbd{M-*} allow you to retrace your steps to | |
797 | a depth determined by the variable @code{find-tag-marker-ring-length}. | |
798 | ||
799 | @findex find-tag-regexp | |
800 | @kindex C-M-. | |
801 | The command @kbd{C-M-.} (@code{find-tag-regexp}) visits the tags that | |
802 | match a specified regular expression. It is just like @kbd{M-.} except | |
803 | that it does regexp matching instead of substring matching. | |
804 | ||
805 | @node Tags Search | |
806 | @subsection Searching and Replacing with Tags Tables | |
807 | @cindex search and replace in multiple files | |
808 | @cindex multiple-file search and replace | |
809 | ||
810 | The commands in this section visit and search all the files listed in the | |
811 | selected tags table, one by one. For these commands, the tags table serves | |
812 | only to specify a sequence of files to search. | |
813 | ||
814 | @table @kbd | |
815 | @item M-x tags-search @key{RET} @var{regexp} @key{RET} | |
816 | Search for @var{regexp} through the files in the selected tags | |
817 | table. | |
818 | @item M-x tags-query-replace @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET} | |
819 | Perform a @code{query-replace-regexp} on each file in the selected tags table. | |
820 | @item M-, | |
821 | Restart one of the commands above, from the current location of point | |
822 | (@code{tags-loop-continue}). | |
823 | @end table | |
824 | ||
825 | @findex tags-search | |
826 | @kbd{M-x tags-search} reads a regexp using the minibuffer, then | |
827 | searches for matches in all the files in the selected tags table, one | |
828 | file at a time. It displays the name of the file being searched so you | |
829 | can follow its progress. As soon as it finds an occurrence, | |
830 | @code{tags-search} returns. | |
831 | ||
832 | @kindex M-, | |
833 | @findex tags-loop-continue | |
834 | Having found one match, you probably want to find all the rest. To find | |
835 | one more match, type @kbd{M-,} (@code{tags-loop-continue}) to resume the | |
836 | @code{tags-search}. This searches the rest of the current buffer, followed | |
837 | by the remaining files of the tags table.@refill | |
838 | ||
839 | @findex tags-query-replace | |
840 | @kbd{M-x tags-query-replace} performs a single | |
841 | @code{query-replace-regexp} through all the files in the tags table. It | |
842 | reads a regexp to search for and a string to replace with, just like | |
843 | ordinary @kbd{M-x query-replace-regexp}. It searches much like @kbd{M-x | |
844 | tags-search}, but repeatedly, processing matches according to your | |
845 | input. @xref{Replace}, for more information on query replace. | |
846 | ||
847 | @vindex tags-case-fold-search | |
848 | @cindex case-sensitivity and tags search | |
849 | You can control the case-sensitivity of tags search commands by | |
850 | customizing the value of the variable @code{tags-case-fold-search}. The | |
851 | default is to use the same setting as the value of | |
852 | @code{case-fold-search} (@pxref{Search Case}). | |
853 | ||
854 | It is possible to get through all the files in the tags table with a | |
855 | single invocation of @kbd{M-x tags-query-replace}. But often it is | |
856 | useful to exit temporarily, which you can do with any input event that | |
857 | has no special query replace meaning. You can resume the query replace | |
858 | subsequently by typing @kbd{M-,}; this command resumes the last tags | |
859 | search or replace command that you did. | |
860 | ||
861 | The commands in this section carry out much broader searches than the | |
862 | @code{find-tag} family. The @code{find-tag} commands search only for | |
863 | definitions of tags that match your substring or regexp. The commands | |
864 | @code{tags-search} and @code{tags-query-replace} find every occurrence | |
865 | of the regexp, as ordinary search commands and replace commands do in | |
866 | the current buffer. | |
867 | ||
868 | These commands create buffers only temporarily for the files that they | |
869 | have to search (those which are not already visited in Emacs buffers). | |
870 | Buffers in which no match is found are quickly killed; the others | |
871 | continue to exist. | |
872 | ||
873 | It may have struck you that @code{tags-search} is a lot like | |
874 | @code{grep}. You can also run @code{grep} itself as an inferior of | |
875 | Emacs and have Emacs show you the matching lines one by one. This works | |
876 | much like running a compilation; finding the source locations of the | |
877 | @code{grep} matches works like finding the compilation errors. | |
878 | @xref{Compilation}. | |
879 | ||
880 | @node List Tags | |
881 | @subsection Tags Table Inquiries | |
882 | ||
883 | @table @kbd | |
884 | @item M-x list-tags @key{RET} @var{file} @key{RET} | |
885 | Display a list of the tags defined in the program file @var{file}. | |
886 | @item M-x tags-apropos @key{RET} @var{regexp} @key{RET} | |
887 | Display a list of all tags matching @var{regexp}. | |
888 | @end table | |
889 | ||
890 | @findex list-tags | |
891 | @kbd{M-x list-tags} reads the name of one of the files described by | |
892 | the selected tags table, and displays a list of all the tags defined in | |
893 | that file. The ``file name'' argument is really just a string to | |
894 | compare against the file names recorded in the tags table; it is read as | |
895 | a string rather than as a file name. Therefore, completion and | |
896 | defaulting are not available, and you must enter the file name the same | |
897 | way it appears in the tags table. Do not include a directory as part of | |
898 | the file name unless the file name recorded in the tags table includes a | |
899 | directory. | |
900 | ||
901 | @findex tags-apropos | |
902 | @vindex tags-apropos-verbose | |
903 | @kbd{M-x tags-apropos} is like @code{apropos} for tags | |
904 | (@pxref{Apropos}). It finds all the tags in the selected tags table | |
905 | whose entries match @var{regexp}, and displays them. If the variable | |
906 | @code{tags-apropos-verbose} is non-@code{nil}, it displays the names | |
907 | of the tags files together with the tag names. | |
908 | ||
909 | @vindex tags-tag-face | |
910 | @vindex tags-apropos-additional-actions | |
911 | You can customize the appearance of the output with the face | |
912 | @code{tags-tag-face}. You can display additional output with @kbd{M-x | |
913 | tags-apropos} by customizing the variable | |
914 | @code{tags-apropos-additional-actions}---see its documentation for | |
915 | details. | |
916 | ||
917 | You can also use the collection of tag names to complete a symbol | |
918 | name in the buffer. @xref{Symbol Completion}. | |
919 | ||
ebe19e1b | 920 | @node Emerge |
f00366c2 RS |
921 | @section Merging Files with Emerge |
922 | @cindex Emerge | |
923 | @cindex merging files | |
924 | ||
925 | It's not unusual for programmers to get their signals crossed and modify | |
926 | the same program in two different directions. To recover from this | |
927 | confusion, you need to merge the two versions. Emerge makes this | |
928 | easier. See also @ref{Comparing Files}, for commands to compare | |
b5f1c9fa | 929 | in a more manual fashion, and @ref{Top, Ediff,, ediff, The Ediff Manual}. |
f00366c2 RS |
930 | |
931 | @menu | |
932 | * Overview of Emerge:: How to start Emerge. Basic concepts. | |
933 | * Submodes of Emerge:: Fast mode vs. Edit mode. | |
934 | Skip Prefers mode and Auto Advance mode. | |
935 | * State of Difference:: You do the merge by specifying state A or B | |
936 | for each difference. | |
937 | * Merge Commands:: Commands for selecting a difference, | |
938 | changing states of differences, etc. | |
939 | * Exiting Emerge:: What to do when you've finished the merge. | |
940 | * Combining in Emerge:: How to keep both alternatives for a difference. | |
941 | * Fine Points of Emerge:: Misc. | |
942 | @end menu | |
943 | ||
944 | @node Overview of Emerge | |
945 | @subsection Overview of Emerge | |
946 | ||
947 | To start Emerge, run one of these four commands: | |
948 | ||
949 | @table @kbd | |
950 | @item M-x emerge-files | |
951 | @findex emerge-files | |
952 | Merge two specified files. | |
953 | ||
954 | @item M-x emerge-files-with-ancestor | |
955 | @findex emerge-files-with-ancestor | |
956 | Merge two specified files, with reference to a common ancestor. | |
957 | ||
958 | @item M-x emerge-buffers | |
959 | @findex emerge-buffers | |
960 | Merge two buffers. | |
961 | ||
962 | @item M-x emerge-buffers-with-ancestor | |
963 | @findex emerge-buffers-with-ancestor | |
964 | Merge two buffers with reference to a common ancestor in a third | |
965 | buffer. | |
966 | @end table | |
967 | ||
968 | @cindex merge buffer (Emerge) | |
969 | @cindex A and B buffers (Emerge) | |
970 | The Emerge commands compare two files or buffers, and display the | |
971 | comparison in three buffers: one for each input text (the @dfn{A buffer} | |
972 | and the @dfn{B buffer}), and one (the @dfn{merge buffer}) where merging | |
973 | takes place. The merge buffer shows the full merged text, not just the | |
974 | differences. Wherever the two input texts differ, you can choose which | |
975 | one of them to include in the merge buffer. | |
976 | ||
977 | The Emerge commands that take input from existing buffers use only the | |
978 | accessible portions of those buffers, if they are narrowed | |
979 | (@pxref{Narrowing}). | |
980 | ||
981 | If a common ancestor version is available, from which the two texts to | |
982 | be merged were both derived, Emerge can use it to guess which | |
983 | alternative is right. Wherever one current version agrees with the | |
984 | ancestor, Emerge presumes that the other current version is a deliberate | |
985 | change which should be kept in the merged version. Use the | |
986 | @samp{with-ancestor} commands if you want to specify a common ancestor | |
987 | text. These commands read three file or buffer names---variant A, | |
988 | variant B, and the common ancestor. | |
989 | ||
990 | After the comparison is done and the buffers are prepared, the | |
991 | interactive merging starts. You control the merging by typing special | |
992 | @dfn{merge commands} in the merge buffer. The merge buffer shows you a | |
993 | full merged text, not just differences. For each run of differences | |
994 | between the input texts, you can choose which one of them to keep, or | |
995 | edit them both together. | |
996 | ||
997 | The merge buffer uses a special major mode, Emerge mode, with commands | |
998 | for making these choices. But you can also edit the buffer with | |
999 | ordinary Emacs commands. | |
1000 | ||
1001 | At any given time, the attention of Emerge is focused on one | |
1002 | particular difference, called the @dfn{selected} difference. This | |
1003 | difference is marked off in the three buffers like this: | |
1004 | ||
1005 | @example | |
1006 | vvvvvvvvvvvvvvvvvvvv | |
1007 | @var{text that differs} | |
1008 | ^^^^^^^^^^^^^^^^^^^^ | |
1009 | @end example | |
1010 | ||
1011 | @noindent | |
1012 | Emerge numbers all the differences sequentially and the mode | |
1013 | line always shows the number of the selected difference. | |
1014 | ||
1015 | Normally, the merge buffer starts out with the A version of the text. | |
1016 | But when the A version of a difference agrees with the common ancestor, | |
1017 | then the B version is initially preferred for that difference. | |
1018 | ||
1019 | Emerge leaves the merged text in the merge buffer when you exit. At | |
1020 | that point, you can save it in a file with @kbd{C-x C-w}. If you give a | |
1021 | numeric argument to @code{emerge-files} or | |
1022 | @code{emerge-files-with-ancestor}, it reads the name of the output file | |
1023 | using the minibuffer. (This is the last file name those commands read.) | |
1024 | Then exiting from Emerge saves the merged text in the output file. | |
1025 | ||
1026 | Normally, Emerge commands save the output buffer in its file when you | |
1027 | exit. If you abort Emerge with @kbd{C-]}, the Emerge command does not | |
1028 | save the output buffer, but you can save it yourself if you wish. | |
1029 | ||
1030 | @node Submodes of Emerge | |
1031 | @subsection Submodes of Emerge | |
1032 | ||
1033 | You can choose between two modes for giving merge commands: Fast mode | |
1034 | and Edit mode. In Fast mode, basic merge commands are single | |
1035 | characters, but ordinary Emacs commands are disabled. This is | |
1036 | convenient if you use only merge commands. In Edit mode, all merge | |
1037 | commands start with the prefix key @kbd{C-c C-c}, and the normal Emacs | |
1038 | commands are also available. This allows editing the merge buffer, but | |
1039 | slows down Emerge operations. | |
1040 | ||
1041 | Use @kbd{e} to switch to Edit mode, and @kbd{C-c C-c f} to switch to | |
1042 | Fast mode. The mode line indicates Edit and Fast modes with @samp{E} | |
1043 | and @samp{F}. | |
1044 | ||
1045 | Emerge has two additional submodes that affect how particular merge | |
1046 | commands work: Auto Advance mode and Skip Prefers mode. | |
1047 | ||
1048 | If Auto Advance mode is in effect, the @kbd{a} and @kbd{b} commands | |
1049 | advance to the next difference. This lets you go through the merge | |
1050 | faster as long as you simply choose one of the alternatives from the | |
1051 | input. The mode line indicates Auto Advance mode with @samp{A}. | |
1052 | ||
1053 | If Skip Prefers mode is in effect, the @kbd{n} and @kbd{p} commands | |
1054 | skip over differences in states prefer-A and prefer-B (@pxref{State of | |
1055 | Difference}). Thus you see only differences for which neither version | |
1056 | is presumed ``correct.'' The mode line indicates Skip Prefers mode with | |
1057 | @samp{S}. | |
1058 | ||
1059 | @findex emerge-auto-advance-mode | |
1060 | @findex emerge-skip-prefers-mode | |
1061 | Use the command @kbd{s a} (@code{emerge-auto-advance-mode}) to set or | |
1062 | clear Auto Advance mode. Use @kbd{s s} | |
1063 | (@code{emerge-skip-prefers-mode}) to set or clear Skip Prefers mode. | |
1064 | These commands turn on the mode with a positive argument, turns it off | |
1065 | with a negative or zero argument, and toggle the mode with no argument. | |
1066 | ||
1067 | @node State of Difference | |
1068 | @subsection State of a Difference | |
1069 | ||
1070 | In the merge buffer, a difference is marked with lines of @samp{v} and | |
1071 | @samp{^} characters. Each difference has one of these seven states: | |
1072 | ||
1073 | @table @asis | |
1074 | @item A | |
1075 | The difference is showing the A version. The @kbd{a} command always | |
1076 | produces this state; the mode line indicates it with @samp{A}. | |
1077 | ||
1078 | @item B | |
1079 | The difference is showing the B version. The @kbd{b} command always | |
1080 | produces this state; the mode line indicates it with @samp{B}. | |
1081 | ||
1082 | @item default-A | |
1083 | @itemx default-B | |
1084 | The difference is showing the A or the B state by default, because you | |
1085 | haven't made a choice. All differences start in the default-A state | |
1086 | (and thus the merge buffer is a copy of the A buffer), except those for | |
1087 | which one alternative is ``preferred'' (see below). | |
1088 | ||
1089 | When you select a difference, its state changes from default-A or | |
1090 | default-B to plain A or B. Thus, the selected difference never has | |
1091 | state default-A or default-B, and these states are never displayed in | |
1092 | the mode line. | |
1093 | ||
1094 | The command @kbd{d a} chooses default-A as the default state, and @kbd{d | |
1095 | b} chooses default-B. This chosen default applies to all differences | |
1096 | which you haven't ever selected and for which no alternative is preferred. | |
1097 | If you are moving through the merge sequentially, the differences you | |
1098 | haven't selected are those following the selected one. Thus, while | |
1099 | moving sequentially, you can effectively make the A version the default | |
1100 | for some sections of the merge buffer and the B version the default for | |
1101 | others by using @kbd{d a} and @kbd{d b} between sections. | |
1102 | ||
1103 | @item prefer-A | |
1104 | @itemx prefer-B | |
1105 | The difference is showing the A or B state because it is | |
1106 | @dfn{preferred}. This means that you haven't made an explicit choice, | |
1107 | but one alternative seems likely to be right because the other | |
1108 | alternative agrees with the common ancestor. Thus, where the A buffer | |
1109 | agrees with the common ancestor, the B version is preferred, because | |
1110 | chances are it is the one that was actually changed. | |
1111 | ||
1112 | These two states are displayed in the mode line as @samp{A*} and @samp{B*}. | |
1113 | ||
1114 | @item combined | |
1115 | The difference is showing a combination of the A and B states, as a | |
1116 | result of the @kbd{x c} or @kbd{x C} commands. | |
1117 | ||
1118 | Once a difference is in this state, the @kbd{a} and @kbd{b} commands | |
1119 | don't do anything to it unless you give them a numeric argument. | |
1120 | ||
1121 | The mode line displays this state as @samp{comb}. | |
1122 | @end table | |
1123 | ||
1124 | @node Merge Commands | |
1125 | @subsection Merge Commands | |
1126 | ||
1127 | Here are the Merge commands for Fast mode; in Edit mode, precede them | |
1128 | with @kbd{C-c C-c}: | |
1129 | ||
1130 | @table @kbd | |
1131 | @item p | |
1132 | Select the previous difference. | |
1133 | ||
1134 | @item n | |
1135 | Select the next difference. | |
1136 | ||
1137 | @item a | |
1138 | Choose the A version of this difference. | |
1139 | ||
1140 | @item b | |
1141 | Choose the B version of this difference. | |
1142 | ||
1143 | @item C-u @var{n} j | |
1144 | Select difference number @var{n}. | |
1145 | ||
1146 | @item . | |
1147 | Select the difference containing point. You can use this command in the | |
1148 | merge buffer or in the A or B buffer. | |
1149 | ||
1150 | @item q | |
1151 | Quit---finish the merge. | |
1152 | ||
1153 | @item C-] | |
1154 | Abort---exit merging and do not save the output. | |
1155 | ||
1156 | @item f | |
1157 | Go into Fast mode. (In Edit mode, this is actually @kbd{C-c C-c f}.) | |
1158 | ||
1159 | @item e | |
1160 | Go into Edit mode. | |
1161 | ||
1162 | @item l | |
1163 | Recenter (like @kbd{C-l}) all three windows. | |
1164 | ||
1165 | @item - | |
1166 | Specify part of a prefix numeric argument. | |
1167 | ||
1168 | @item @var{digit} | |
1169 | Also specify part of a prefix numeric argument. | |
1170 | ||
1171 | @item d a | |
1172 | Choose the A version as the default from here down in | |
1173 | the merge buffer. | |
1174 | ||
1175 | @item d b | |
1176 | Choose the B version as the default from here down in | |
1177 | the merge buffer. | |
1178 | ||
1179 | @item c a | |
1180 | Copy the A version of this difference into the kill ring. | |
1181 | ||
1182 | @item c b | |
1183 | Copy the B version of this difference into the kill ring. | |
1184 | ||
1185 | @item i a | |
1186 | Insert the A version of this difference at point. | |
1187 | ||
1188 | @item i b | |
1189 | Insert the B version of this difference at point. | |
1190 | ||
1191 | @item m | |
1192 | Put point and mark around the difference. | |
1193 | ||
1194 | @item ^ | |
1195 | Scroll all three windows down (like @kbd{M-v}). | |
1196 | ||
1197 | @item v | |
1198 | Scroll all three windows up (like @kbd{C-v}). | |
1199 | ||
1200 | @item < | |
1201 | Scroll all three windows left (like @kbd{C-x <}). | |
1202 | ||
1203 | @item > | |
1204 | Scroll all three windows right (like @kbd{C-x >}). | |
1205 | ||
1206 | @item | | |
1207 | Reset horizontal scroll on all three windows. | |
1208 | ||
1209 | @item x 1 | |
1210 | Shrink the merge window to one line. (Use @kbd{C-u l} to restore it | |
1211 | to full size.) | |
1212 | ||
1213 | @item x c | |
1214 | Combine the two versions of this difference (@pxref{Combining in | |
1215 | Emerge}). | |
1216 | ||
1217 | @item x f | |
1218 | Show the names of the files/buffers Emerge is operating on, in a Help | |
1219 | window. (Use @kbd{C-u l} to restore windows.) | |
1220 | ||
1221 | @item x j | |
1222 | Join this difference with the following one. | |
1223 | (@kbd{C-u x j} joins this difference with the previous one.) | |
1224 | ||
1225 | @item x s | |
1226 | Split this difference into two differences. Before you use this | |
1227 | command, position point in each of the three buffers at the place where | |
1228 | you want to split the difference. | |
1229 | ||
1230 | @item x t | |
1231 | Trim identical lines off the top and bottom of the difference. | |
1232 | Such lines occur when the A and B versions are | |
1233 | identical but differ from the ancestor version. | |
1234 | @end table | |
1235 | ||
1236 | @node Exiting Emerge | |
1237 | @subsection Exiting Emerge | |
1238 | ||
1239 | The @kbd{q} command (@code{emerge-quit}) finishes the merge, storing | |
1240 | the results into the output file if you specified one. It restores the | |
1241 | A and B buffers to their proper contents, or kills them if they were | |
1242 | created by Emerge and you haven't changed them. It also disables the | |
1243 | Emerge commands in the merge buffer, since executing them later could | |
1244 | damage the contents of the various buffers. | |
1245 | ||
1246 | @kbd{C-]} aborts the merge. This means exiting without writing the | |
1247 | output file. If you didn't specify an output file, then there is no | |
1248 | real difference between aborting and finishing the merge. | |
1249 | ||
1250 | If the Emerge command was called from another Lisp program, then its | |
1251 | return value is @code{t} for successful completion, or @code{nil} if you | |
1252 | abort. | |
1253 | ||
1254 | @node Combining in Emerge | |
1255 | @subsection Combining the Two Versions | |
1256 | ||
1257 | Sometimes you want to keep @emph{both} alternatives for a particular | |
1258 | difference. To do this, use @kbd{x c}, which edits the merge buffer | |
1259 | like this: | |
1260 | ||
1261 | @example | |
1262 | @group | |
1263 | #ifdef NEW | |
1264 | @var{version from A buffer} | |
1265 | #else /* not NEW */ | |
1266 | @var{version from B buffer} | |
1267 | #endif /* not NEW */ | |
1268 | @end group | |
1269 | @end example | |
1270 | ||
1271 | @noindent | |
1272 | @vindex emerge-combine-versions-template | |
1273 | While this example shows C preprocessor conditionals delimiting the two | |
1274 | alternative versions, you can specify the strings to use by setting | |
1275 | the variable @code{emerge-combine-versions-template} to a string of your | |
1276 | choice. In the string, @samp{%a} says where to put version A, and | |
1277 | @samp{%b} says where to put version B. The default setting, which | |
1278 | produces the results shown above, looks like this: | |
1279 | ||
1280 | @example | |
1281 | @group | |
1282 | "#ifdef NEW\n%a#else /* not NEW */\n%b#endif /* not NEW */\n" | |
1283 | @end group | |
1284 | @end example | |
1285 | ||
1286 | @node Fine Points of Emerge | |
1287 | @subsection Fine Points of Emerge | |
1288 | ||
1289 | During the merge, you mustn't try to edit the A and B buffers yourself. | |
1290 | Emerge modifies them temporarily, but ultimately puts them back the way | |
1291 | they were. | |
1292 | ||
1293 | You can have any number of merges going at once---just don't use any one | |
1294 | buffer as input to more than one merge at once, since the temporary | |
1295 | changes made in these buffers would get in each other's way. | |
1296 | ||
1297 | Starting Emerge can take a long time because it needs to compare the | |
1298 | files fully. Emacs can't do anything else until @code{diff} finishes. | |
1299 | Perhaps in the future someone will change Emerge to do the comparison in | |
1300 | the background when the input files are large---then you could keep on | |
1301 | doing other things with Emacs until Emerge is ready to accept | |
1302 | commands. | |
1303 | ||
1304 | @vindex emerge-startup-hook | |
1305 | After setting up the merge, Emerge runs the hook | |
1306 | @code{emerge-startup-hook} (@pxref{Hooks}). |