Mercurial > emacs
annotate doc/emacs/fortran-xtra.texi @ 97683:02243cbabf8e
(Fortran): Change description of free form and
fixed form a bit. Mention hideshow and imenu.
(Fortran Motion): Mention fortran-end-of-subprogram,
fortran-beginning-of-subprogram, fortran-mark-do, fortran-mark-if.
(Fortran Indent): Minor re-word.
(ForIndent Commands): Mention fortran-fill-paragraph and
fortran-fill-statement.
(ForIndent Cont): Mention fortran-tab-mode-string.
(Fortran Comments): Mention fortran-comment-line-start-skip.
(Fortran Columns): Mention font-locking.
(Fortran Abbrev): Word syntax not relevant with new-style abbrev.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 23 Aug 2008 23:29:54 +0000 |
parents | 4b2311c2836f |
children | cb5d2387102c |
rev | line source |
---|---|
84241 | 1 @c This is part of the Emacs manual. |
87903 | 2 @c Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
84241 | 3 @c See file emacs.texi for copying conditions. |
4 @c | |
5 @c This file is included either in emacs-xtra.texi (when producing the | |
6 @c printed version) or in the main Emacs manual (for the on-line version). | |
7 @node Fortran | |
8 @section Fortran Mode | |
9 @cindex Fortran mode | |
10 @cindex mode, Fortran | |
11 | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
12 @cindex Fortran fixed form and free form |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
13 @cindex Fortran 77 and Fortran 90, 95, 2003 |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
14 @findex f90-mode |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
15 @findex fortran-mode |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
16 Fortran mode is meant for editing ``fixed form'' (and also ``tab |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
17 format'') source code (normally Fortran 77). For editing more modern |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
18 ``free form'' source code (Fortran 90, 95, 2003), use F90 mode |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
19 (@code{f90-mode}). Emacs normally uses Fortran mode for files with |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
20 extension @samp{.f}, @samp{.F} or @samp{.for}, and F90 mode for the |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
21 extensions @samp{.f90} and @samp{.f95}. Customize |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
22 @code{auto-mode-alist} to add more extensions. GNU Fortran supports |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
23 both free and fixed form. This manual mainly documents Fortran mode, |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
24 but the corresponding F90 mode features are mentioned when revelant. |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
25 |
84241 | 26 Fortran mode provides special motion commands for Fortran statements |
27 and subprograms, and indentation commands that understand Fortran | |
28 conventions of nesting, line numbers and continuation statements. | |
29 Fortran mode has support for Auto Fill mode that breaks long lines into | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
30 proper Fortran continuation lines. Fortran mode also supports Hideshow |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
31 minor mode |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
32 @iftex |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
33 (@pxref{Hideshow,,, emacs, the Emacs Manual}), |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
34 @end iftex |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
35 @ifnottex |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
36 (@pxref{Hideshow}), |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
37 @end ifnottex |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
38 and Imenu |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
39 @iftex |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
40 (@pxref{Imenu,,, emacs, the Emacs Manual}). |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
41 @end iftex |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
42 @ifnottex |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
43 (@pxref{Imenu}). |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
44 @end ifnottex |
84241 | 45 |
46 Special commands for comments are provided because Fortran comments | |
47 are unlike those of other languages. Built-in abbrevs optionally save | |
48 typing when you insert Fortran keywords. | |
49 | |
50 Use @kbd{M-x fortran-mode} to switch to this major mode. This | |
51 command runs the hook @code{fortran-mode-hook}. | |
52 @iftex | |
53 @xref{Hooks,,, emacs, the Emacs Manual}. | |
54 @end iftex | |
55 @ifnottex | |
56 @xref{Hooks}. | |
57 @end ifnottex | |
58 | |
59 @menu | |
60 * Motion: Fortran Motion. Moving point by statements or subprograms. | |
61 * Indent: Fortran Indent. Indentation commands for Fortran. | |
62 * Comments: Fortran Comments. Inserting and aligning comments. | |
63 * Autofill: Fortran Autofill. Auto fill support for Fortran. | |
64 * Columns: Fortran Columns. Measuring columns for valid Fortran. | |
65 * Abbrev: Fortran Abbrev. Built-in abbrevs for Fortran keywords. | |
66 @end menu | |
67 | |
68 @node Fortran Motion | |
69 @subsection Motion Commands | |
70 | |
71 In addition to the normal commands for moving by and operating on | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
72 ``defuns'' (Fortran subprograms---functions and subroutines, using the |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
73 commands @code{fortran-end-of-subprogram} and |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
74 @code{fortran-beginning-of-subprogram}; as well as modules for F90 |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
75 mode), Fortran mode provides special commands to move by statements and |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
76 other program units. |
84241 | 77 |
78 @table @kbd | |
79 @kindex C-c C-n @r{(Fortran mode)} | |
80 @findex fortran-next-statement | |
81 @findex f90-next-statement | |
82 @item C-c C-n | |
83 Move to the beginning of the next statement | |
84 (@code{fortran-next-statement}/@code{f90-next-statement}). | |
85 | |
86 @kindex C-c C-p @r{(Fortran mode)} | |
87 @findex fortran-previous-statement | |
88 @findex f90-previous-statement | |
89 @item C-c C-p | |
90 Move to the beginning of the previous statement | |
91 (@code{fortran-previous-statement}/@code{f90-previous-statement}). | |
92 If there is no previous statement (i.e. if called from the first | |
93 statement in the buffer), move to the start of the buffer. | |
94 | |
95 @kindex C-c C-e @r{(F90 mode)} | |
96 @findex f90-next-block | |
97 @item C-c C-e | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
98 Move point forward to the start of the next code block, or the end of |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
99 the current block, whichever is encountered first. |
84241 | 100 (@code{f90-next-block}). A code block is a subroutine, |
101 @code{if}--@code{endif} statement, and so forth. This command exists | |
102 for F90 mode only, not Fortran mode. With a numeric argument, this | |
103 moves forward that many blocks. | |
104 | |
105 @kindex C-c C-a @r{(F90 mode)} | |
106 @findex f90-previous-block | |
107 @item C-c C-a | |
108 Move point backward to the previous code block | |
109 (@code{f90-previous-block}). This is like @code{f90-next-block}, but | |
110 moves backwards. | |
111 | |
112 @kindex C-M-n @r{(Fortran mode)} | |
113 @findex fortran-end-of-block | |
114 @findex f90-end-of-block | |
115 @item C-M-n | |
116 Move to the end of the current code block | |
117 (@code{fortran-end-of-block}/@code{f90-end-of-block}). With a numeric | |
118 argument, move forward that number of blocks. The mark is set before | |
119 moving point. The F90 mode version of this command checks for | |
120 consistency of block types and labels (if present), but it does not | |
121 check the outermost block since that may be incomplete. | |
122 | |
123 @kindex C-M-p @r{(Fortran mode)} | |
124 @findex fortran-beginning-of-block | |
125 @findex f90-beginning-of-block | |
126 @item C-M-p | |
127 Move to the start of the current code block | |
128 (@code{fortran-beginning-of-block}/@code{f90-beginning-of-block}). This | |
129 is like @code{fortran-end-of-block}, but moves backwards. | |
130 @end table | |
131 | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
132 The commands @code{fortran-end-of-subprogram} and |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
133 @code{fortran-beginning-of-subprogram} move to the end or start of the |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
134 current subprogram, respectively. The commands @code{fortran-mark-do} |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
135 and @code{fortran-mark-if} mark the end of the current @code{do} or |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
136 @code{if} block, and move point to the start. |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
137 |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
138 |
84241 | 139 @node Fortran Indent |
140 @subsection Fortran Indentation | |
141 | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
142 Special commands and features are needed for indenting fixed (or tab) |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
143 form Fortran code in order to make sure various syntactic entities (line |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
144 numbers, comment line indicators and continuation line flags) appear in |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
145 the required columns. |
84241 | 146 |
147 @menu | |
148 * Commands: ForIndent Commands. Commands for indenting and filling Fortran. | |
149 * Contline: ForIndent Cont. How continuation lines indent. | |
150 * Numbers: ForIndent Num. How line numbers auto-indent. | |
151 * Conv: ForIndent Conv. Conventions you must obey to avoid trouble. | |
152 * Vars: ForIndent Vars. Variables controlling Fortran indent style. | |
153 @end menu | |
154 | |
155 @node ForIndent Commands | |
156 @subsubsection Fortran Indentation and Filling Commands | |
157 | |
158 @table @kbd | |
159 @item C-M-j | |
160 Break the current line at point and set up a continuation line | |
161 (@code{fortran-split-line}). | |
162 @item M-^ | |
163 Join this line to the previous line (@code{fortran-join-line}). | |
164 @item C-M-q | |
165 Indent all the lines of the subprogram point is in | |
166 (@code{fortran-indent-subprogram}). | |
167 @item M-q | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
168 Fill a comment block or statement (using @code{fortran-fill-paragraph} |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
169 or @code{fortran-fill-statement}). |
84241 | 170 @end table |
171 | |
172 @kindex C-M-q @r{(Fortran mode)} | |
173 @findex fortran-indent-subprogram | |
174 The key @kbd{C-M-q} runs @code{fortran-indent-subprogram}, a command | |
175 to reindent all the lines of the Fortran subprogram (function or | |
176 subroutine) containing point. | |
177 | |
178 @kindex C-M-j @r{(Fortran mode)} | |
179 @findex fortran-split-line | |
180 The key @kbd{C-M-j} runs @code{fortran-split-line}, which splits | |
181 a line in the appropriate fashion for Fortran. In a non-comment line, | |
182 the second half becomes a continuation line and is indented | |
183 accordingly. In a comment line, both halves become separate comment | |
184 lines. | |
185 | |
186 @kindex M-^ @r{(Fortran mode)} | |
187 @kindex C-c C-d @r{(Fortran mode)} | |
188 @findex fortran-join-line | |
189 @kbd{M-^} or @kbd{C-c C-d} runs the command @code{fortran-join-line}, | |
190 which joins a continuation line back to the previous line, roughly as | |
191 the inverse of @code{fortran-split-line}. The point must be on a | |
192 continuation line when this command is invoked. | |
193 | |
194 @kindex M-q @r{(Fortran mode)} | |
195 @kbd{M-q} in Fortran mode fills the comment block or statement that | |
196 point is in. This removes any excess statement continuations. | |
197 | |
198 @node ForIndent Cont | |
199 @subsubsection Continuation Lines | |
200 @cindex Fortran continuation lines | |
201 | |
202 @vindex fortran-continuation-string | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
203 Most Fortran 77 compilers allow two ways of writing continuation lines. |
84241 | 204 If the first non-space character on a line is in column 5, then that |
205 line is a continuation of the previous line. We call this @dfn{fixed | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
206 form}. (In GNU Emacs we always count columns from 0; but note that |
84241 | 207 the Fortran standard counts from 1.) The variable |
208 @code{fortran-continuation-string} specifies what character to put in | |
209 column 5. A line that starts with a tab character followed by any digit | |
210 except @samp{0} is also a continuation line. We call this style of | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
211 continuation @dfn{tab format}. (Fortran 90 introduced ``free form,'' |
84241 | 212 with another style of continuation lines). |
213 | |
214 @vindex indent-tabs-mode @r{(Fortran mode)} | |
215 @vindex fortran-analyze-depth | |
216 @vindex fortran-tab-mode-default | |
217 Fortran mode can use either style of continuation line. When you | |
218 enter Fortran mode, it tries to deduce the proper continuation style | |
219 automatically from the buffer contents. It does this by scanning up to | |
220 @code{fortran-analyze-depth} (default 100) lines from the start of the | |
221 buffer. The first line that begins with either a tab character or six | |
222 spaces determines the choice. If the scan fails (for example, if the | |
223 buffer is new and therefore empty), the value of | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
224 @code{fortran-tab-mode-default} (@code{nil} for fixed form, and |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
225 non-@code{nil} for tab format) is used. @samp{/t} |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
226 (@code{fortran-tab-mode-string}) in the mode line indicates tab format |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
227 is selected. Fortran mode sets the value of @code{indent-tabs-mode} |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
228 accordingly. |
84241 | 229 |
230 If the text on a line starts with the Fortran continuation marker | |
231 @samp{$}, or if it begins with any non-whitespace character in column | |
232 5, Fortran mode treats it as a continuation line. When you indent a | |
233 continuation line with @key{TAB}, it converts the line to the current | |
234 continuation style. When you split a Fortran statement with | |
235 @kbd{C-M-j}, the continuation marker on the newline is created according | |
236 to the continuation style. | |
237 | |
238 The setting of continuation style affects several other aspects of | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
239 editing in Fortran mode. In fixed form mode, the minimum column |
84241 | 240 number for the body of a statement is 6. Lines inside of Fortran |
241 blocks that are indented to larger column numbers always use only the | |
242 space character for whitespace. In tab format mode, the minimum | |
243 column number for the statement body is 8, and the whitespace before | |
244 column 8 must always consist of one tab character. | |
245 | |
246 @node ForIndent Num | |
247 @subsubsection Line Numbers | |
248 | |
249 If a number is the first non-whitespace in the line, Fortran | |
250 indentation assumes it is a line number and moves it to columns 0 | |
251 through 4. (Columns always count from 0 in GNU Emacs.) | |
252 | |
253 @vindex fortran-line-number-indent | |
254 Line numbers of four digits or less are normally indented one space. | |
255 The variable @code{fortran-line-number-indent} controls this; it | |
256 specifies the maximum indentation a line number can have. The default | |
257 value of the variable is 1. Fortran mode tries to prevent line number | |
258 digits passing column 4, reducing the indentation below the specified | |
259 maximum if necessary. If @code{fortran-line-number-indent} has the | |
260 value 5, line numbers are right-justified to end in column 4. | |
261 | |
262 @vindex fortran-electric-line-number | |
263 Simply inserting a line number is enough to indent it according to | |
264 these rules. As each digit is inserted, the indentation is recomputed. | |
265 To turn off this feature, set the variable | |
266 @code{fortran-electric-line-number} to @code{nil}. | |
267 | |
268 | |
269 @node ForIndent Conv | |
270 @subsubsection Syntactic Conventions | |
271 | |
272 Fortran mode assumes that you follow certain conventions that simplify | |
273 the task of understanding a Fortran program well enough to indent it | |
274 properly: | |
275 | |
276 @itemize @bullet | |
277 @item | |
278 Two nested @samp{do} loops never share a @samp{continue} statement. | |
279 | |
280 @item | |
281 Fortran keywords such as @samp{if}, @samp{else}, @samp{then}, @samp{do} | |
282 and others are written without embedded whitespace or line breaks. | |
283 | |
284 Fortran compilers generally ignore whitespace outside of string | |
285 constants, but Fortran mode does not recognize these keywords if they | |
286 are not contiguous. Constructs such as @samp{else if} or @samp{end do} | |
287 are acceptable, but the second word should be on the same line as the | |
288 first and not on a continuation line. | |
289 @end itemize | |
290 | |
291 @noindent | |
292 If you fail to follow these conventions, the indentation commands may | |
293 indent some lines unaesthetically. However, a correct Fortran program | |
294 retains its meaning when reindented even if the conventions are not | |
295 followed. | |
296 | |
297 @node ForIndent Vars | |
298 @subsubsection Variables for Fortran Indentation | |
299 | |
300 @vindex fortran-do-indent | |
301 @vindex fortran-if-indent | |
302 @vindex fortran-structure-indent | |
303 @vindex fortran-continuation-indent | |
304 @vindex fortran-check-all-num@dots{} | |
305 @vindex fortran-minimum-statement-indent@dots{} | |
306 Several additional variables control how Fortran indentation works: | |
307 | |
308 @table @code | |
309 @item fortran-do-indent | |
310 Extra indentation within each level of @samp{do} statement (default 3). | |
311 | |
312 @item fortran-if-indent | |
313 Extra indentation within each level of @samp{if}, @samp{select case}, or | |
314 @samp{where} statements (default 3). | |
315 | |
316 @item fortran-structure-indent | |
317 Extra indentation within each level of @samp{structure}, @samp{union}, | |
318 @samp{map}, or @samp{interface} statements (default 3). | |
319 | |
320 @item fortran-continuation-indent | |
321 Extra indentation for bodies of continuation lines (default 5). | |
322 | |
323 @item fortran-check-all-num-for-matching-do | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
324 In Fortran 77, a numbered @samp{do} statement is ended by any statement |
84241 | 325 with a matching line number. It is common (but not compulsory) to use a |
326 @samp{continue} statement for this purpose. If this variable has a | |
327 non-@code{nil} value, indenting any numbered statement must check for a | |
328 @samp{do} that ends there. If you always end @samp{do} statements with | |
329 a @samp{continue} line (or if you use the more modern @samp{enddo}), | |
330 then you can speed up indentation by setting this variable to | |
331 @code{nil}. The default is @code{nil}. | |
332 | |
333 @item fortran-blink-matching-if | |
334 If this is @code{t}, indenting an @samp{endif} (or @samp{enddo} | |
335 statement moves the cursor momentarily to the matching @samp{if} (or | |
336 @samp{do}) statement to show where it is. The default is @code{nil}. | |
337 | |
338 @item fortran-minimum-statement-indent-fixed | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
339 Minimum indentation for Fortran statements when using fixed form |
84241 | 340 continuation line style. Statement bodies are never indented less than |
341 this much. The default is 6. | |
342 | |
343 @item fortran-minimum-statement-indent-tab | |
344 Minimum indentation for Fortran statements for tab format continuation line | |
345 style. Statement bodies are never indented less than this much. The | |
346 default is 8. | |
347 @end table | |
348 | |
349 The variables controlling the indentation of comments are described in | |
350 the following section. | |
351 | |
352 @node Fortran Comments | |
353 @subsection Fortran Comments | |
354 | |
355 The usual Emacs comment commands assume that a comment can follow a | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
356 line of code. In Fortran 77, the standard comment syntax requires an |
84241 | 357 entire line to be just a comment. Therefore, Fortran mode replaces the |
358 standard Emacs comment commands and defines some new variables. | |
359 | |
360 @vindex fortran-comment-line-start | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
361 Fortran mode can also handle the Fortran 90 comment syntax where |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
362 comments start with @samp{!} and can follow other text. Because only |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
363 some Fortran 77 compilers accept this syntax, Fortran mode will not |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
364 insert such comments unless you have said in advance to do so. To do |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
365 this, set the variable @code{fortran-comment-line-start} to @samp{"!"}. |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
366 If you use an unusual value, you may also need to adjust |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
367 @code{fortran-comment-line-start-skip}. |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
368 |
84241 | 369 |
370 @table @kbd | |
371 @item M-; | |
97590
4b2311c2836f
(Fortran Comments): Replace fortran-indent-comment with comment-dwim.
Glenn Morris <rgm@gnu.org>
parents:
97588
diff
changeset
|
372 Align comment or insert new comment (@code{comment-dwim}). |
84241 | 373 |
374 @item C-x ; | |
375 Applies to nonstandard @samp{!} comments only. | |
376 | |
377 @item C-c ; | |
378 Turn all lines of the region into comments, or (with argument) turn them back | |
379 into real code (@code{fortran-comment-region}). | |
380 @end table | |
381 | |
97590
4b2311c2836f
(Fortran Comments): Replace fortran-indent-comment with comment-dwim.
Glenn Morris <rgm@gnu.org>
parents:
97588
diff
changeset
|
382 @kbd{M-;} in Fortran mode runs the standard @code{comment-dwim}. |
4b2311c2836f
(Fortran Comments): Replace fortran-indent-comment with comment-dwim.
Glenn Morris <rgm@gnu.org>
parents:
97588
diff
changeset
|
383 This recognizes any kind of existing comment and aligns its text |
4b2311c2836f
(Fortran Comments): Replace fortran-indent-comment with comment-dwim.
Glenn Morris <rgm@gnu.org>
parents:
97588
diff
changeset
|
384 appropriately; if there is no existing comment, a comment is inserted |
4b2311c2836f
(Fortran Comments): Replace fortran-indent-comment with comment-dwim.
Glenn Morris <rgm@gnu.org>
parents:
97588
diff
changeset
|
385 and aligned. Inserting and aligning comments are not the same in |
4b2311c2836f
(Fortran Comments): Replace fortran-indent-comment with comment-dwim.
Glenn Morris <rgm@gnu.org>
parents:
97588
diff
changeset
|
386 Fortran mode as in other modes. |
84241 | 387 |
388 When a new comment must be inserted, if the current line is blank, a | |
389 full-line comment is inserted. On a non-blank line, a nonstandard @samp{!} | |
390 comment is inserted if you have said you want to use them. Otherwise a | |
391 full-line comment is inserted on a new line before the current line. | |
392 | |
393 Nonstandard @samp{!} comments are aligned like comments in other | |
394 languages, but full-line comments are different. In a standard full-line | |
395 comment, the comment delimiter itself must always appear in column zero. | |
396 What can be aligned is the text within the comment. You can choose from | |
397 three styles of alignment by setting the variable | |
398 @code{fortran-comment-indent-style} to one of these values: | |
399 | |
400 @vindex fortran-comment-indent-style | |
401 @vindex fortran-comment-line-extra-indent | |
402 @table @code | |
403 @item fixed | |
404 Align the text at a fixed column, which is the sum of | |
405 @code{fortran-comment-line-extra-indent} and the minimum statement | |
406 indentation. This is the default. | |
407 | |
408 The minimum statement indentation is | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
409 @code{fortran-minimum-statement-indent-fixed} for fixed form |
84241 | 410 continuation line style and @code{fortran-minimum-statement-indent-tab} |
411 for tab format style. | |
412 | |
413 @item relative | |
414 Align the text as if it were a line of code, but with an additional | |
415 @code{fortran-comment-line-extra-indent} columns of indentation. | |
416 | |
417 @item nil | |
418 Don't move text in full-line comments automatically. | |
419 @end table | |
420 | |
421 @vindex fortran-comment-indent-char | |
422 In addition, you can specify the character to be used to indent within | |
423 full-line comments by setting the variable | |
424 @code{fortran-comment-indent-char} to the single-character string you want | |
425 to use. | |
426 | |
427 @vindex fortran-directive-re | |
428 Compiler directive lines, or preprocessor lines, have much the same | |
429 appearance as comment lines. It is important, though, that such lines | |
430 never be indented at all, no matter what the value of | |
431 @code{fortran-comment-indent-style}. The variable | |
432 @code{fortran-directive-re} is a regular expression that specifies which | |
433 lines are directives. Matching lines are never indented, and receive | |
434 distinctive font-locking. | |
435 | |
436 The normal Emacs comment command @kbd{C-x ;} has not been redefined. If | |
437 you use @samp{!} comments, this command can be used with them. Otherwise | |
438 it is useless in Fortran mode. | |
439 | |
440 @kindex C-c ; @r{(Fortran mode)} | |
441 @findex fortran-comment-region | |
442 @vindex fortran-comment-region | |
443 The command @kbd{C-c ;} (@code{fortran-comment-region}) turns all the | |
444 lines of the region into comments by inserting the string @samp{C$$$} at | |
445 the front of each one. With a numeric argument, it turns the region | |
446 back into live code by deleting @samp{C$$$} from the front of each line | |
447 in it. The string used for these comments can be controlled by setting | |
448 the variable @code{fortran-comment-region}. Note that here we have an | |
449 example of a command and a variable with the same name; these two uses | |
450 of the name never conflict because in Lisp and in Emacs it is always | |
451 clear from the context which one is meant. | |
452 | |
453 @node Fortran Autofill | |
454 @subsection Auto Fill in Fortran Mode | |
455 | |
456 Fortran mode has specialized support for Auto Fill mode, which is a | |
457 minor mode that automatically splits statements as you insert them | |
458 when they become too wide. Splitting a statement involves making | |
459 continuation lines using @code{fortran-continuation-string} | |
460 (@pxref{ForIndent Cont}). This splitting happens when you type | |
461 @key{SPC}, @key{RET}, or @key{TAB}, and also in the Fortran | |
462 indentation commands. You activate Auto Fill in Fortran mode in the | |
463 normal way. | |
464 @iftex | |
465 @xref{Auto Fill,,, emacs, the Emacs Manual}. | |
466 @end iftex | |
467 @ifnottex | |
468 @xref{Auto Fill}. | |
469 @end ifnottex | |
470 | |
471 @vindex fortran-break-before-delimiters | |
472 Auto Fill breaks lines at spaces or delimiters when the lines get | |
473 longer than the desired width (the value of @code{fill-column}). The | |
474 delimiters (besides whitespace) that Auto Fill can break at are | |
475 @samp{+}, @samp{-}, @samp{/}, @samp{*}, @samp{=}, @samp{<}, @samp{>}, | |
476 and @samp{,}. The line break comes after the delimiter if the | |
477 variable @code{fortran-break-before-delimiters} is @code{nil}. | |
478 Otherwise (and by default), the break comes before the delimiter. | |
479 | |
480 To enable Auto Fill in all Fortran buffers, add | |
481 @code{turn-on-auto-fill} to @code{fortran-mode-hook}. | |
482 @iftex | |
483 @xref{Hooks,,, emacs, the Emacs Manual}. | |
484 @end iftex | |
485 @ifnottex | |
486 @xref{Hooks}. | |
487 @end ifnottex | |
488 | |
489 @node Fortran Columns | |
490 @subsection Checking Columns in Fortran | |
491 | |
97588
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
492 @vindex fortran-line-length |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
493 In standard Fortran 77, anything beyond column 72 is ignored. |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
494 Most compilers provide an option to change this (for example, |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
495 @samp{-ffixed-line-length-N} in gfortran). Customize the variable |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
496 @code{fortran-line-length} to change the line length in Fortran mode. |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
497 Anything beyond this point is font-locked as a comment. (Unless it is |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
498 inside a string: strings that extend beyond @code{fortran-line-length} |
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
499 will confuse font-lock.) |
97588
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
500 |
84241 | 501 @table @kbd |
502 @item C-c C-r | |
503 Display a ``column ruler'' momentarily above the current line | |
504 (@code{fortran-column-ruler}). | |
505 @item C-c C-w | |
97588
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
506 Split the current window horizontally temporarily so that it is |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
507 @code{fortran-line-length} columns wide |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
508 (@code{fortran-window-create-momentarily}). This may help you avoid |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
509 making lines longer than the character limit imposed by your Fortran |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
510 compiler. |
84241 | 511 @item C-u C-c C-w |
97588
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
512 Split the current window horizontally so that it is |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
513 @code{fortran-line-length} columns wide (@code{fortran-window-create}). |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
514 You can then continue editing. |
84241 | 515 @item M-x fortran-strip-sequence-nos |
97588
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
516 Delete all text in column @code{fortran-line-length} and beyond. |
84241 | 517 @end table |
518 | |
519 @kindex C-c C-r @r{(Fortran mode)} | |
520 @findex fortran-column-ruler | |
521 The command @kbd{C-c C-r} (@code{fortran-column-ruler}) shows a column | |
522 ruler momentarily above the current line. The comment ruler is two lines | |
523 of text that show you the locations of columns with special significance in | |
524 Fortran programs. Square brackets show the limits of the columns for line | |
525 numbers, and curly brackets show the limits of the columns for the | |
526 statement body. Column numbers appear above them. | |
527 | |
528 Note that the column numbers count from zero, as always in GNU Emacs. | |
529 As a result, the numbers may be one less than those you are familiar | |
530 with; but the positions they indicate in the line are standard for | |
531 Fortran. | |
532 | |
533 @vindex fortran-column-ruler-fixed | |
534 @vindex fortran-column-ruler-tabs | |
535 The text used to display the column ruler depends on the value of the | |
536 variable @code{indent-tabs-mode}. If @code{indent-tabs-mode} is | |
537 @code{nil}, then the value of the variable | |
538 @code{fortran-column-ruler-fixed} is used as the column ruler. | |
539 Otherwise, the value of the variable @code{fortran-column-ruler-tab} is | |
540 displayed. By changing these variables, you can change the column ruler | |
541 display. | |
542 | |
543 @kindex C-c C-w @r{(Fortran mode)} | |
544 @findex fortran-window-create-momentarily | |
545 @kbd{C-c C-w} (@code{fortran-window-create-momentarily}) temporarily | |
97588
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
546 splits the current window horizontally, making a window |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
547 @code{fortran-line-length} columns wide, so you can see any lines that |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
548 are too long. Type a space to restore the normal width. |
84241 | 549 |
550 @kindex C-u C-c C-w @r{(Fortran mode)} | |
551 @findex fortran-window-create | |
552 You can also split the window horizontally and continue editing with | |
553 the split in place. To do this, use @kbd{C-u C-c C-w} (@code{M-x | |
554 fortran-window-create}). By editing in this window you can | |
555 immediately see when you make a line too wide to be correct Fortran. | |
556 | |
557 @findex fortran-strip-sequence-nos | |
558 The command @kbd{M-x fortran-strip-sequence-nos} deletes all text in | |
97588
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
559 column @code{fortran-line-length} and beyond, on all lines in the |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
560 current buffer. This is the easiest way to get rid of old sequence |
a32c3ff6e2b1
(Fortran Columns): Document `fortran-line-length'.
Glenn Morris <rgm@gnu.org>
parents:
87903
diff
changeset
|
561 numbers. |
84241 | 562 |
563 @node Fortran Abbrev | |
564 @subsection Fortran Keyword Abbrevs | |
565 | |
566 Fortran mode provides many built-in abbrevs for common keywords and | |
567 declarations. These are the same sort of abbrev that you can define | |
568 yourself. To use them, you must turn on Abbrev mode. | |
569 @iftex | |
570 @xref{Abbrevs,,, emacs, the Emacs Manual}. | |
571 @end iftex | |
572 @ifnottex | |
573 @xref{Abbrevs}. | |
574 @end ifnottex | |
575 | |
576 The built-in abbrevs are unusual in one way: they all start with a | |
97683
02243cbabf8e
(Fortran): Change description of free form and
Glenn Morris <rgm@gnu.org>
parents:
97590
diff
changeset
|
577 semicolon. For example, one built-in Fortran abbrev is @samp{;c} for |
84241 | 578 @samp{continue}. If you insert @samp{;c} and then insert a punctuation |
579 character such as a space or a newline, the @samp{;c} expands automatically | |
580 to @samp{continue}, provided Abbrev mode is enabled.@refill | |
581 | |
582 Type @samp{;?} or @samp{;C-h} to display a list of all the built-in | |
583 Fortran abbrevs and what they stand for. | |
584 | |
585 @ignore | |
586 arch-tag: 23ed7c36-1517-4646-9235-2d5ade5f06f6 | |
587 @end ignore |