(add_regex): Invalid regexp modifiers are ignored.
[bpt/emacs.git] / man / maintaining.texi
CommitLineData
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
11version control features (@pxref{Version Control}) are also
12particularly 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
28file for the file you are editing
29(@code{add-change-log-entry-other-window}). If that file is actually
30a backup file, it makes an entry appropriate for the file's
31parent---that is useful for making log entries for functions that
32have been deleted in the current version.
33
34 A change log file contains a chronological record of when and why you
35have changed a program, consisting of a sequence of entries describing
36individual changes. Normally it is kept in a file called
37@file{ChangeLog} in the same directory as the file you are editing, or
38one of its parent directories. A single @file{ChangeLog} file can
39record changes for all the files in its directory and all its
40subdirectories.
41
1e4cb307
RS
42 You should put a copyright notice and permission notice at the
43end of the change log file. Here is an example:
44
45@example
46Copyright 1997, 1998 Free Software Foundation, Inc.
47Copying and distribution of this file, with or without modification, are
48permitted provided the copyright notice and this notice are preserved.
49@end example
50
51@noindent
52Of 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
55current date, your name, and your email address (taken from the
56variable @code{user-mail-address}). Aside from these header lines,
57every line in the change log starts with a space or a tab. The bulk
58of the entry consists of @dfn{items}, each of which starts with a line
59starting with whitespace and a star. Here are two entries, both dated
60in May 1993, each with two items:
61
62@iftex
63@medbreak
64@end iftex
65@smallexample
661993-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
741993-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
81own item. Normally there should be a blank line between items. When
82items are related (parts of the same change, in different places), group
83them by leaving no blank line between them. The second entry above
84contains two items grouped in this way.
85
86 @kbd{C-x 4 a} visits the change log file and creates a new entry
87unless the most recent entry is for today's date and your name. It
88also creates a new item for the current file. For many languages, it
89can even guess the name of the function or other object that was
90changed.
91
92@vindex add-log-keep-changes-together
93 When the option @code{add-log-keep-changes-together} is
94non-@code{nil}, @kbd{C-x 4 a} adds to any existing entry for the file
95rather 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}
101is non-@code{nil}, @kbd{C-x 4 a} adds the file's version number to the
102change log entry. It finds the version number by searching the first
103ten 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
109mode, each bunch of grouped items counts as one paragraph, and each
110entry is considered a page. This facilitates editing the entries.
111@kbd{C-j} and auto-fill indent each new line like the previous line;
112this 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
116log files into a buffer in Change Log Mode, preserving the date
117ordering 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
122the change log entry:
123
124@smallexample
125Fri May 25 11:23:23 1993 Richard Stallman <rms@@gnu.org>
126@end smallexample
127
128@noindent
129The @kbd{M-x change-log-redate} command converts all the old-style
130date entries in the change log file visited in the current buffer to
131the new format, to make the file uniform in style. This is handy when
132entries are contributed by many different people, some of whom use old
133versions of Emacs.
134
135 Version control systems are another way to keep track of changes in your
136program 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
148contributions. 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 153Emacs source directory. It then scans @file{ChangeLog} files and Lisp
f00366c2 154source files under that directory for information about authors of
d7ed11cd 155individual packages, and people who made changes in source files, and
f00366c2
RS
156puts the information it gleans into a buffer named @samp{*Authors*}.
157You can then edit the contents of that buffer and merge it with the
24cc235a 158existing @file{AUTHORS} file.
f00366c2
RS
159
160 Do not assume that this command finds all the contributors; don't
161assume that a person not listed in the output was not a contributor.
162If you merged in someone's contribution and did not put his name
163in 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
171broken up into files. It lists the names of the component files and the
172names and positions of the functions (or other named subunits) in each
173file. Grouping the related files makes it possible to search or replace
174through all the files with one command. Recording the function names
175and positions makes possible the @kbd{M-.} command which finds the
176definition 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
179conventional 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
182file that the tag is defined in (implicitly), and the position in that
183file of the tag's definition. When a file parsed by @code{etags} is
0f5401a8
FP
184generated from a different source file, like a C file generated from a
185Cweb source file, the tags of the parsed file reference the source
186file.
f00366c2
RS
187
188 Just what names from the described files are recorded in the tags table
189depends on the programming language of the described file. They
190normally include all file names, functions and subroutines, and may
191also include global variables, data types, and anything else
192convenient. 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
218In 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
221tags, unless you specify @samp{--no-defines} when making the tags table.
222Similarly, global variables are tags, unless you specify
223@samp{--no-globals}. Use of @samp{--no-globals} and @samp{--no-defines}
224can make the tags table file much smaller.
225
226You can tag function declarations and external variables in addition
227to function definitions by giving the @samp{--declarations} option to
228@code{etags}.
229
230@item
231In C++ code, in addition to all the tag constructs of C code, member
232functions are also recognized, and optionally member variables if you
233use the @samp{--members} option. Tags for variables and functions in
234classes are named @samp{@var{class}::@var{variable}} and
235@samp{@var{class}::@var{function}}. @code{operator} definitions have
236tag names like @samp{operator+}.
237
238@item
239In Java code, tags include all the constructs recognized in C++, plus
240the @code{interface}, @code{extends} and @code{implements} constructs.
241Tags for variables and functions in classes are named
242@samp{@var{class}.@var{variable}} and @samp{@var{class}.@var{function}}.
243
244@item
245In 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
252Other commands can make tags as well, if you specify them in the
253environment variable @env{TEXTAGS} before invoking @code{etags}. The
254value of this environment variable should be a colon-separated list of
255command names. For example,
256
257@example
e4a1e8d9 258TEXTAGS="mycommand:myothercommand"
f00366c2
RS
259export TEXTAGS
260@end example
261
262@noindent
e4a1e8d9
FP
263specifies (using Bourne shell syntax) that the commands
264@samp{\mycommand} and @samp{\myothercommand} also define tags.
f00366c2
RS
265
266@item
267In Lisp code, any function defined with @code{defun}, any variable
268defined with @code{defvar} or @code{defconst}, and in general the first
269argument of any expression that starts with @samp{(def} in column zero, is
270a tag.
271
272@item
273In Scheme code, tags include anything defined with @code{def} or with a
274construct whose name starts with @samp{def}. They also include variables
275set 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
283In Ada code, functions, procedures, packages, tasks, and types are
284tags. Use the @samp{--packages-only} option to create tags for
285packages only.
286
287In 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
289packages, procedures and functions, there is the spec (i.e.@: the
290interface) and the body (i.e.@: the implementation). To make it
291easier to pick the definition you want, Ada tag name have suffixes
292indicating the type of entity:
293
294@table @samp
295@item /b
296package body.
297@item /f
298function.
299@item /k
300task.
301@item /p
302procedure.
303@item /s
304package spec.
305@item /t
306type.
307@end table
308
309 Thus, @kbd{M-x find-tag @key{RET} bidule/b @key{RET}} will go
310directly to the body of the package @code{bidule}, while @kbd{M-x
311find-tag @key{RET} bidule @key{RET}} will just search for any tag
312@code{bidule}.
313
314@item
315In assembler code, labels appearing at the beginning of a line,
316followed by a colon, are tags.
317
318@item
319In Bison or Yacc input files, each rule defines as a tag the nonterminal
320it constructs. The portions of the file that contain C code are parsed
321as C code.
322
323@item
324In Cobol code, tags are paragraph names; that is, any word starting in
325column 8 and followed by a period.
326
327@item
328In Erlang code, the tags are the functions, records, and macros defined
329in the file.
330
331@item
47d7776c 332In Fortran code, functions, subroutines and block data are tags.
f00366c2
RS
333
334@item
335In makefiles, targets are tags.
336
337@item
338In Objective C code, tags include Objective C definitions for classes,
3e7eaab2
FP
339class categories, methods, and protocols. Tags for variables and
340functions in classes are named @samp{@var{class}::@var{variable}} and
341@samp{@var{class}::@var{function}}.
f00366c2
RS
342
343@item
344In Pascal code, the tags are the functions and procedures defined in
345the file.
346
347@item
3e7eaab2
FP
348In Perl code, the tags are the packages, subroutines and variables
349defined by the @code{package}, @code{sub}, @code{my} and @code{local}
350keywords. Use @samp{--globals} if you want to tag global variables.
351Tags for subroutines are named @samp{@var{package}::@var{sub}}. The
352name for subroutines defined in the default package is
353@samp{main::@var{sub}}.
f00366c2 354
e94a3679
FP
355@item
356In PHP code, tags are functions, classes and defines. When using the
357@samp{--members} option, vars are tags too.
358
f00366c2
RS
359@item
360In PostScript code, the tags are the functions.
361
362@item
e94a3679
FP
363In Prolog code, tags are predicates and rules at the beginning of
364line.
f00366c2
RS
365
366@item
367In Python code, @code{def} or @code{class} at the beginning of a line
368generate a tag.
369@end itemize
370
371 You can also generate tags based on regexp matching (@pxref{Etags
372Regexps}) 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
379the syntax of several languages, as described in
380@iftex
381the previous section.
382@end iftex
383@ifinfo
384@ref{Tag Syntax}.
385@end ifinfo
386Here is how to run @code{etags}:
387
388@example
389etags @var{inputfiles}@dots{}
390@end example
391
392@noindent
393The @code{etags} program reads the specified files, and writes a tags
394table named @file{TAGS} in the current working directory.
395
396 If the specified files don't exist, @code{etags} looks for
397compressed versions of them and uncompresses them to read them. Under
398MS-DOS, @code{etags} also looks for file names like @file{mycode.cgz}
399if it is given @samp{mycode.c} on the command line and @file{mycode.c}
400does not exist.
401
402 @code{etags} recognizes the language used in an input file based on
403its 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
407described in the table, the way to update the tags table is the same
55d3737d
RS
408way it was made in the first place. If the tags table fails to record
409a tag, or records it for the wrong file, then Emacs cannot possibly
410find its definition until you update the tags table. However, if the
f00366c2 411position recorded in the tags table becomes a little bit wrong (due to
55d3737d
RS
412other editing), the only consequence is a slight delay in finding the
413tag. Even if the stored position is very far wrong, Emacs will still
414find the tag, after searching most of the file for it. Even that
415delay 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
418to have listed, or when you move tag definitions from one file to another,
419or when changes become substantial. Normally there is no need to update
420the tags table after each edit, or even every day.
421
422 One tags table can virtually include another. Specify the included
423tags file name with the @samp{--include=@var{file}} option when
424creating the file that is to include it. The latter file then acts as
425if it covered all the source files specified in the included file, as
426well 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
430directory where the tags file was initially written. This way, you can
431move an entire directory tree containing both the tags file and the
432source files, and the tags file will still refer correctly to the source
433files.
434
435 If you specify absolute file names as arguments to @code{etags}, then
436the tags file will contain absolute file names. This way, the tags file
437will still refer to the same files even if you move it, as long as the
438source 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
442may have problems listing them on the command line, because some systems
443have a limit on its length. The simplest way to circumvent this limit
444is to tell @code{etags} to read the file names from its standard input,
445by typing a dash in place of the file names, like this:
446
447@smallexample
448find . -name "*.[chCH]" -print | etags -
449@end smallexample
450
451 Use the option @samp{--language=@var{name}} to specify the language
452explicitly. You can intermix these options with file names; each one
453applies to the file names that follow it. Specify
454@samp{--language=auto} to tell @code{etags} to resume guessing the
455language from the file names and file contents. Specify
456@samp{--language=none} to turn off language-specific processing
457entirely; 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
461calling @code{etags} from programs. It can be used (only once) in
462place of a file name on the command line. @code{Etags} will read from
463standard 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}
467knows, and the file name rules for guessing the language. It also prints
468a list of all the available @code{etags} options, together with a short
469explanation.
470
471@node Etags Regexps
472@subsection Etags Regexps
473
474 The @samp{--regex} option provides a general way of recognizing tags
475based on regexp matching. You can freely intermix it with file names.
476Each @samp{--regex} option adds to the preceding ones, and applies only
477to 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
484or else:
cc76b311
FP
485
486@smallexample
487--regex=@@@var{regexfile}
f00366c2
RS
488@end smallexample
489
490@noindent
648ed8f4
FP
491where @var{tagregexp} is a regular expression used to find the tags.
492It is always
f00366c2
RS
493anchored, that is, it behaves as if preceded by @samp{^}. If you want
494to account for indentation, just match any initial number of blanks by
495beginning your regular expression with @samp{[ \t]*}. In the regular
b4b39c67
FP
496expressions, @samp{\} quotes the next character, and all the
497@code{gcc} character escape sequences are supported. Here is the list
498of the character escape sequences:
499
500@table @samp
501@item \a
502BEL (bell).
503@item \b
504BS (back space).
505@item \d
506DEL (delete).
507@item \e
508ESC (delete).
509@item \f
510FF (form feed).
511@item \n
512NL (new line).
513@item \r
514CR (carriage return).
515@item \t
516TAB (horizontal tab).
517@item \v
518VT (vertical tab).
519@end table
f00366c2 520
648ed8f4
FP
521@noindent
522The syntax of regular expressions in @code{etags} is the same as in
e30fbfef 523Emacs.
f00366c2
RS
524
525 You should not match more characters with @var{tagregexp} than that
526needed to recognize what you want to tag. If the match is such that
527more 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
529pick out just the tag. This will enable Emacs to find tags more
530accurately and to do completion on tag names more reliably. You can
531find some examples below.
532
648ed8f4
FP
533 The suggested separator character used to delimit @var{tagregexp}
534and @var{nameregex} is @samp{/}, as in the example above. However,
535you can use any other character as a separator, as long as it is
536different from space, tab, braces or the @samp{@@} character. If you
537need to use the separator as part of the regular expression, you must
538precede it by the @samp{\} character.
cc76b311
FP
539
540 The @var{modifiers} are a sequence of 0 or more characters that
648ed8f4
FP
541modify the way @code{etags} does the matching for that particular
542@samp{--regex} option. Without modifiers, the regular expression
543is applied sequentially to each line of the input file, in
cc76b311
FP
544a case-sensitive way. The modifiers and their meanings are:
545
546@table @samp
547@item i
548ignore case when matching.
549@item m
648ed8f4
FP
550do not match line by line; rather, match this regular expression
551against the whole file, so that multi-line matches are possible.
cc76b311
FP
552@item s
553implies @samp{m}, and causes dots in @var{tagregexp} to match newlines
554as well.
555@end table
556
b8fc5a9c
FP
557 A @var{regexfile} is the name of a file where you can store the
558arguments of @samp{--regex} options, one per line. The syntax is the
648ed8f4 559same as the one used for the @samp{--regex} option, without the
b8fc5a9c
FP
560initial @samp{--regex=} part. @code{etags} ignores the lines that
561begin 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
566you can see from the following example:
567
568@smallexample
648ed8f4 569etags --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
574Here @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,
581permitting multi-line matches, in a case-sensitive way. @code{etags}
582uses 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
586given 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
589predefined regular expressions for @code{etags} in a file. The
f00366c2
RS
590following example tags the @code{DEFVAR} macros in the Emacs source
591files, for the C language only:
592
593@smallexample
594--regex='@{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
595@end smallexample
596
597@noindent
598This feature is particularly useful when you store a list of regular
599expressions in a file. The following option syntax instructs
600@code{etags} to read two files of regular expressions. The regular
601expressions contained in the second file are matched without regard to
602case.
603
604@smallexample
605--regex=@@first-file --ignore-case-regex=@@second-file
606@end smallexample
607
608@noindent
609A regex file contains one regular expressions per line. Empty lines,
610and lines beginning with space or tab are ignored. When the first
611character in a line is @samp{@@}, @code{etags} assumes that the rest
612of the line is the name of a file of regular expressions; thus, one
613such file can include another file. All the other lines are taken to
614be regular expressions. If the first non-whitespace text on the line
615is @samp{--}, that line is a comment.
616
617 For example, one can create a file called @samp{emacs.tags} with the
618following 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
626and then use it like this:
627
628@smallexample
629etags --regex=@@emacs.tags *.[ch] */*.[ch]
630@end smallexample
631
632 Here are some more examples. The regexps are quoted to protect them
633from shell interpretation.
634
635@itemize @bullet
636
637@item
638Tag Octave files:
639
640@smallexample
641etags --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
649Note that tags are not generated for scripts, so that you have to add
650a line by yourself of the form @samp{###key @var{scriptname}} if you
651want to jump to it.
652
653@item
654Tag Tcl files:
655
656@smallexample
657etags --language=none --regex='/proc[ \t]+\([^ \t]+\)/\1/' *.tcl
658@end smallexample
659
660@item
661Tag VHDL files:
662
663@smallexample
664etags --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
677for working with tags tables use the selected one. To select a tags table,
678type @kbd{M-x visit-tags-table}, which reads the tags table file name as an
679argument. The name @file{TAGS} in the default directory is used as the
680default 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
684contents until you try to use them. Setting this variable yourself is just
685as 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
687that 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
690gives you a choice: you can add the new tags table to the current list
691of tags tables, or start a new list. The tags commands use all the tags
692tables in the current list. If you start a new list, the new tags table
693is used @emph{instead} of others. If you add the new table to the
694current list, it is used @emph{as well as} the others. When the tags
695commands scan the list of tags tables, they don't always start at the
696beginning of the list; they start with the first tags table (if any)
697that describes the current file, proceed from there to the end of the
698list, and then scan from the beginning of the list until they have
699covered 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
714This 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}
716directory. The order depends on which file you are in and which tags
717table 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
725the definition of a specific tag.
726
727@table @kbd
728@item M-.@: @var{tag} @key{RET}
729Find first definition of @var{tag} (@code{find-tag}).
730@item C-u M-.
731Find next alternate definition of last tag specified.
732@item C-u - M-.
733Go back to previous tag found.
734@item C-M-. @var{pattern} @key{RET}
735Find a tag whose name matches @var{pattern} (@code{find-tag-regexp}).
736@item C-u C-M-.
737Find the next tag whose name matches the last pattern used.
738@item C-x 4 .@: @var{tag} @key{RET}
739Find 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}
742Find first definition of @var{tag}, and create a new frame to select the
743buffer (@code{find-tag-other-frame}).
744@item M-*
745Pop 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
751a specified tag. It searches through the tags table for that tag, as a
752string, and then uses the tags table info to determine the file that the
753definition is in and the approximate character position in the file of
754the definition. Then @code{find-tag} visits that file, moves point to
755the approximate character position, and searches ever-increasing
756distances away to find the tag definition.
757
758 If an empty argument is given (just type @key{RET}), the balanced
759expression 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
763will do. This is because @kbd{M-.} finds tags in the table which
764contain @var{tag} as a substring. However, it prefers an exact match
765to a substring match. To find other tags that match the same
766substring, give @code{find-tag} a numeric argument, as in @kbd{C-u
767M-.}; this does not read a tag name, but continues searching the tags
768table's text for another tag containing the same substring last used.
769If you have a real @key{META} key, @kbd{M-0 M-.}@: is an easier
770alternative 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
777variant that displays the new buffer in another window, and one that
778makes a new frame for it. The former is @kbd{C-x 4 .}, which invokes
779the command @code{find-tag-other-window}. The latter is @kbd{C-x 5 .},
780which invokes @code{find-tag-other-frame}.
781
782 To move back to places you've found tags recently, use @kbd{C-u -
783M-.}; more generally, @kbd{M-.} with a negative numeric argument. This
784command can take you to another buffer. @kbd{C-x 4 .} with a negative
785argument 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
791back to places @emph{from where} you found them. Use @kbd{M-*}, which
792invokes the command @code{pop-tag-mark}, for this. Typically you would
793find and study the definition of something with @kbd{M-.} and then
794return to where you were with @kbd{M-*}.
795
796 Both @kbd{C-u - M-.} and @kbd{M-*} allow you to retrace your steps to
797a 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
802match a specified regular expression. It is just like @kbd{M-.} except
803that 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
811selected tags table, one by one. For these commands, the tags table serves
812only to specify a sequence of files to search.
813
814@table @kbd
815@item M-x tags-search @key{RET} @var{regexp} @key{RET}
816Search for @var{regexp} through the files in the selected tags
817table.
818@item M-x tags-query-replace @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
819Perform a @code{query-replace-regexp} on each file in the selected tags table.
820@item M-,
821Restart 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
827searches for matches in all the files in the selected tags table, one
828file at a time. It displays the name of the file being searched so you
829can 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
835one 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
837by 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
842reads a regexp to search for and a string to replace with, just like
843ordinary @kbd{M-x query-replace-regexp}. It searches much like @kbd{M-x
844tags-search}, but repeatedly, processing matches according to your
845input. @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
850customizing the value of the variable @code{tags-case-fold-search}. The
851default 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
855single invocation of @kbd{M-x tags-query-replace}. But often it is
856useful to exit temporarily, which you can do with any input event that
857has no special query replace meaning. You can resume the query replace
858subsequently by typing @kbd{M-,}; this command resumes the last tags
859search 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
863definitions of tags that match your substring or regexp. The commands
864@code{tags-search} and @code{tags-query-replace} find every occurrence
865of the regexp, as ordinary search commands and replace commands do in
866the current buffer.
867
868 These commands create buffers only temporarily for the files that they
869have to search (those which are not already visited in Emacs buffers).
870Buffers in which no match is found are quickly killed; the others
871continue 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
875Emacs and have Emacs show you the matching lines one by one. This works
876much 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}
885Display a list of the tags defined in the program file @var{file}.
886@item M-x tags-apropos @key{RET} @var{regexp} @key{RET}
887Display 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
892the selected tags table, and displays a list of all the tags defined in
893that file. The ``file name'' argument is really just a string to
894compare against the file names recorded in the tags table; it is read as
895a string rather than as a file name. Therefore, completion and
896defaulting are not available, and you must enter the file name the same
897way it appears in the tags table. Do not include a directory as part of
898the file name unless the file name recorded in the tags table includes a
899directory.
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
905whose entries match @var{regexp}, and displays them. If the variable
906@code{tags-apropos-verbose} is non-@code{nil}, it displays the names
907of the tags files together with the tag names.
908
909@vindex tags-tag-face
910@vindex tags-apropos-additional-actions
911You can customize the appearance of the output with the face
912@code{tags-tag-face}. You can display additional output with @kbd{M-x
913tags-apropos} by customizing the variable
914@code{tags-apropos-additional-actions}---see its documentation for
915details.
916
917 You can also use the collection of tag names to complete a symbol
918name 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
925It's not unusual for programmers to get their signals crossed and modify
926the same program in two different directions. To recover from this
927confusion, you need to merge the two versions. Emerge makes this
928easier. See also @ref{Comparing Files}, for commands to compare
b5f1c9fa 929in 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
947To start Emerge, run one of these four commands:
948
949@table @kbd
950@item M-x emerge-files
951@findex emerge-files
952Merge two specified files.
953
954@item M-x emerge-files-with-ancestor
955@findex emerge-files-with-ancestor
956Merge two specified files, with reference to a common ancestor.
957
958@item M-x emerge-buffers
959@findex emerge-buffers
960Merge two buffers.
961
962@item M-x emerge-buffers-with-ancestor
963@findex emerge-buffers-with-ancestor
964Merge two buffers with reference to a common ancestor in a third
965buffer.
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
971comparison in three buffers: one for each input text (the @dfn{A buffer}
972and the @dfn{B buffer}), and one (the @dfn{merge buffer}) where merging
973takes place. The merge buffer shows the full merged text, not just the
974differences. Wherever the two input texts differ, you can choose which
975one of them to include in the merge buffer.
976
977 The Emerge commands that take input from existing buffers use only the
978accessible 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
982be merged were both derived, Emerge can use it to guess which
983alternative is right. Wherever one current version agrees with the
984ancestor, Emerge presumes that the other current version is a deliberate
985change which should be kept in the merged version. Use the
986@samp{with-ancestor} commands if you want to specify a common ancestor
987text. These commands read three file or buffer names---variant A,
988variant B, and the common ancestor.
989
990 After the comparison is done and the buffers are prepared, the
991interactive merging starts. You control the merging by typing special
992@dfn{merge commands} in the merge buffer. The merge buffer shows you a
993full merged text, not just differences. For each run of differences
994between the input texts, you can choose which one of them to keep, or
995edit them both together.
996
997 The merge buffer uses a special major mode, Emerge mode, with commands
998for making these choices. But you can also edit the buffer with
999ordinary Emacs commands.
1000
1001 At any given time, the attention of Emerge is focused on one
1002particular difference, called the @dfn{selected} difference. This
1003difference is marked off in the three buffers like this:
1004
1005@example
1006vvvvvvvvvvvvvvvvvvvv
1007@var{text that differs}
1008^^^^^^^^^^^^^^^^^^^^
1009@end example
1010
1011@noindent
1012Emerge numbers all the differences sequentially and the mode
1013line always shows the number of the selected difference.
1014
1015 Normally, the merge buffer starts out with the A version of the text.
1016But when the A version of a difference agrees with the common ancestor,
1017then the B version is initially preferred for that difference.
1018
1019 Emerge leaves the merged text in the merge buffer when you exit. At
1020that point, you can save it in a file with @kbd{C-x C-w}. If you give a
1021numeric argument to @code{emerge-files} or
1022@code{emerge-files-with-ancestor}, it reads the name of the output file
1023using the minibuffer. (This is the last file name those commands read.)
1024Then 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
1027exit. If you abort Emerge with @kbd{C-]}, the Emerge command does not
1028save 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
1034and Edit mode. In Fast mode, basic merge commands are single
1035characters, but ordinary Emacs commands are disabled. This is
1036convenient if you use only merge commands. In Edit mode, all merge
1037commands start with the prefix key @kbd{C-c C-c}, and the normal Emacs
1038commands are also available. This allows editing the merge buffer, but
1039slows down Emerge operations.
1040
1041 Use @kbd{e} to switch to Edit mode, and @kbd{C-c C-c f} to switch to
1042Fast mode. The mode line indicates Edit and Fast modes with @samp{E}
1043and @samp{F}.
1044
1045 Emerge has two additional submodes that affect how particular merge
1046commands work: Auto Advance mode and Skip Prefers mode.
1047
1048 If Auto Advance mode is in effect, the @kbd{a} and @kbd{b} commands
1049advance to the next difference. This lets you go through the merge
1050faster as long as you simply choose one of the alternatives from the
1051input. 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
1054skip over differences in states prefer-A and prefer-B (@pxref{State of
1055Difference}). Thus you see only differences for which neither version
1056is 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
1062clear Auto Advance mode. Use @kbd{s s}
1063(@code{emerge-skip-prefers-mode}) to set or clear Skip Prefers mode.
1064These commands turn on the mode with a positive argument, turns it off
1065with 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
1075The difference is showing the A version. The @kbd{a} command always
1076produces this state; the mode line indicates it with @samp{A}.
1077
1078@item B
1079The difference is showing the B version. The @kbd{b} command always
1080produces this state; the mode line indicates it with @samp{B}.
1081
1082@item default-A
1083@itemx default-B
1084The difference is showing the A or the B state by default, because you
1085haven'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
1087which one alternative is ``preferred'' (see below).
1088
1089When you select a difference, its state changes from default-A or
1090default-B to plain A or B. Thus, the selected difference never has
1091state default-A or default-B, and these states are never displayed in
1092the mode line.
1093
1094The command @kbd{d a} chooses default-A as the default state, and @kbd{d
1095b} chooses default-B. This chosen default applies to all differences
1096which you haven't ever selected and for which no alternative is preferred.
1097If you are moving through the merge sequentially, the differences you
1098haven't selected are those following the selected one. Thus, while
1099moving sequentially, you can effectively make the A version the default
1100for some sections of the merge buffer and the B version the default for
1101others by using @kbd{d a} and @kbd{d b} between sections.
1102
1103@item prefer-A
1104@itemx prefer-B
1105The difference is showing the A or B state because it is
1106@dfn{preferred}. This means that you haven't made an explicit choice,
1107but one alternative seems likely to be right because the other
1108alternative agrees with the common ancestor. Thus, where the A buffer
1109agrees with the common ancestor, the B version is preferred, because
1110chances are it is the one that was actually changed.
1111
1112These two states are displayed in the mode line as @samp{A*} and @samp{B*}.
1113
1114@item combined
1115The difference is showing a combination of the A and B states, as a
1116result of the @kbd{x c} or @kbd{x C} commands.
1117
1118Once a difference is in this state, the @kbd{a} and @kbd{b} commands
1119don't do anything to it unless you give them a numeric argument.
1120
1121The 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
1128with @kbd{C-c C-c}:
1129
1130@table @kbd
1131@item p
1132Select the previous difference.
1133
1134@item n
1135Select the next difference.
1136
1137@item a
1138Choose the A version of this difference.
1139
1140@item b
1141Choose the B version of this difference.
1142
1143@item C-u @var{n} j
1144Select difference number @var{n}.
1145
1146@item .
1147Select the difference containing point. You can use this command in the
1148merge buffer or in the A or B buffer.
1149
1150@item q
1151Quit---finish the merge.
1152
1153@item C-]
1154Abort---exit merging and do not save the output.
1155
1156@item f
1157Go into Fast mode. (In Edit mode, this is actually @kbd{C-c C-c f}.)
1158
1159@item e
1160Go into Edit mode.
1161
1162@item l
1163Recenter (like @kbd{C-l}) all three windows.
1164
1165@item -
1166Specify part of a prefix numeric argument.
1167
1168@item @var{digit}
1169Also specify part of a prefix numeric argument.
1170
1171@item d a
1172Choose the A version as the default from here down in
1173the merge buffer.
1174
1175@item d b
1176Choose the B version as the default from here down in
1177the merge buffer.
1178
1179@item c a
1180Copy the A version of this difference into the kill ring.
1181
1182@item c b
1183Copy the B version of this difference into the kill ring.
1184
1185@item i a
1186Insert the A version of this difference at point.
1187
1188@item i b
1189Insert the B version of this difference at point.
1190
1191@item m
1192Put point and mark around the difference.
1193
1194@item ^
1195Scroll all three windows down (like @kbd{M-v}).
1196
1197@item v
1198Scroll all three windows up (like @kbd{C-v}).
1199
1200@item <
1201Scroll all three windows left (like @kbd{C-x <}).
1202
1203@item >
1204Scroll all three windows right (like @kbd{C-x >}).
1205
1206@item |
1207Reset horizontal scroll on all three windows.
1208
1209@item x 1
1210Shrink the merge window to one line. (Use @kbd{C-u l} to restore it
1211to full size.)
1212
1213@item x c
1214Combine the two versions of this difference (@pxref{Combining in
1215Emerge}).
1216
1217@item x f
1218Show the names of the files/buffers Emerge is operating on, in a Help
1219window. (Use @kbd{C-u l} to restore windows.)
1220
1221@item x j
1222Join this difference with the following one.
1223(@kbd{C-u x j} joins this difference with the previous one.)
1224
1225@item x s
1226Split this difference into two differences. Before you use this
1227command, position point in each of the three buffers at the place where
1228you want to split the difference.
1229
1230@item x t
1231Trim identical lines off the top and bottom of the difference.
1232Such lines occur when the A and B versions are
1233identical 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
1240the results into the output file if you specified one. It restores the
1241A and B buffers to their proper contents, or kills them if they were
1242created by Emerge and you haven't changed them. It also disables the
1243Emerge commands in the merge buffer, since executing them later could
1244damage the contents of the various buffers.
1245
1246 @kbd{C-]} aborts the merge. This means exiting without writing the
1247output file. If you didn't specify an output file, then there is no
1248real difference between aborting and finishing the merge.
1249
1250 If the Emerge command was called from another Lisp program, then its
1251return value is @code{t} for successful completion, or @code{nil} if you
1252abort.
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
1258difference. To do this, use @kbd{x c}, which edits the merge buffer
1259like 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
1273While this example shows C preprocessor conditionals delimiting the two
1274alternative versions, you can specify the strings to use by setting
1275the variable @code{emerge-combine-versions-template} to a string of your
1276choice. 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
1278produces 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.
1290Emerge modifies them temporarily, but ultimately puts them back the way
1291they were.
1292
1293 You can have any number of merges going at once---just don't use any one
1294buffer as input to more than one merge at once, since the temporary
1295changes 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
1298files fully. Emacs can't do anything else until @code{diff} finishes.
1299Perhaps in the future someone will change Emerge to do the comparison in
1300the background when the input files are large---then you could keep on
1301doing other things with Emacs until Emerge is ready to accept
1302commands.
1303
1304@vindex emerge-startup-hook
1305 After setting up the merge, Emerge runs the hook
1306@code{emerge-startup-hook} (@pxref{Hooks}).