annotate man/xemacs/programs.texi @ 5797:a1808d52a34a

If the position of a window's cached point is deleted, use buffer point instead src/ChangeLog addition: 2014-06-17 Aidan Kehoe <kehoea@parhasard.net> * extents.h: * window.c: * window.c (unshow_buffer): * window.c (Fset_window_buffer): Use extents, rather than markers, for the window buffer point cache, so that when the text containing that window buffer point is deleted, the window display code uses the buffer's actual point instead of the position that the marker had been moved to. Fixes Michael Heinrich's problem of http://mid.gmane.org/6zr42uxtf5.fsf@elektra.science-computing.de , introduced by Ben's patch of https://bitbucket.org/xemacs/xemacs/commits/047d37eb70d70f43803 .
author Aidan Kehoe <kehoea@parhasard.net>
date Tue, 17 Jun 2014 20:55:45 +0100
parents 9fae6227ede5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 @node Programs, Running, Text, Top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 @chapter Editing Programs
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
4 @cindex Programming Languages
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 @cindex Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
7 XEmacs provides specialized support for editing source files for many
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
8 different programming languages. For example it is possible to
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 @item
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
12 Follow the usual indentation conventions of the language
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
13 (@pxref{Grinding}).
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
14 @item
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 Move over or kill balanced expressions or @dfn{sexps} (@pxref{Lists}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 Move over or mark top-level balanced expressions (@dfn{defuns}, in Lisp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 functions, in C).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Show how parentheses balance (@pxref{Matching}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 Insert, kill, or align comments (@pxref{Comments}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 @item
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
24 Find functions and symbols in program by name (@pxref{Tags}).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 The commands available for words, sentences, and paragraphs are useful in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 editing code even though their canonical application is for editing human
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 language text. Most symbols contain words (@pxref{Words}); sentences can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 be found in strings and comments (@pxref{Sentences}). Paragraphs per se
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 are not present in code, but the paragraph commands are useful anyway,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 because Lisp mode and C mode define paragraphs to begin and end at blank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 lines (@pxref{Paragraphs}). Judicious use of blank lines to make the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 program clearer also provides interesting chunks of text for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 paragraph commands to work on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 The selective display feature is useful for looking at the overall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 structure of a function (@pxref{Selective Display}). This feature causes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 only the lines that are indented less than a specified amount to appear
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 on the screen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 * Program Modes:: Major modes for editing programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 * Lists:: Expressions with balanced parentheses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 There are editing commands to operate on them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 * Defuns:: Each program is made up of separate functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 There are editing commands to operate on them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 * Grinding:: Adjusting indentation to show the nesting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 * Matching:: Insertion of a close-delimiter flashes matching open.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
50 * Comments:: Inserting, filling and aligning comments.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 * Balanced Editing:: Inserting two matching parentheses at once, etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 * Lisp Completion:: Completion on symbol names in Lisp code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 * Documentation:: Getting documentation of functions you plan to call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 * Change Log:: Maintaining a change history for your program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 * Tags:: Go direct to any function in your program in one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 command. Tags remembers which file it is in.
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
57 * CC Mode:: Modes for C, C++, Java and similar languages
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 * Fortran:: Fortran mode and its special features.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 * Asm Mode:: Asm mode and its special features.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 @node Program Modes, Lists, Programs, Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 @section Major Modes for Programming Languages
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 @cindex Lisp mode
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
66 Emacs has several major modes (@pxref{Major Modes}) to support
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
67 programming languages. These major modes will typically understand
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
68 language syntax, provide automatic indentation features, syntax based
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
69 highlighting of text, and will often provide interfaces to the
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
70 programming environment to assist in compiling, executing and debugging
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
71 programs.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
72
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
73 A language mode exist when someone decides to take the trouble to
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
74 write it. At this time many widely used programming languages are
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
75 supported by XEmacs. Examples include Ada, Awk, C, C++, CORBA (IDL),
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
76 Fortran, Java, Lisp, Modula 2, Objective-C, Perl, Pike, Prolog, Python,
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
77 Ruby, Scheme, Simula, SQL, Tcl, Unix Shell scripts, and VHDL. Some of
4488
6b0000935adc Spelling fixes.
"Ville Skyttä <scop@xemacs.org>"
parents: 2522
diff changeset
78 these language have separate manuals, and some times more than one mode
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
79 may be available for a language. For example, there are several
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
80 variants of Lisp mode, which differ in the way they interface to Lisp
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
81 execution. @xref{Lisp Modes}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
83 Major modes for programming language support are distributed in
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
84 optional XEmacs packages (@pxref{Packages}) that must be installed
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
85 before use. A notable exception to this rule is that a Lisp Mode is
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
86 integral to XEmacs. The Programming Mode Package (@file{prog-modes})
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
87 contains many such modes. Some languages are supported by packages of
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
88 their own; prominent examples of such packages include @file{cc-mode}
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
89 for C, C++, Java, Objective C etc.@:, @file{python-modes} for Python,
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
90 and @file{scheme} for Scheme.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
92 For a language named @var{lang} the major mode for the language will
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
93 typically be named @code{@var{lang}-mode}. For example, the mode for C
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
94 is called @code{c-mode}, that for Bourne shell scripts is called
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
95 @code{sh-mode} and so on. These modes will invoke the functions listed
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
96 in the corresponding hook variables as a last step. @xref{Mode Hooks}.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
97
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
98 A mode can be invoked by typing @kbd{M-x @var{lang}-mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
99 @key{RET}}. However this step is not normally required. If the package
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
100 for a language mode is installed XEmacs usually knows when to
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
101 automatically invoke the mode. This is normally done based on examining
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
102 the file name to determine the language. @ref{Choosing Modes}.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
103
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
104 Each of the programming language modes defines the @key{TAB} key to
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
105 run an indentation function that knows the indentation conventions of
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
106 that language and updates the current line's indentation accordingly.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
107 @key{LFD} is normally defined to do @key{RET} followed by @key{TAB};
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
108 thus it, too, indents in a mode-specific fashion.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 @kindex DEL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 @findex backward-delete-char-untabify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 In most programming languages, indentation is likely to vary from line to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 line. So the major modes for those languages rebind @key{DEL} to treat a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 tab as if it were the equivalent number of spaces (using the command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 @code{backward-delete-char-untabify}). This makes it possible to rub out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 indentation one column at a time without worrying whether it is made up of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 spaces or tabs. In these modes, use @kbd{C-b C-d} to delete a tab
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 character before point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 Programming language modes define paragraphs to be separated only by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 blank lines, so that the paragraph commands remain useful. Auto Fill mode,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 if enabled in a programming language major mode, indents the new lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 which it creates.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 @node Lists, Defuns, Program Modes, Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 @section Lists and Sexps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 @cindex Control-Meta
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 By convention, Emacs keys for dealing with balanced expressions are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 usually @kbd{Control-Meta-} characters. They tend to be analogous in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 function to their @kbd{Control-} and @kbd{Meta-} equivalents. These commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 are usually thought of as pertaining to expressions in programming
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 languages, but can be useful with any language in which some sort of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 parentheses exist (including English).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 @cindex list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 @cindex sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 @cindex expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 The commands fall into two classes. Some commands deal only with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 @dfn{lists} (parenthetical groupings). They see nothing except
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 parentheses, brackets, braces (depending on what must balance in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 language you are working with), and escape characters that might be used
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 to quote those.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 The other commands deal with expressions or @dfn{sexps}. The word `sexp'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 is derived from @dfn{s-expression}, the term for a symbolic expression in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 Lisp. In Emacs, the notion of `sexp' is not limited to Lisp. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 refers to an expression in the language your program is written in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 Each programming language has its own major mode, which customizes the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 syntax tables so that expressions in that language count as sexps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 Sexps typically include symbols, numbers, and string constants, as well
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 as anything contained in parentheses, brackets, or braces.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 In languages that use prefix and infix operators, such as C, it is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 possible for all expressions to be sexps. For example, C mode does not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 recognize @samp{foo + bar} as an sexp, even though it @i{is} a C expression;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 it recognizes @samp{foo} as one sexp and @samp{bar} as another, with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 @samp{+} as punctuation between them. This is a fundamental ambiguity:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 both @samp{foo + bar} and @samp{foo} are legitimate choices for the sexp to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 move over if point is at the @samp{f}. Note that @samp{(foo + bar)} is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 sexp in C mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 Some languages have obscure forms of syntax for expressions that nobody
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 has bothered to make Emacs understand properly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 @c doublewidecommands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 @item C-M-f
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 Move forward over an sexp (@code{forward-sexp}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 @item C-M-b
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 Move backward over an sexp (@code{backward-sexp}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 @item C-M-k
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 Kill sexp forward (@code{kill-sexp}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 @item C-M-u
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 Move up and backward in list structure (@code{backward-up-list}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 @item C-M-d
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 Move down and forward in list structure (@code{down-list}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 @item C-M-n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 Move forward over a list (@code{forward-list}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 @item C-M-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 Move backward over a list (@code{backward-list}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 @item C-M-t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 Transpose expressions (@code{transpose-sexps}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 @item C-M-@@
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 Put mark after following expression (@code{mark-sexp}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 @kindex C-M-f
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 @kindex C-M-b
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 @findex forward-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 @findex backward-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 To move forward over an sexp, use @kbd{C-M-f} (@code{forward-sexp}). If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 the first significant character after point is an opening delimiter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 (@samp{(} in Lisp; @samp{(}, @samp{[}, or @samp{@{} in C), @kbd{C-M-f}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 moves past the matching closing delimiter. If the character begins a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 symbol, string, or number, @kbd{C-M-f} moves over that. If the character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 after point is a closing delimiter, @kbd{C-M-f} just moves past it. (This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 last is not really moving across an sexp; it is an exception which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 included in the definition of @kbd{C-M-f} because it is as useful a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 behavior as anyone can think of for that situation.)@refill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 The command @kbd{C-M-b} (@code{backward-sexp}) moves backward over a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 sexp. The detailed rules are like those above for @kbd{C-M-f}, but with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 directions reversed. If there are any prefix characters (single quote,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 back quote, and comma, in Lisp) preceding the sexp, @kbd{C-M-b} moves back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 over them as well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 specified number of times; with a negative argument, it moves in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 opposite direction.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 @kindex C-M-k
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 @findex kill-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 Killing an sexp at a time can be done with @kbd{C-M-k} (@code{kill-sexp}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 @kbd{C-M-k} kills the characters that @kbd{C-M-f} would move over.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 @kindex C-M-n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 @kindex C-M-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 @findex forward-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 @findex backward-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 The @dfn{list commands}, @kbd{C-M-n} (@code{forward-list}) and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 @kbd{C-M-p} (@code{backward-list}), move over lists like the sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 commands but skip over any number of other kinds of sexps (symbols,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 strings, etc). In some situations, these commands are useful because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 they usually ignore comments, since the comments usually do not contain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 any lists.@refill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 @kindex C-M-u
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 @kindex C-M-d
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 @findex backward-up-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 @findex down-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 @kbd{C-M-n} and @kbd{C-M-p} stay at the same level in parentheses, when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 that is possible. To move @i{up} one (or @var{n}) levels, use @kbd{C-M-u}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (@code{backward-up-list}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 @kbd{C-M-u} moves backward up past one unmatched opening delimiter. A
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 positive argument serves as a repeat count; a negative argument reverses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 direction of motion and also requests repetition, so it moves forward and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 up one or more levels.@refill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 To move @i{down} in list structure, use @kbd{C-M-d}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (@code{down-list}). In Lisp mode, where @samp{(} is the only opening
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 delimiter, this is nearly the same as searching for a @samp{(}. An
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 argument specifies the number of levels of parentheses to go down.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 @cindex transposition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 @kindex C-M-t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 @findex transpose-sexps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 @kbd{C-M-t} (@code{transpose-sexps}) drags the previous sexp across
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 the next one. An argument serves as a repeat count, and a negative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 argument drags backwards (thus canceling out the effect of @kbd{C-M-t} with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 a positive argument). An argument of zero, rather than doing nothing,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 transposes the sexps ending after point and the mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 @kindex C-M-@@
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 @findex mark-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 To make the region be the next sexp in the buffer, use @kbd{C-M-@@}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (@code{mark-sexp}) which sets the mark at the same place that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 @kbd{C-M-f} would move to. @kbd{C-M-@@} takes arguments like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 @kbd{C-M-f}. In particular, a negative argument is useful for putting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 the mark at the beginning of the previous sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 The list and sexp commands' understanding of syntax is completely
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 controlled by the syntax table. Any character can, for example, be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 declared to be an opening delimiter and act like an open parenthesis.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 @xref{Syntax}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 @node Defuns, Grinding, Lists, Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 @section Defuns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 @cindex defuns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 In Emacs, a parenthetical grouping at the top level in the buffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 called a @dfn{defun}. The name derives from the fact that most
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4488
diff changeset
274 top-level lists in Lisp are instances of the special operator
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 @code{defun}, but Emacs calls any top-level parenthetical
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 grouping counts a defun regardless of its contents or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 the programming language. For example, in C, the body of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 function definition is a defun.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 @c doublewidecommands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 @item C-M-a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 Move to beginning of current or preceding defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (@code{beginning-of-defun}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 @item C-M-e
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 Move to end of current or following defun (@code{end-of-defun}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 @item C-M-h
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 Put region around whole current or following defun (@code{mark-defun}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 @kindex C-M-a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 @kindex C-M-e
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 @kindex C-M-h
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 @findex beginning-of-defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 @findex end-of-defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 @findex mark-defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 The commands to move to the beginning and end of the current defun are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 @kbd{C-M-a} (@code{beginning-of-defun}) and @kbd{C-M-e} (@code{end-of-defun}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299
5707
5fd1b9a95531 Improve description of `mark-defun'.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4905
diff changeset
300 To operate on the current defun, use @kbd{C-M-h} (@code{mark-defun})
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 which puts point at the beginning and the mark at the end of the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 or next defun. This is the easiest way to prepare for moving the defun
5707
5fd1b9a95531 Improve description of `mark-defun'.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4905
diff changeset
303 to a different place. In Lisp modes, a ``defun'' is merely any sexp
5fd1b9a95531 Improve description of `mark-defun'.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4905
diff changeset
304 starting in column 1. In other modes, a defun is a syntactic unit
5fd1b9a95531 Improve description of `mark-defun'.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4905
diff changeset
305 defining an entity, and these modes often bind @kbd{C-M-h} to a
5fd1b9a95531 Improve description of `mark-defun'.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4905
diff changeset
306 different function. For example, in CC Mode's C mode, @kbd{C-M-h} runs
5fd1b9a95531 Improve description of `mark-defun'.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4905
diff changeset
307 the function @code{c-mark-function}, which is almost the same as
5fd1b9a95531 Improve description of `mark-defun'.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4905
diff changeset
308 @code{mark-defun}, but which backs up over the argument declarations,
5fd1b9a95531 Improve description of `mark-defun'.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4905
diff changeset
309 function name, and returned data type so that the entire C function is
5fd1b9a95531 Improve description of `mark-defun'.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4905
diff changeset
310 inside the region. It also knows about struct definitions, macro
5fd1b9a95531 Improve description of `mark-defun'.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4905
diff changeset
311 definitions, and many other constructs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 @findex compile-defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 To compile and evaluate the current defun, use @kbd{M-x compile-defun}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 This function prints the results in the minibuffer. If you include an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 argument, it inserts the value in the current buffer after the defun.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 Emacs assumes that any open-parenthesis found in the leftmost column is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 the start of a defun. Therefore, @i{never put an open-parenthesis at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 left margin in a Lisp file unless it is the start of a top level list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 Never put an open-brace or other opening delimiter at the beginning of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 line of C code unless it starts the body of a function.} The most likely
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 problem case is when you want an opening delimiter at the start of a line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 inside a string. To avoid trouble, put an escape character (@samp{\} in C
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 and Emacs Lisp, @samp{/} in some other Lisp dialects) before the opening
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 delimiter. It will not affect the contents of the string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 The original Emacs found defuns by moving upward a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 level of parentheses until there were no more levels to go up. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 required scanning back to the beginning of the buffer for every
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 function. To speed this up, Emacs was changed to assume
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 that any @samp{(} (or other character assigned the syntactic class of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 opening-delimiter) at the left margin is the start of a defun. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 heuristic is nearly always right; however, it mandates the convention
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 described above.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 @node Grinding, Matching, Defuns, Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 @section Indentation for Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 @cindex indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 @cindex grinding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 The best way to keep a program properly indented (``ground'') is to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 use Emacs to re-indent it as you change the program. Emacs has commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 to indent properly either a single line, a specified number of lines, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 all of the lines inside a single parenthetical grouping.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 * Basic Indent::
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 * Multi-line Indent:: Commands to reindent many lines at once.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 * Lisp Indent:: Specifying how each Lisp function should be indented.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 @node Basic Indent, Multi-line Indent, Grinding, Grinding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 @subsection Basic Program Indentation Commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 @c WideCommands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 @item @key{TAB}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 Adjust indentation of current line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 @item @key{LFD}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 Equivalent to @key{RET} followed by @key{TAB} (@code{newline-and-indent}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 @kindex TAB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 @findex c-indent-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 @findex lisp-indent-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 The basic indentation command is @key{TAB}, which gives the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 line the correct indentation as determined from the previous lines. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 function that @key{TAB} runs depends on the major mode; it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 @code{lisp-indent-line} in Lisp mode, @code{c-indent-line} in C mode,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 etc. These functions understand different syntaxes for different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 languages, but they all do about the same thing. @key{TAB} in any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 programming language major mode inserts or deletes whitespace at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 beginning of the current line, independent of where point is in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 line. If point is inside the whitespace at the beginning of the line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 @key{TAB} leaves it at the end of that whitespace; otherwise, @key{TAB}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 leaves point fixed with respect to the characters around it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 Use @kbd{C-q @key{TAB}} to insert a tab at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 @kindex LFD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 @findex newline-and-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 When entering a large amount of new code, use @key{LFD}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (@code{newline-and-indent}), which is equivalent to a @key{RET} followed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 by a @key{TAB}. @key{LFD} creates a blank line, then gives it the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 appropriate indentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 @key{TAB} indents the second and following lines of the body of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 parenthetical grouping each under the preceding one; therefore, if you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 alter one line's indentation to be nonstandard, the lines below tend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 to follow it. This is the right behavior in cases where the standard
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 result of @key{TAB} does not look good.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 Remember that Emacs assumes that an open-parenthesis, open-brace, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 other opening delimiter at the left margin (including the indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 routines) is the start of a function. You should therefore never have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 an opening delimiter in column zero that is not the beginning of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 function, not even inside a string. This restriction is vital for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 making the indentation commands fast. @xref{Defuns}, for more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 information on this behavior.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 @node Multi-line Indent, Lisp Indent, Basic Indent, Grinding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 @subsection Indenting Several Lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 Several commands are available to re-indent several lines of code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 which have been altered or moved to a different level in a list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 structure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 @item C-M-q
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 Re-indent all the lines within one list (@code{indent-sexp}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 @item C-u @key{TAB}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 Shift an entire list rigidly sideways so that its first line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 is properly indented.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 @item C-M-\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 Re-indent all lines in the region (@code{indent-region}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 @kindex C-M-q
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 @findex indent-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 @findex indent-c-exp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 To re-indent the contents of a single list, position point before the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 beginning of it and type @kbd{C-M-q}. This key is bound to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 @code{indent-sexp} in Lisp mode, @code{indent-c-exp} in C mode, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 bound to other suitable functions in other modes. The indentation of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 the line the sexp starts on is not changed; therefore, only the relative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 indentation within the list, and not its position, is changed. To
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 correct the position as well, type a @key{TAB} before @kbd{C-M-q}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 @kindex C-u TAB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 If the relative indentation within a list is correct but the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 indentation of its beginning is not, go to the line on which the list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 begins and type @kbd{C-u @key{TAB}}. When you give @key{TAB} a numeric
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 argument, it moves all the lines in the group, starting on the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 line, sideways the same amount that the current line moves. The command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 does not move lines that start inside strings, or C
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 preprocessor lines when in C mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 @kindex C-M-\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 @findex indent-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 Another way to specify a range to be re-indented is with point and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 mark. The command @kbd{C-M-\} (@code{indent-region}) applies @key{TAB}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 to every line whose first character is between point and mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
446 @node Lisp Indent, , Multi-line Indent, Grinding
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 @subsection Customizing Lisp Indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 @cindex customization
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 The indentation pattern for a Lisp expression can depend on the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 called by the expression. For each Lisp function, you can choose among
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 several predefined patterns of indentation, or define an arbitrary one with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 a Lisp program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 The standard pattern of indentation is as follows: the second line of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 expression is indented under the first argument, if that is on the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 line as the beginning of the expression; otherwise, the second line is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 indented underneath the function name. Each following line is indented
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 under the previous line whose nesting depth is the same.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 @vindex lisp-indent-offset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 If the variable @code{lisp-indent-offset} is non-@code{nil}, it overrides
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 the usual indentation pattern for the second line of an expression, so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 such lines are always indented @code{lisp-indent-offset} more columns than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 the containing list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 @vindex lisp-body-indention
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 Certain functions override the standard pattern. Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 whose names start with @code{def} always indent the second line by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 @code{lisp-body-indention} extra columns beyond the open-parenthesis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 starting the expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 Individual functions can override the standard pattern in various
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 ways, according to the @code{lisp-indent-function} property of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 function name. (Note: @code{lisp-indent-function} was formerly called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 @code{lisp-indent-hook}). There are four possibilities for this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 property:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 @table @asis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 @item @code{nil}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 This is the same as no property; the standard indentation pattern is used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 @item @code{defun}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 The pattern used for function names that start with @code{def} is used for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 this function also.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 @item a number, @var{number}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 The first @var{number} arguments of the function are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 @dfn{distinguished} arguments; the rest are considered the @dfn{body}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 of the expression. A line in the expression is indented according to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 whether the first argument on it is distinguished or not. If the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 argument is part of the body, the line is indented @code{lisp-body-indent}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 more columns than the open-parenthesis starting the containing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 expression. If the argument is distinguished and is either the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 or second argument, it is indented @i{twice} that many extra columns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 If the argument is distinguished and not the first or second argument,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 the standard pattern is followed for that line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 @item a symbol, @var{symbol}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 @var{symbol} should be a function name; that function is called to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 calculate the indentation of a line within this expression. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 function receives two arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 @table @asis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 @item @var{state}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 The value returned by @code{parse-partial-sexp} (a Lisp primitive for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 indentation and nesting computation) when it parses up to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 beginning of this line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 @item @var{pos}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 The position at which the line being indented begins.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 It should return either a number, which is the number of columns of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 indentation for that line, or a list whose first element is such a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 number. The difference between returning a number and returning a list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 is that a number says that all following lines at the same nesting level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 should be indented just like this one; a list says that following lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 might call for different indentations. This makes a difference when the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 indentation is computed by @kbd{C-M-q}; if the value is a number,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 @kbd{C-M-q} need not recalculate indentation for the following lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 until the end of the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 @node Matching, Comments, Grinding, Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 @section Automatic Display of Matching Parentheses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 @cindex matching parentheses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 @cindex parentheses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 The Emacs parenthesis-matching feature shows you automatically how
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 parentheses match in the text. Whenever a self-inserting character that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 is a closing delimiter is typed, the cursor moves momentarily to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 location of the matching opening delimiter, provided that is visible on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 the screen. If it is not on the screen, some text starting with that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 opening delimiter is displayed in the echo area. Either way, you see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 the grouping you are closing off.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 In Lisp, automatic matching applies only to parentheses. In C, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 also applies to braces and brackets. Emacs knows which characters to regard
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 as matching delimiters based on the syntax table set by the major
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 mode. @xref{Syntax}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 If the opening delimiter and closing delimiter are mismatched---as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 in @samp{[x)}---the echo area displays a warning message. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 correct matches are specified in the syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 @vindex blink-matching-paren
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 @vindex blink-matching-paren-distance
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 Two variables control parenthesis matching displays.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 @code{blink-matching-paren} turns the feature on or off. The default is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 @code{t} (match display is on); @code{nil} turns it off.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 @code{blink-matching-paren-distance} specifies how many characters back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 Emacs searches to find a matching opening delimiter. If the match is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 not found in the specified region, scanning stops, and nothing is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 displayed. This prevents wasting lots of time scanning when there is no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 match. The default is 4000.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 @node Comments, Balanced Editing, Matching, Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 @section Manipulating Comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 @cindex comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 @kindex M-;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 @cindex indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 @findex indent-for-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 The comment commands insert, kill and align comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 @c WideCommands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 @item M-;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 Insert or align comment (@code{indent-for-comment}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 @item C-x ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 Set comment column (@code{set-comment-column}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 @item C-u - C-x ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 Kill comment on current line (@code{kill-comment}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 @item M-@key{LFD}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 Like @key{RET} followed by inserting and aligning a comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 (@code{indent-new-comment-line}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 The command that creates a comment is @kbd{Meta-;}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 (@code{indent-for-comment}). If there is no comment already on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 line, a new comment is created and aligned at a specific column called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 the @dfn{comment column}. Emacs creates the comment by inserting the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 string at the value of @code{comment-start}; see below. Point is left
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 after that string. If the text of the line extends past the comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 column, indentation is done to a suitable boundary (usually, at least
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 one space is inserted). If the major mode has specified a string to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 terminate comments, that string is inserted after point, to keep the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 syntax valid.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 You can also use @kbd{Meta-;} to align an existing comment. If a line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 already contains the string that starts comments, @kbd{M-;} just moves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 point after it and re-indents it to the conventional place. Exception:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 comments starting in column 0 are not moved.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 Some major modes have special rules for indenting certain kinds of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 comments in certain contexts. For example, in Lisp code, comments which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 start with two semicolons are indented as if they were lines of code,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 instead of at the comment column. Comments which start with three
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 semicolons are supposed to start at the left margin. Emacs understands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 these conventions by indenting a double-semicolon comment using @key{TAB}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 and by not changing the indentation of a triple-semicolon comment at all.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 ;; This function is just an example.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 ;;; Here either two or three semicolons are appropriate.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 (defun foo (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 ;;; And now, the first part of the function:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 ;; The following line adds one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 (1+ x)) ; This line adds one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 In C code, a comment preceded on its line by nothing but whitespace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 is indented like a line of code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 Even when an existing comment is properly aligned, @kbd{M-;} is still
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 useful for moving directly to the start of the comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 @kindex C-u - C-x ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 @findex kill-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 @kbd{C-u - C-x ;} (@code{kill-comment}) kills the comment on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 current line, if there is one. The indentation before the start of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 comment is killed as well. If there does not appear to be a comment in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 the line, nothing happens. To reinsert the comment on another line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 move to the end of that line, type first @kbd{C-y}, and then @kbd{M-;}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 to realign the comment. Note that @kbd{C-u - C-x ;} is not a distinct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 key; it is @kbd{C-x ;} (@code{set-comment-column}) with a negative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 argument. That command is programmed to call @code{kill-comment} when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 called with a negative argument. However, @code{kill-comment} is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 valid command which you could bind directly to a key if you wanted to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 @subsection Multiple Lines of Comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 @kindex M-LFD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 @cindex blank lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 @cindex Auto Fill mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 @findex indent-new-comment-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 If you are typing a comment and want to continue it on another line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 use the command @kbd{Meta-@key{LFD}} (@code{indent-new-comment-line}),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 which terminates the comment you are typing, creates a new blank line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 afterward, and begins a new comment indented under the old one. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 Auto Fill mode is on and you go past the fill column while typing, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 comment is continued in just this fashion. If point is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 not at the end of the line when you type @kbd{M-@key{LFD}}, the text on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 the rest of the line becomes part of the new comment line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 @subsection Options Controlling Comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 @vindex comment-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 @kindex C-x ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 @findex set-comment-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 The comment column is stored in the variable @code{comment-column}. You
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 can explicitly set it to a number. Alternatively, the command @kbd{C-x ;}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 (@code{set-comment-column}) sets the comment column to the column point is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 at. @kbd{C-u C-x ;} sets the comment column to match the last comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 before point in the buffer, and then calls @kbd{Meta-;} to align the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 current line's comment under the previous one. Note that @kbd{C-u - C-x ;}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 runs the function @code{kill-comment} as described above.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 @code{comment-column} is a per-buffer variable; altering the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 affects only the current buffer. You can also change the default value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 @xref{Locals}. Many major modes initialize this variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 for the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 @vindex comment-start-skip
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 The comment commands recognize comments based on the regular expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 that is the value of the variable @code{comment-start-skip}. This regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 should not match the null string. It may match more than the comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 starting delimiter in the strictest sense of the word; for example, in C
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 mode the value of the variable is @code{@t{"/\\*+ *"}}, which matches extra
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 stars and spaces after the @samp{/*} itself. (Note that @samp{\\} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 needed in Lisp syntax to include a @samp{\} in the string, which is needed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 to deny the first star its special meaning in regexp syntax. @xref{Regexps}.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 @vindex comment-start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 @vindex comment-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 When a comment command makes a new comment, it inserts the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 @code{comment-start} to begin it. The value of @code{comment-end} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 inserted after point and will follow the text you will insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 into the comment. In C mode, @code{comment-start} has the value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 @w{@code{"/* "}} and @code{comment-end} has the value @w{@code{" */"}}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 @vindex comment-multi-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 @code{comment-multi-line} controls how @kbd{M-@key{LFD}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 (@code{indent-new-comment-line}) behaves when used inside a comment. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 @code{comment-multi-line} is @code{nil}, as it normally is, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 @kbd{M-@key{LFD}} terminates the comment on the starting line and starts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 a new comment on the new following line. If @code{comment-multi-line}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 is not @code{nil}, then @kbd{M-@key{LFD}} sets up the new following line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 as part of the same comment that was found on the starting line. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 is done by not inserting a terminator on the old line and not inserting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 a starter on the new line. In languages where multi-line comments are legal,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 the value you choose for this variable is a matter of taste.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 @vindex comment-indent-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 The variable @code{comment-indent-hook} should contain a function that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 is called to compute the indentation for a newly inserted comment or for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 aligning an existing comment. Major modes set this variable differently.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 The function is called with no arguments, but with point at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 beginning of the comment, or at the end of a line if a new comment is to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 be inserted. The function should return the column in which the comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 ought to start. For example, in Lisp mode, the indent hook function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 bases its decision on the number of semicolons that begin an existing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 comment and on the code in the preceding lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 @node Balanced Editing, Lisp Completion, Comments, Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 @section Editing Without Unbalanced Parentheses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 @item M-(
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 Put parentheses around next sexp(s) (@code{insert-parentheses}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 @item M-)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 Move past next close parenthesis and re-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 (@code{move-over-close-and-reindent}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 @kindex M-(
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 @kindex M-)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 @findex insert-parentheses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 @findex move-over-close-and-reindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 The commands @kbd{M-(} (@code{insert-parentheses}) and @kbd{M-)}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 (@code{move-over-close-and-reindent}) are designed to facilitate a style of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 editing which keeps parentheses balanced at all times. @kbd{M-(} inserts a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 pair of parentheses, either together as in @samp{()}, or, if given an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 argument, around the next several sexps, and leaves point after the open
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 parenthesis. Instead of typing @kbd{( F O O )}, you can type @kbd{M-( F O
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 O}, which has the same effect except for leaving the cursor before the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 close parenthesis. You can then type @kbd{M-)}, which moves past the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 close parenthesis, deletes any indentation preceding it (in this example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 there is none), and indents with @key{LFD} after it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 @node Lisp Completion, Documentation, Balanced Editing, Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 @section Completion for Lisp Symbols
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 @cindex completion (symbol names)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 Completion usually happens in the minibuffer. An exception is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 completion for Lisp symbol names, which is available in all buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 @kindex M-TAB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 @findex lisp-complete-symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 The command @kbd{M-@key{TAB}} (@code{lisp-complete-symbol}) takes the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 partial Lisp symbol before point to be an abbreviation, and compares it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 against all non-trivial Lisp symbols currently known to Emacs. Any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 additional characters that they all have in common are inserted at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 Non-trivial symbols are those that have function definitions, values, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 If there is an open-parenthesis immediately before the beginning of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 the partial symbol, only symbols with function definitions are considered
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 as completions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 If the partial name in the buffer has more than one possible completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 and they have no additional characters in common, a list of all possible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 completions is displayed in another window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 @node Documentation, Change Log, Lisp Completion, Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 @section Documentation Commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 @kindex C-h f
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 @findex describe-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 @kindex C-h v
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 @findex describe-variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 As you edit Lisp code to be run in Emacs, you can use the commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 @kbd{C-h f} (@code{describe-function}) and @kbd{C-h v}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 (@code{describe-variable}) to print documentation of functions and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 variables you want to call. These commands use the minibuffer to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 read the name of a function or variable to document, and display the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 documentation in a window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 For extra convenience, these commands provide default arguments based on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 the code in the neighborhood of point. @kbd{C-h f} sets the default to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 function called in the innermost list containing point. @kbd{C-h v} uses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 the symbol name around or adjacent to point as its default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 @findex manual-entry
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 The @kbd{M-x manual-entry} command gives you access to documentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 on Unix commands, system calls, and libraries. The command reads a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 topic as an argument, and displays the Unix manual page for that topic.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 @code{manual-entry} always searches all 8 sections of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 manual and concatenates all the entries it finds. For example,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 the topic @samp{termcap} finds the description of the termcap library
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 from section 3, followed by the description of the termcap data base
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 from section 5.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 @node Change Log, Tags, Documentation, Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 @section Change Logs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 @cindex change log
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 @findex add-change-log-entry
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 The Emacs command @kbd{M-x add-change-log-entry} helps you keep a record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 of when and why you have changed a program. It assumes that you have a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 file in which you write a chronological sequence of entries describing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 individual changes. The default is to store the change entries in a file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 called @file{ChangeLog} in the same directory as the file you are editing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 The same @file{ChangeLog} file therefore records changes for all the files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 in a directory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 A change log entry starts with a header line that contains your name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 and the current date. Except for these header lines, every line in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 change log starts with a tab. One entry can describe several changes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 each change starts with a line starting with a tab and a star. @kbd{M-x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 add-change-log-entry} visits the change log file and creates a new entry
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 unless the most recent entry is for today's date and your name. In
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 either case, it adds a new line to start the description of another
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 change just after the header line of the entry. When @kbd{M-x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 add-change-log-entry} is finished, all is prepared for you to edit in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 the description of what you changed and how. You must then save the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 change log file yourself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 The change log file is always visited in Indented Text mode, which means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 that @key{LFD} and auto-filling indent each new line like the previous
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 line. This is convenient for entering the contents of an entry, which must
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 be indented. @xref{Text Mode}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 Here is an example of the formatting conventions used in the change log
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 for Emacs:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 Wed Jun 26 19:29:32 1985 Richard M. Stallman (rms at mit-prep)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 * xdisp.c (try_window_id):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 If C-k is done at end of next-to-last line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 this fn updates window_end_vpos and cannot leave
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 window_end_pos nonnegative (it is zero, in fact).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 If display is preempted before lines are output,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 this is inconsistent. Fix by setting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 blank_end_of_window to nonzero.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 Tue Jun 25 05:25:33 1985 Richard M. Stallman (rms at mit-prep)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 * cmds.c (Fnewline):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 Call the auto fill hook if appropriate.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 * xdisp.c (try_window_id):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 If point is found by compute_motion after xp, record that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 permanently. If display_text_line sets point position wrong
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 (case where line is killed, point is at eob and that line is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 not displayed), set it again in final compute_motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
837 @node Tags, CC Mode, Change Log, Programs
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 @section Tags Tables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 @cindex tags table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 A @dfn{tags table} is a description of how a multi-file program is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 broken up into files. It lists the names of the component files and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 names and positions of the functions (or other named subunits) in each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 file. Grouping the related files makes it possible to search or replace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 through all the files with one command. Recording the function names
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 and positions makes possible the @kbd{M-.} command which finds the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 definition of a function by looking up which of the files it is in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 Tags tables are stored in files called @dfn{tags table files}. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 conventional name for a tags table file is @file{TAGS}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 Each entry in the tags table records the name of one tag, the name of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 file that the tag is defined in (implicitly), and the position in that file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 of the tag's definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 Just what names from the described files are recorded in the tags table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 depends on the programming language of the described file. They
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 normally include all functions and subroutines, and may also include
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 global variables, data types, and anything else convenient. Each name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 recorded is called a @dfn{tag}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
862 @cindex C++ class browser, tags
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
863 @cindex tags, C++
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
864 @cindex class browser, C++
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
865 @cindex Ebrowse
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
866 The Ebrowse is a separate facility tailored for C++, with tags and a
704
374035d3ca4c [xemacs-hg @ 2001-12-18 22:37:41 by janv]
janv
parents: 460
diff changeset
867 class browser. @xref{Ebrowse,,, ebrowse, Ebrowse User's Manual}.
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
868
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 * Tag Syntax:: Tag syntax for various types of code and text files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 * Create Tags Table:: Creating a tags table with @code{etags}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 * Etags Regexps:: Create arbitrary tags using regular expressions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 * Select Tags Table:: How to visit a tags table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 * Find Tag:: Commands to find the definition of a specific tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 * Tags Search:: Using a tags table for searching and replacing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 * List Tags:: Listing and finding tags defined in a file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5707
diff changeset
879 @node Tag Syntax, Create Tags Table, Tags, Tags
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 @subsection Source File Tag Syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 Here is how tag syntax is defined for the most popular languages:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 In C code, any C function or typedef is a tag, and so are definitions of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 @code{struct}, @code{union} and @code{enum}. You can tag function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 declarations and external variables in addition to function definitions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 by giving the @samp{--declarations} option to @code{etags}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 @code{#define} macro definitions and @code{enum} constants are also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 tags, unless you specify @samp{--no-defines} when making the tags table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 Similarly, global variables are tags, unless you specify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 @samp{--no-globals}. Use of @samp{--no-globals} and @samp{--no-defines}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 can make the tags table file much smaller.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 In C++ code, in addition to all the tag constructs of C code, member
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 functions are also recognized, and optionally member variables if you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 use the @samp{--members} option. Tags for variables and functions in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 classes are named @samp{@var{class}::@var{variable}} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 @samp{@var{class}::@var{function}}. @code{operator} functions tags are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 named, for example @samp{operator+}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 In Java code, tags include all the constructs recognized in C++, plus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 the @code{interface}, @code{extends} and @code{implements} constructs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 Tags for variables and functions in classes are named
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 @samp{@var{class}.@var{variable}} and @samp{@var{class}.@var{function}}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 In La@TeX{} text, the argument of any of the commands @code{\chapter},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 @code{\section}, @code{\subsection}, @code{\subsubsection},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 @code{\eqno}, @code{\label}, @code{\ref}, @code{\cite}, @code{\bibitem},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 @code{\part}, @code{\appendix}, @code{\entry}, or @code{\index}, is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 tag.@refill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 Other commands can make tags as well, if you specify them in the
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
918 environment variable @code{TEXTAGS} before invoking @code{etags}. The
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 value of this environment variable should be a colon-separated list of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 command names. For example,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 TEXTAGS="def:newcommand:newenvironment"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 export TEXTAGS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 specifies (using Bourne shell syntax) that the commands @samp{\def},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 @samp{\newcommand} and @samp{\newenvironment} also define tags.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 In Lisp code, any function defined with @code{defun}, any variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 defined with @code{defvar} or @code{defconst}, and in general the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 argument of any expression that starts with @samp{(def} in column zero, is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 a tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 In Scheme code, tags include anything defined with @code{def} or with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 construct whose name starts with @samp{def}. They also include variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 set with @code{set!} at top level in the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 Several other languages are also supported:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 In Ada code, functions, procedures, packages, tasks, and types are
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
949 tags. Use the @samp{--packages-only} option to create tags for
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
950 packages only.
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
951
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
952 With Ada, it is possible to have the same name used for different
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
953 entity kinds (e.g.@: the same name for a procedure and a function). Also,
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
954 for things like packages, procedures and functions, there is the spec
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
955 (i.e.@: the interface) and the body (i.e.@: the implementation). To
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
956 facilitate the choice to the user, a tag value is appended with a
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
957 qualifier:
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
958
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
959 @table @asis
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
960 @item function
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
961 @kbd{/f}
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
962 @item procedure
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
963 @kbd{/p}
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
964 @item package spec
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
965 @kbd{/s}
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
966 @item package body
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
967 @kbd{/b}
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
968 @item type
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
969 @kbd{/t}
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
970 @item task
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
971 @kbd{/k}
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
972 @end table
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
973
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
974 So, as an example, @kbd{M-x find-tag bidule/b} will go directly to the
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
975 body of the package @var{bidule} while @kbd{M-x find-tag bidule} will
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
976 just search for any tag @var{bidule}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 In assembler code, labels appearing at the beginning of a line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 followed by a colon, are tags.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 In Bison or Yacc input files, each rule defines as a tag the nonterminal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 it constructs. The portions of the file that contain C code are parsed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 as C code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 In Cobol code, tags are paragraph names; that is, any word starting in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 column 8 and followed by a period.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 In Erlang code, the tags are the functions, records, and macros defined
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 in the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 In Fortran code, functions, subroutines and blockdata are tags.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 @item
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
999 In makefiles, targets are tags.
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
1000
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
1001 @item
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 In Objective C code, tags include Objective C definitions for classes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 class categories, methods, and protocols.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 In Pascal code, the tags are the functions and procedures defined in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 In Perl code, the tags are the procedures defined by the @code{sub},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 @code{my} and @code{local} keywords. Use @samp{--globals} if you want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 to tag global variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 @item
709
1df7a5cfb04a [xemacs-hg @ 2001-12-20 07:58:18 by yoshiki]
yoshiki
parents: 704
diff changeset
1015 In PHP code, tags are functions, classes and defines. When using the
1df7a5cfb04a [xemacs-hg @ 2001-12-20 07:58:18 by yoshiki]
yoshiki
parents: 704
diff changeset
1016 @samp{--members} option, vars are tags too.
1df7a5cfb04a [xemacs-hg @ 2001-12-20 07:58:18 by yoshiki]
yoshiki
parents: 704
diff changeset
1017
1df7a5cfb04a [xemacs-hg @ 2001-12-20 07:58:18 by yoshiki]
yoshiki
parents: 704
diff changeset
1018 @item
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
1019 In PostScript code, the tags are the functions.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 @item
709
1df7a5cfb04a [xemacs-hg @ 2001-12-20 07:58:18 by yoshiki]
yoshiki
parents: 704
diff changeset
1022 In Prolog code, tags are predicates and rules at the beginning of
1df7a5cfb04a [xemacs-hg @ 2001-12-20 07:58:18 by yoshiki]
yoshiki
parents: 704
diff changeset
1023 line.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 In Python code, @code{def} or @code{class} at the beginning of a line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 generate a tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
1030 You can also generate tags based on regexp matching (@pxref{Etags
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
1031 Regexps}) to handle other formats and languages.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5707
diff changeset
1033 @node Create Tags Table, Etags Regexps, Tag Syntax, Tags
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 @subsection Creating Tags Tables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 @cindex @code{etags} program
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 The @code{etags} program is used to create a tags table file. It knows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 the syntax of several languages, as described in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 @iftex
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 the previous section.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 @end iftex
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 @ifinfo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 @ref{Tag Syntax}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 @end ifinfo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 Here is how to run @code{etags}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 etags @var{inputfiles}@dots{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 The @code{etags} program reads the specified files, and writes a tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 table named @file{TAGS} in the current working directory. You can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 intermix compressed and plain text source file names. @code{etags}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 knows about the most common compression formats, and does the right
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 thing. So you can compress all your source files and have @code{etags}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 look for compressed versions of its file name arguments, if it does not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 find uncompressed versions. Under MS-DOS, @code{etags} also looks for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 file names like @samp{mycode.cgz} if it is given @samp{mycode.c} on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 command line and @samp{mycode.c} does not exist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 @code{etags} recognizes the language used in an input file based on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 its file name and contents. You can specify the language with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 @samp{--language=@var{name}} option, described below.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 If the tags table data become outdated due to changes in the files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 described in the table, the way to update the tags table is the same way it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 was made in the first place. It is not necessary to do this often.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 If the tags table fails to record a tag, or records it for the wrong
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 file, then Emacs cannot possibly find its definition. However, if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 position recorded in the tags table becomes a little bit wrong (due to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 some editing in the file that the tag definition is in), the only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 consequence is a slight delay in finding the tag. Even if the stored
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 position is very wrong, Emacs will still find the tag, but it must
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 search the entire file for it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 So you should update a tags table when you define new tags that you want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 to have listed, or when you move tag definitions from one file to another,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 or when changes become substantial. Normally there is no need to update
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 the tags table after each edit, or even every day.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 One tags table can effectively include another. Specify the included
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 tags file name with the @samp{--include=@var{file}} option when creating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 the file that is to include it. The latter file then acts as if it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 contained all the files specified in the included file, as well as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 files it directly contains.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 If you specify the source files with relative file names when you run
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 @code{etags}, the tags file will contain file names relative to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 directory where the tags file was initially written. This way, you can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 move an entire directory tree containing both the tags file and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 source files, and the tags file will still refer correctly to the source
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 If you specify absolute file names as arguments to @code{etags}, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 the tags file will contain absolute file names. This way, the tags file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 will still refer to the same files even if you move it, as long as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 source files remain in the same place. Absolute file names start with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 @samp{/}, or with @samp{@var{device}:/} on MS-DOS and MS-Windows.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 When you want to make a tags table from a great number of files, you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 may have problems listing them on the command line, because some systems
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 have a limit on its length. The simplest way to circumvent this limit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 is to tell @code{etags} to read the file names from its standard input,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 by typing a dash in place of the file names, like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 find . -name "*.[chCH]" -print | etags -
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 Use the option @samp{--language=@var{name}} to specify the language
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 explicitly. You can intermix these options with file names; each one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 applies to the file names that follow it. Specify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 @samp{--language=auto} to tell @code{etags} to resume guessing the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 language from the file names and file contents. Specify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 @samp{--language=none} to turn off language-specific processing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 entirely; then @code{etags} recognizes tags by regexp matching alone
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 (@pxref{Etags Regexps}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 @samp{etags --help} prints the list of the languages @code{etags}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 knows, and the file name rules for guessing the language. It also prints
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 a list of all the available @code{etags} options, together with a short
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 explanation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5707
diff changeset
1126 @node Etags Regexps, Select Tags Table, Create Tags Table, Tags
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 @subsection Etags Regexps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 The @samp{--regex} option provides a general way of recognizing tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 based on regexp matching. You can freely intermix it with file names.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 Each @samp{--regex} option adds to the preceding ones, and applies only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 to the following files. The syntax is:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 --regex=/@var{tagregexp}[/@var{nameregexp}]/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 where @var{tagregexp} is used to match the lines to tag. It is always
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 anchored, that is, it behaves as if preceded by @samp{^}. If you want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 to account for indentation, just match any initial number of blanks by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 beginning your regular expression with @samp{[ \t]*}. In the regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 expressions, @samp{\} quotes the next character, and @samp{\t} stands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 for the tab character. Note that @code{etags} does not handle the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 C escape sequences for special characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 @cindex interval operator (in regexps)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 The syntax of regular expressions in @code{etags} is the same as in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 Emacs, augmented with the @dfn{interval operator}, which works as in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 @code{grep} and @code{ed}. The syntax of an interval operator is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 @samp{\@{@var{m},@var{n}\@}}, and its meaning is to match the preceding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 expression at least @var{m} times and up to @var{n} times.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 You should not match more characters with @var{tagregexp} than that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 needed to recognize what you want to tag. If the match is such that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 more characters than needed are unavoidably matched by @var{tagregexp}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 (as will usually be the case), you should add a @var{nameregexp}, to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 pick out just the tag. This will enable Emacs to find tags more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 accurately and to do completion on tag names more reliably. You can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 find some examples below.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 The option @samp{--ignore-case-regex} (or @samp{-c}) is like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 @samp{--regex}, except that the regular expression provided will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 matched without regard to case, which is appropriate for various
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 programming languages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 The @samp{-R} option deletes all the regexps defined with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 @samp{--regex} options. It applies to the file names following it, as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 you can see from the following example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 etags --regex=/@var{reg1}/ voo.doo --regex=/@var{reg2}/ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 bar.ber -R --lang=lisp los.er
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 Here @code{etags} chooses the parsing language for @file{voo.doo} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 @file{bar.ber} according to their contents. @code{etags} also uses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 @var{reg1} to recognize additional tags in @file{voo.doo}, and both
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 @var{reg1} and @var{reg2} to recognize additional tags in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 @file{bar.ber}. @code{etags} uses the Lisp tags rules, and no regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 matching, to recognize tags in @file{los.er}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 A regular expression can be bound to a given language, by prepending
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 it with @samp{@{lang@}}. When you do this, @code{etags} will use the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 regular expression only for files of that language. @samp{etags --help}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 prints the list of languages recognised by @code{etags}. The following
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 example tags the @code{DEFVAR} macros in the Emacs source files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 @code{etags} applies this regular expression to C files only:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 --regex='@{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 This feature is particularly useful when storing a list of regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 expressions in a file. The following option syntax instructs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 @code{etags} to read two files of regular expressions. The regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 expressions contained in the second file are matched without regard to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 --regex=@@first-file --ignore-case-regex=@@second-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 A regex file contains one regular expressions per line. Empty lines,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 and lines beginning with space or tab are ignored. When the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 character in a line is @samp{@@}, @code{etags} assumes that the rest of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 the line is the name of a file of regular expressions. This means that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 such files can be nested. All the other lines are taken to be regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 expressions. For example, one can create a file called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 @samp{emacs.tags} with the following contents (the first line in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 file is a comment):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 -- This is for GNU Emacs source files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 @{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/\1/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 and then use it like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 etags --regex=@@emacs.tags *.[ch] */*.[ch]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 Here are some more examples. The regexps are quoted to protect them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 from shell interpretation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 Tag Octave files:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 etags --language=none \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 --regex='/[ \t]*function.*=[ \t]*\([^ \t]*\)[ \t]*(/\1/' \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 --regex='/###key \(.*\)/\1/' \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 --regex='/[ \t]*global[ \t].*/' \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 *.m
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 Note that tags are not generated for scripts so that you have to add a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 line by yourself of the form `###key <script-name>' if you want to jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 Tag Tcl files:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 etags --language=none --regex='/proc[ \t]+\([^ \t]+\)/\1/' *.tcl
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 Tag VHDL files:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 --language=none \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/' \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 @node Select Tags Table, Find Tag, Etags Regexps, Tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 @subsection Selecting a Tags Table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 @vindex tag-table-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 At any time Emacs has one @dfn{selected} tags table, and all the commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 for working with tags tables use the selected one. To select a tags table,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 use the variable @code{tag-table-alist}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 The value of @code{tag-table-alist} is a list that determines which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 @code{TAGS} files should be active for a given buffer. This is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 really an association list, in that all elements are checked. The car
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 of each element of this list is a pattern against which the buffers file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 name is compared; if it matches, then the cdr of the list should be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 name of the tags table to use. If more than one element of this list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 matches the buffers file name, all of the associated tags tables are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 used. Earlier ones are searched first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 If the car of elements of this list are strings, they are treated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 as regular-expressions against which the file is compared (like the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 @code{auto-mode-alist}). If they are not strings, they are evaluated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 If they evaluate to non-@code{nil}, the current buffer is considered to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 If the cdr of the elements of this list are strings, they are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 assumed to name a tags file. If they name a directory, the string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 @file{tags} is appended to them to get the file name. If they are not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 strings, they are evaluated and must return an appropriate string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 (setq tag-table-alist
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1299 '(("/usr/src/public/perl/" . "/usr/src/public/perl/perl-3.0/")
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1300 ("\\.el$" . "/usr/local/emacs/src/")
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1301 ("/jbw/gnu/" . "/usr15/degree/stud/jbw/gnu/")
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1302 ("" . "/usr/local/emacs/src/")
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1303 ))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 The example defines the tags table alist in the following way:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 Anything in the directory @file{/usr/src/public/perl/}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 should use the @file{TAGS} file @file{/usr/src/public/perl/perl-3.0/TAGS}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 Files ending in @file{.el} should use the @file{TAGS} file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 @file{/usr/local/emacs/src/TAGS}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 Anything in or below the directory @file{/jbw/gnu/} should use the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 @file{TAGS} file @file{/usr15/degree/stud/jbw/gnu/TAGS}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 If you had a file called @file{/usr/jbw/foo.el}, it would use both
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 @file{TAGS} files, @* @file{/usr/local/emacs/src/TAGS} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 @file{/usr15/degree/stud/jbw/gnu/TAGS} (in that order), because it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 matches both patterns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 If the buffer-local variable @code{buffer-tag-table} is set, it names a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 tags table that is searched before all others when @code{find-tag} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 executed from this buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 If there is a file called @file{TAGS} in the same directory as the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 in question, then that tags file will always be used as well (after the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 @code{buffer-tag-table} but before the tables specified by this list).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 If the variable @code{tags-file-name} is set, the @file{TAGS} file it names
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 will apply to all buffers (for backwards compatibility.) It is searched
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 @vindex tags-always-build-completion-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 If the value of the variable @code{tags-always-build-completion-table}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 is @code{t}, the tags file will always be added to the completion table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 without asking first, regardless of the size of the tags file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 @vindex tags-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 @findex visit-tags-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 The function @kbd{M-x visit-tags-table}, is largely made obsolete by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 the variable @code{tag-table-alist}, tells tags commands to use the tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 table file @var{file} first. The @var{file} should be the name of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 file created with the @code{etags} program. A directory name is also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 acceptable; it means the file @file{TAGS} in that directory. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 function only stores the file name you provide in the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 @code{tags-file-name}. Emacs does not actually read in the tags table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 contents until you try to use them. You can set the variable explicitly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 instead of using @code{visit-tags-table}. The value of the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 @code{tags-file-name} is the name of the tags table used by all buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 This is for backward compatibility, and is largely supplanted by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 variable @code{tag-table-alist}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 @node Find Tag, Tags Search, Select Tags Table, Tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 @subsection Finding a Tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 The most important thing that a tags table enables you to do is to find
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 the definition of a specific tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 @item M-.@: @var{tag &optional other-window}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 Find first definition of @var{tag} (@code{find-tag}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 @item C-u M-.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 Find next alternate definition of last tag specified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 @item C-x 4 . @var{tag}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 Find first definition of @var{tag}, but display it in another window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 (@code{find-tag-other-window}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 @kindex M-.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 @findex find-tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 @kbd{M-.}@: (@code{find-tag}) is the command to find the definition of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 a specified tag. It searches through the tags table for that tag, as a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 string, then uses the tags table information to determine the file in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 which the definition is used and the approximate character position of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 the definition in the file. Then @code{find-tag} visits the file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 moves point to the approximate character position, and starts searching
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 ever-increasing distances away for the text that should appear at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 the beginning of the definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 If an empty argument is given (by typing @key{RET}), the sexp in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 buffer before or around point is used as the name of the tag to find.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 @xref{Lists}, for information on sexps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 The argument to @code{find-tag} need not be the whole tag name; it can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 be a substring of a tag name. However, there can be many tag names
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 containing the substring you specify. Since @code{find-tag} works by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 searching the text of the tags table, it finds the first tag in the table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 that the specified substring appears in. To find other tags that match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 the substring, give @code{find-tag} a numeric argument, as in @kbd{C-u
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 M-.}. This does not read a tag name, but continues searching the tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 table's text for another tag containing the same substring last used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 If your keyboard has a real @key{META} key, @kbd{M-0 M-.}@: is an easier
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 alternative to @kbd{C-u M-.}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 If the optional second argument @var{other-window} is non-@code{nil}, it uses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 another window to display the tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 Multiple active tags tables and completion are supported.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 Variables of note include the following:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 @vindex tag-table-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 @vindex tags-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 @vindex tags-build-completion-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 @vindex buffer-tag-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 @vindex make-tags-files-invisible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 @vindex tag-mark-stack-max
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 @item tag-table-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 Controls which tables apply to which buffers.
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1415 @item tags-file-name
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 Stores a default tags table.
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1417 @item tags-build-completion-table
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 Controls completion behavior.
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1419 @item buffer-tag-table
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 Specifies a buffer-local table.
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1421 @item make-tags-files-invisible
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 Sets whether tags tables should be very hidden.
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1423 @item tag-mark-stack-max
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 Specifies how many tags-based hops to remember.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 @kindex C-x 4 .
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 @findex find-tag-other-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 Like most commands that can switch buffers, @code{find-tag} has another
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 similar command that displays the new buffer in another window. @kbd{C-x 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 .}@: invokes the function @code{find-tag-other-window}. (This key sequence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 ends with a period.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 Emacs comes with a tags table file @file{TAGS} (in the directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 containing Lisp libraries) that includes all the Lisp libraries and all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 the C sources of Emacs. By specifying this file with @code{visit-tags-table}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 and then using @kbd{M-.}@: you can quickly look at the source of any Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 @node Tags Search, List Tags, Find Tag, Tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 @subsection Searching and Replacing with Tags Tables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 The commands in this section visit and search all the files listed in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 selected tags table, one by one. For these commands, the tags table serves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 only to specify a sequence of files to search. A related command is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 @kbd{M-x grep} (@pxref{Compilation}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 @item M-x tags-search @key{RET} @var{regexp} @key{RET}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 Search for @var{regexp} through the files in the selected tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 @item M-x tags-query-replace @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 Perform a @code{query-replace-regexp} on each file in the selected tags table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 @item M-,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 Restart one of the commands above, from the current location of point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 (@code{tags-loop-continue}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 @findex tags-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 @kbd{M-x tags-search} reads a regexp using the minibuffer, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 searches for matches in all the files in the selected tags table, one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 file at a time. It displays the name of the file being searched so you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 can follow its progress. As soon as it finds an occurrence,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 @code{tags-search} returns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 @kindex M-,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 @findex tags-loop-continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 Having found one match, you probably want to find all the rest. To find
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 one more match, type @kbd{M-,} (@code{tags-loop-continue}) to resume the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 @code{tags-search}. This searches the rest of the current buffer, followed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 by the remaining files of the tags table.@refill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 @findex tags-query-replace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 @kbd{M-x tags-query-replace} performs a single
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 @code{query-replace-regexp} through all the files in the tags table. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 reads a regexp to search for and a string to replace with, just like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 ordinary @kbd{M-x query-replace-regexp}. It searches much like @kbd{M-x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 tags-search}, but repeatedly, processing matches according to your
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 input. @xref{Replace}, for more information on query replace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 It is possible to get through all the files in the tags table with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 single invocation of @kbd{M-x tags-query-replace}. But often it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 useful to exit temporarily, which you can do with any input event that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 has no special query replace meaning. You can resume the query replace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 subsequently by typing @kbd{M-,}; this command resumes the last tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 search or replace command that you did.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 The commands in this section carry out much broader searches than the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 @code{find-tag} family. The @code{find-tag} commands search only for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 definitions of tags that match your substring or regexp. The commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 @code{tags-search} and @code{tags-query-replace} find every occurrence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 of the regexp, as ordinary search commands and replace commands do in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 These commands create buffers only temporarily for the files that they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 have to search (those which are not already visited in Emacs buffers).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 Buffers in which no match is found are quickly killed; the others
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 continue to exist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 It may have struck you that @code{tags-search} is a lot like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 @code{grep}. You can also run @code{grep} itself as an inferior of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 Emacs and have Emacs show you the matching lines one by one. This works
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 much like running a compilation; finding the source locations of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 @code{grep} matches works like finding the compilation errors.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 @xref{Compilation}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 If you wish to process all the files in a selected tags table, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 @kbd{M-x tags-search} and @kbd{M-x tags-query-replace} are not giving
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 you the desired result, you can use @kbd{M-x next-file}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 @item C-u M-x next-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 With a numeric argument, regardless of its value, visit the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 file in the tags table and prepare to advance sequentially by files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 @item M-x next-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 Visit the next file in the selected tags table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 @node List Tags, , Tags Search, Tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 @subsection Tags Table Inquiries
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 @item M-x list-tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 Display a list of the tags defined in a specific program file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 @item M-x tags-apropos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 Display a list of all tags matching a specified regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 @findex list-tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 @kbd{M-x list-tags} reads the name of one of the files described by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 selected tags table, and displays a list of all the tags defined in that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 file. The ``file name'' argument is really just a string to compare
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 against the names recorded in the tags table; it is read as a string rather
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 than a file name. Therefore, completion and defaulting are not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 available, and you must enter the string the same way it appears in the tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 table. Do not include a directory as part of the file name unless the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 name recorded in the tags table contains that directory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 @findex tags-apropos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 @kbd{M-x tags-apropos} is like @code{apropos} for tags. It reads a regexp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 then finds all the tags in the selected tags table whose entries match that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 regexp, and displays the tag names found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1544 @node CC Mode, Fortran, Tags, Programs
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1545 @section Modes for C, C++, Java and similar languages
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1546 @cindex C Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1547 @cindex C++ Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1548 @cindex Java Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1549 @cindex AWK Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1550 @cindex Objective C Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1551 @cindex CORBA IDL Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1552 @findex c-mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1553 @findex c++-mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1554 @findex java-mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1555 @findex idl-mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1556 @findex awk-mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1557 @findex pike-mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1558 @findex objc-mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1559 @vindex c-mode-hook
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1560 @vindex c++-mode-hook
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1561 @vindex java-mode-hook
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1562 @vindex idl-mode-hook
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1563 @vindex awk-mode-hook
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1564 @vindex pike-mode-hook
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1565 @vindex objc-mode-hook
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1566 @vindex c-mode-common-hook
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1567 @vindex c-initialization-hook
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1568
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1569 The recommended means for supporting the ``C--like'' programming
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1570 languages in XEmacs is the @file{cc-mode} package. CC Mode is not
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1571 included in the basic XEmacs distribution but is available as an
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1572 optional package. If loading a file whose names ends in the @file{.cc}
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1573 extension does not automatically invoke a C++ Mode then the
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1574 @file{cc-mode} package is probably not yet installed. @xref{Packages}.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1575
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1576 CC Mode provides modes for editing source files in Awk
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1577 (@code{awk-mode}), C (@code{c-mode}), C++ (@code{c++-mode}), CORBA IDL
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1578 (@code{idl-mode}), Java (@code{java-mode}), Objective C
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1579 (@code{objc-mode}), and Pike (@code{pike-mode}). All these languages are
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1580 supported with an sophisticated ``indentation engine'' that is feature
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1581 rich, customizable and quite efficient.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1582
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1583 Each language major mode runs hooks in the conventionally named hook
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1584 variables (@pxref{Mode Hooks}). In addition to this conventional
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1585 behavior all the CC Mode major modes will also run hooks in
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1586 @code{c-mode-common-hook} @emph{before} invoking the major mode specific
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1587 hook.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1588
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1589 CC Mode runs any hooks in @code{c-initialization-hook} exactly once
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1590 when it is first loaded.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1591
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1592 CC Mode is a very comprehensive and flexible system and full
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1593 description of its capabilities is beyond the scope of this manual. It
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1594 is strongly recommended that the reader consult the CC Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1595 documentation for details once the package has been
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1596 installed. @xref{Top,CC Mode,,cc-mode, The CC Mode Manual}.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1597
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1598 @menu
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1599 * Older Modes:: Older Modes for C and AWK
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1600 * Customizing CC Mode:: An Introduction to Customizing CC Mode.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1601 @end menu
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1602
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1603
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1604 @node Older Modes, Customizing CC Mode, CC Mode, CC Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1605 @subsection Older Modes for C and AWK
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1606 @cindex Old C Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1607 @cindex Old AWK Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1608 @cindex C Mode without CC Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1609 @cindex AWK Mode without CC Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1610 @cindex old-c-mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1611
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1612 XEmacs provides older versions of a C Mode and an AWK Mode in the
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1613 @file{prog-modes} package. These older modes do not share the
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1614 indentation engine in CC Mode have have their own specific means of
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1615 customizing indentation. To use these modes the @file{prog-modes}
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1616 package must be installed.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1617
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1618 This older C mode is known simply as the ``Old C Mode''. It supports
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1619 only the C language and it lacks many of the features of CC Mode.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1620 However the old C mode offers modest space requirements and very fast
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1621 operation. Old C Mode might be useful in space constrained
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1622 environments, on slow machines, or for editing very large files. This
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1623 old C mode is available in the @file{old-c-mode}
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1624 library. @xref{old-c-mode,Old C Mode,old-c-mode,prog-modes,The
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1625 Programming Modes Package Manual}.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1626
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1627 The old AWK mode exists for similar reasons. It is available in the
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1628 @file{awk-mode} library. @xref{awk-mode,Old AWK
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1629 Mode,awk-mode,prog-modes,The Programming Modes Package Manual}.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1630
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1631 Note that the prog-modes package will never automatically invoke these
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1632 older modes for a user. However installing the @file{cc-mode} package
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1633 @emph{will} make CC Mode's versions available automatically. As a
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1634 result a user who wants to use these older modes must explicitly load
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1635 the old libraries to use them.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1636
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1637 @node Customizing CC Mode, , Older Modes, CC Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1638 @subsection Customizing Indentation in CC Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1639
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1640 A very brief introduction is included here on customizing CC Mode. CC
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1641 Mode has many features, including useful minor modes, that are
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1642 completely documented in its own manual.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1643
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1644 CC Mode implements several different ``styles'' for C code (and the
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1645 other languages supported by CC Mode). If you need to change the
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1646 indentation style for CC Mode it is recommended that you first see if an
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1647 existing style meets your requirements. The style chosen will affect the
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1648 placement of language elements like braces, function declarations and
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1649 comments. You can choose a style interactively by typing @kbd{C-c .} and
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1650 pressing the space bar at the prompt to get a list of supported
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1651 styles. @kbd{C-c .} runs the function @code{c-set-style} which applies
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1652 to all CC Mode language modes though its name might suggest otherwise. A
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1653 few of the the supported styles are listed below.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1654
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1655 @itemize @bullet
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1656 @item
4488
6b0000935adc Spelling fixes.
"Ville Skyttä <scop@xemacs.org>"
parents: 2522
diff changeset
1657 ``gnu'' --- The recommended style from the Free Software Foundation for
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1658 GNU software.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1659 @item
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1660 ``k&r'' --- The classic style from Kernighan and Ritchie.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1661 @item
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1662 ``linux'' --- The style recommended for code in the Linux kernel.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1663 @item
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1664 ``bsd'' --- The style recommended for software developed in BSD.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1665 @item
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1666 ``java --- The ``traditional'' Java style.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1667 @end itemize
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1668
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1669 The default style in XEmacs is ``gnu'' except for Java mode where it
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1670 is the ``java'' style (this is governed by the variable
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1671 @code{c-default-style}).
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1672
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1673 The styles included in CC Mode all use a buffer local variable called
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1674 @code{c-basic-offset} as the basic indentation level (this buffer local
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1675 variable is used in all CC Mode language modes though its name might
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1676 suggest otherwise). All indentation is, by default, expressed in
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1677 multiples of @code{c-basic-offset}.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1678
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1679 Each style defines a default value for @code{c-basic-offset}, for the
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1680 ``gnu'' style sets it to 2. A very common customization scenario is
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1681 where a user wants to use an existing style but with a different basic
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1682 offset value. An easy way to do this is to set @code{c-basic-offset} in
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1683 the language mode hook after selecting the chosen style.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1684
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1685 For example, a user might want to follow a local coding convention of
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1686 using the ``k&r'' style for C code with indentation in two columns
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1687 multiples (instead of the five column default provided by the CC Mode
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1688 ``k&r'' style). This can be achieved with the following code in the
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1689 initialization file (@pxref{Init File})
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1690
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1691 @example
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1692 (defun my-c-mode-hook ()
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1693 (c-set-style "k&r")
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1694 (setq c-basic-offset 2))
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1695 (add-hook 'c-mode-hook 'my-c-mode-hook)
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1696 @end example
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1697
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1698 Most customizations for indentation in various CC modes can be
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1699 accomplished by choosing a style and then choosing value for
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1700 @code{c-basic-offset} that meets the local coding convention. CC Mode
4488
6b0000935adc Spelling fixes.
"Ville Skyttä <scop@xemacs.org>"
parents: 2522
diff changeset
1701 has a very customizable indentation engine and a further discussion is
2522
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1702 really beyond the scope of this manual. @xref{Indentation
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1703 Engine,,,cc-mode,The CC Mode Manual}.
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1704
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1705
52dc9b940348 [xemacs-hg @ 2005-01-28 00:12:32 by ben]
ben
parents: 709
diff changeset
1706 @node Fortran, Asm Mode, CC Mode, Programs
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 @section Fortran Mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 @cindex Fortran mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 Fortran mode provides special motion commands for Fortran statements and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 subprograms, and indentation commands that understand Fortran conventions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 of nesting, line numbers, and continuation statements.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 Special commands for comments are provided because Fortran comments are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 unlike those of other languages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 Built-in abbrevs optionally save typing when you insert Fortran keywords.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 @findex fortran-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 Use @kbd{M-x fortran-mode} to switch to this major mode. Doing so calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 the value of @code{fortran-mode-hook} as a function of no arguments if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 that variable has a non-@code{nil} value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 * Motion: Fortran Motion. Moving point by statements or subprograms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 * Indent: Fortran Indent. Indentation commands for Fortran.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 * Comments: Fortran Comments. Inserting and aligning comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 * Columns: Fortran Columns. Measuring columns for valid Fortran.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 * Abbrev: Fortran Abbrev. Built-in abbrevs for Fortran keywords.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 Fortran mode was contributed by Michael Prange.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 @node Fortran Motion, Fortran Indent, Fortran, Fortran
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 @subsection Motion Commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 Fortran mode provides special commands to move by subprograms (functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 and subroutines) and by statements. There is also a command to put the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 region around one subprogram, which is convenient for killing it or moving it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 @kindex C-M-a (Fortran mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 @kindex C-M-e (Fortran mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 @kindex C-M-h (Fortran mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 @kindex C-c C-p (Fortran mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 @kindex C-c C-n (Fortran mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 @findex beginning-of-fortran-subprogram
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 @findex end-of-fortran-subprogram
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 @findex mark-fortran-subprogram
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 @findex fortran-previous-statement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 @findex fortran-next-statement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 @item C-M-a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 Move to beginning of subprogram@*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 (@code{beginning-of-fortran-subprogram}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 @item C-M-e
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 Move to end of subprogram (@code{end-of-fortran-subprogram}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 @item C-M-h
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 Put point at beginning of subprogram and mark at end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 (@code{mark-fortran-subprogram}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 @item C-c C-n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 Move to beginning of current or next statement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 (@code{fortran-next-@*statement}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 @item C-c C-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 Move to beginning of current or previous statement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 (@code{fortran-@*previous-statement}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 @node Fortran Indent, Fortran Comments, Fortran Motion, Fortran
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 @subsection Fortran Indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 Special commands and features are available for indenting Fortran
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 code. They make sure various syntactic entities (line numbers, comment line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 indicators, and continuation line flags) appear in the columns that are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 required for standard Fortran.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 * Commands: ForIndent Commands. Commands for indenting Fortran.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 * Numbers: ForIndent Num. How line numbers auto-indent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 * Conv: ForIndent Conv. Conventions you must obey to avoid trouble.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 * Vars: ForIndent Vars. Variables controlling Fortran indent style.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 @node ForIndent Commands, ForIndent Num, Fortran Indent, Fortran Indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 @subsubsection Fortran Indentation Commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 @item @key{TAB}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 Indent the current line (@code{fortran-indent-line}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 @item M-@key{LFD}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 Break the current line and set up a continuation line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 @item C-M-q
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 Indent all the lines of the subprogram point is in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 (@code{fortran-indent-subprogram}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 @findex fortran-indent-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 @key{TAB} is redefined by Fortran mode to reindent the current line for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 Fortran (@code{fortran-indent-line}). Line numbers and continuation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 markers are indented to their required columns, and the body of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 statement is independently indented, based on its nesting in the program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 @kindex C-M-q (Fortran mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 @findex fortran-indent-subprogram
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 The key @kbd{C-M-q} is redefined as @code{fortran-indent-subprogram}, a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 command that reindents all the lines of the Fortran subprogram (function or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 subroutine) containing point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 @kindex M-LFD (Fortran mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 @findex fortran-split-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 The key @kbd{M-@key{LFD}} is redefined as @code{fortran-split-line}, a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 command to split a line in the appropriate fashion for Fortran. In a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 non-comment line, the second half becomes a continuation line and is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 indented accordingly. In a comment line, both halves become separate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 comment lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 @node ForIndent Num, ForIndent Conv, ForIndent Commands, Fortran Indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 @subsubsection Line Numbers and Continuation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 If a number is the first non-whitespace in the line, it is assumed to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 a line number and is moved to columns 0 through 4. (Columns are always
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 counted from 0 in XEmacs.) If the text on the line starts with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 conventional Fortran continuation marker @samp{$}, it is moved to column 5.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 If the text begins with any non whitespace character in column 5, it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 assumed to be an unconventional continuation marker and remains in column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 5.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 @vindex fortran-line-number-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 Line numbers of four digits or less are normally indented one space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 This amount is controlled by the variable @code{fortran-line-number-indent},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 which is the maximum indentation a line number can have. Line numbers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 are indented to right-justify them to end in column 4 unless that would
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 require more than the maximum indentation. The default value of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 variable is 1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 @vindex fortran-electric-line-number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 Simply inserting a line number is enough to indent it according to these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 rules. As each digit is inserted, the indentation is recomputed. To turn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 off this feature, set the variable @code{fortran-electric-line-number} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 @code{nil}. Then inserting line numbers is like inserting anything else.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 @node ForIndent Conv, ForIndent Vars, ForIndent Num, Fortran Indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 @subsubsection Syntactic Conventions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 Fortran mode assumes that you follow certain conventions that simplify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 the task of understanding a Fortran program well enough to indent it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 properly:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 @vindex fortran-continuation-char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 Two nested @samp{do} loops never share a @samp{continue} statement.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 The same character appears in column 5 of all continuation lines. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 is the value of the variable @code{fortran-continuation-char}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 By default, this character is @samp{$}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 If you fail to follow these conventions, the indentation commands may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 indent some lines unaesthetically. However, a correct Fortran program will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 retain its meaning when reindented even if the conventions are not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 followed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 @node ForIndent Vars, , ForIndent Conv, Fortran Indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 @subsubsection Variables for Fortran Indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 @vindex fortran-do-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 @vindex fortran-if-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 @vindex fortran-continuation-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 @vindex fortran-check-all-num-for-matching-do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 @vindex fortran-minimum-statement-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 Several additional variables control how Fortran indentation works.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 @table @code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 @item fortran-do-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 Extra indentation within each level of @samp{do} statement (the default is 3).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 @item fortran-if-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 Extra indentation within each level of @samp{if} statement (the default is 3).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 @item fortran-continuation-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 Extra indentation for bodies of continuation lines (the default is 5).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 @item fortran-check-all-num-for-matching-do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 If this is @code{nil}, indentation assumes that each @samp{do}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 statement ends on a @samp{continue} statement. Therefore, when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 computing indentation for a statement other than @samp{continue}, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 can save time by not checking for a @samp{do} statement ending there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 If this is non-@code{nil}, indenting any numbered statement must check
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 for a @samp{do} that ends there. The default is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 @item fortran-minimum-statement-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 Minimum indentation for Fortran statements. For standard Fortran,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 this is 6. Statement bodies are always indented at least this much.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 @node Fortran Comments, Fortran Columns, Fortran Indent, Fortran
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 @subsection Comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 The usual Emacs comment commands assume that a comment can follow a line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 of code. In Fortran, the standard comment syntax requires an entire line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 to be just a comment. Therefore, Fortran mode replaces the standard Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 comment commands and defines some new variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 Fortran mode can also handle a non-standard comment syntax where comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 start with @samp{!} and can follow other text. Because only some Fortran
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 compilers accept this syntax, Fortran mode will not insert such comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 unless you have specified to do so in advance by setting the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 @code{comment-start} to @samp{"!"} (@pxref{Variables}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 @item M-;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 Align comment or insert new comment (@code{fortran-comment-indent}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 @item C-x ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 Applies to nonstandard @samp{!} comments only.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 @item C-c ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 Turn all lines of the region into comments, or (with arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 turn them back into real code (@code{fortran-comment-region}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 @kbd{M-;} in Fortran mode is redefined as the command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 @code{fortran-comment-indent}. Like the usual @kbd{M-;} command,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 it recognizes an existing comment and aligns its text appropriately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 If there is no existing comment, a comment is inserted and aligned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 Inserting and aligning comments is not the same in Fortran mode as in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 other modes. When a new comment must be inserted, a full-line comment is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 inserted if the current line is blank. On a non-blank line, a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 non-standard @samp{!} comment is inserted if you previously specified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 you wanted to use them. Otherwise a full-line comment is inserted on a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 new line before the current line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 Non-standard @samp{!} comments are aligned like comments in other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 languages, but full-line comments are aligned differently. In a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 standard full-line comment, the comment delimiter itself must always
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 appear in column zero. What can be aligned is the text within the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 comment. You can choose from three styles of alignment by setting the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 variable @code{fortran-comment-indent-style} to one of these values:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 @vindex fortran-comment-indent-style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 @vindex fortran-comment-line-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 @table @code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 @item fixed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 The text is aligned at a fixed column, which is the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 @code{fortran-comment-line-column}. This is the default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 @item relative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 The text is aligned as if it were a line of code, but with an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 additional @code{fortran-comment-line-column} columns of indentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 @item nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 Text in full-line columns is not moved automatically.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 @vindex fortran-comment-indent-char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 You can also specify the character to be used to indent within
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 full-line comments by setting the variable @code{fortran-comment-indent-char}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 to the character you want to use.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 @vindex comment-line-start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 @vindex comment-line-start-skip
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 Fortran mode introduces two variables @code{comment-line-start} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 @code{comment-line-start-skip}, which do for full-line comments what
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 @code{comment-start} and @code{comment-start-skip} do for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 ordinary text-following comments. Normally these are set properly by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 Fortran mode, so you do not need to change them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 The normal Emacs comment command @kbd{C-x ;} has not been redefined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 It can therefore be used if you use @samp{!} comments, but is useless in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 Fortran mode otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 @kindex C-c ; (Fortran mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 @findex fortran-comment-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 @vindex fortran-comment-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 The command @kbd{C-c ;} (@code{fortran-comment-region}) turns all the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 lines of the region into comments by inserting the string @samp{C$$$} at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 the front of each one. With a numeric arg, the region is turned back into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 live code by deleting @samp{C$$$} from the front of each line. You can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 control the string used for the comments by setting the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 @code{fortran-comment-region}. Note that here we have an example of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 command and a variable with the same name; the two uses of the name never
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 conflict because in Lisp and in Emacs it is always clear from the context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 which one is referred to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 @node Fortran Columns, Fortran Abbrev, Fortran Comments, Fortran
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 @subsection Columns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 @item C-c C-r
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 Displays a ``column ruler'' momentarily above the current line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 (@code{fortran-column-ruler}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 @item C-c C-w
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 Splits the current window horizontally so that it is 72 columns wide.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 This may help you avoid going over that limit (@code{fortran-window-create}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 @kindex C-c C-r (Fortran mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 @findex fortran-column-ruler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 The command @kbd{C-c C-r} (@code{fortran-column-ruler}) shows a column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 ruler above the current line. The comment ruler consists of two lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003 of text that show you the locations of columns with special significance
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 in Fortran programs. Square brackets show the limits of the columns for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 line numbers, and curly brackets show the limits of the columns for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 statement body. Column numbers appear above them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 Note that the column numbers count from zero, as always in XEmacs. As
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 a result, the numbers may not be those you are familiar with; but the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010 actual positions in the line are standard Fortran.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012 The text used to display the column ruler is the value of the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 @code{fortran-comment-ruler}. By changing this variable, you can change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 the display.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 @kindex C-c C-w (Fortran mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 @findex fortran-window-create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 For even more help, use @kbd{C-c C-w} (@code{fortran-window-create}), a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 command which splits the current window horizontally, resulting in a window 72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 columns wide. When you edit in this window, you can immediately see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 when a line gets too wide to be correct Fortran.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 @node Fortran Abbrev, , Fortran Columns, Fortran
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 @subsection Fortran Keyword Abbrevs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 Fortran mode provides many built-in abbrevs for common keywords and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 declarations. These are the same sort of abbrevs that you can define
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 yourself. To use them, you must turn on Abbrev mode. @pxref{Abbrevs}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 The built-in abbrevs are unusual in one way: they all start with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031 semicolon. You cannot normally use semicolon in an abbrev, but Fortran
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 mode makes this possible by changing the syntax of semicolon to ``word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033 constituent''.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 For example, one built-in Fortran abbrev is @samp{;c} for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 @samp{continue}. If you insert @samp{;c} and then insert a punctuation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 character such as a space or a newline, the @samp{;c} changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 automatically to @samp{continue}, provided Abbrev mode is enabled.@refill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 Type @samp{;?} or @samp{;C-h} to display a list of all built-in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 Fortran abbrevs and what they stand for.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 @node Asm Mode, , Fortran, Programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 @section Asm Mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 @cindex Asm mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 Asm mode is a major mode for editing files of assembler code. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 defines these commands:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 @table @kbd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 @item @key{TAB}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 @code{tab-to-tab-stop}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 @item @key{LFD}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 Insert a newline and then indent using @code{tab-to-tab-stop}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 @item :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 Insert a colon and then remove the indentation from before the label
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 preceding colon. Then do @code{tab-to-tab-stop}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 @item ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 Insert or align a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 The variable @code{asm-comment-char} specifies which character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 starts comments in assembler syntax.