Commit | Line | Data |
---|---|---|
8cf51b2c | 1 | @c This is part of the Emacs manual. |
95df8112 | 2 | @c Copyright (C) 2004-2011 Free Software Foundation, Inc. |
8cf51b2c GM |
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 | ||
74f0711b GM |
12 | @cindex Fortran fixed form and free form |
13 | @cindex Fortran 77 and Fortran 90, 95, 2003 | |
14 | @findex f90-mode | |
15 | @findex fortran-mode | |
16 | Fortran mode is meant for editing ``fixed form'' (and also ``tab | |
17 | format'') source code (normally Fortran 77). For editing more modern | |
18 | ``free form'' source code (Fortran 90, 95, 2003), use F90 mode | |
19 | (@code{f90-mode}). Emacs normally uses Fortran mode for files with | |
20 | extension @samp{.f}, @samp{.F} or @samp{.for}, and F90 mode for the | |
21 | extensions @samp{.f90} and @samp{.f95}. Customize | |
22 | @code{auto-mode-alist} to add more extensions. GNU Fortran supports | |
23 | both free and fixed form. This manual mainly documents Fortran mode, | |
24 | but the corresponding F90 mode features are mentioned when revelant. | |
25 | ||
8cf51b2c GM |
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 | |
74f0711b GM |
30 | proper Fortran continuation lines. Fortran mode also supports Hideshow |
31 | minor mode | |
32 | @iftex | |
33 | (@pxref{Hideshow,,, emacs, the Emacs Manual}), | |
34 | @end iftex | |
35 | @ifnottex | |
36 | (@pxref{Hideshow}), | |
37 | @end ifnottex | |
38 | and Imenu | |
39 | @iftex | |
40 | (@pxref{Imenu,,, emacs, the Emacs Manual}). | |
41 | @end iftex | |
42 | @ifnottex | |
43 | (@pxref{Imenu}). | |
44 | @end ifnottex | |
8cf51b2c GM |
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 | ||
8cf51b2c | 59 | @menu |
8838673e GM |
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. | |
8cf51b2c GM |
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 | |
74f0711b | 72 | ``defuns'' (Fortran subprograms---functions and subroutines, using the |
e1fbeef1 GM |
73 | commands @code{fortran-beginning-of-subprogram} and |
74 | @code{fortran-end-of-subprogram}; as well as modules for F90 mode), | |
75 | Fortran mode provides special commands to move by statements and other | |
76 | program units. | |
8cf51b2c GM |
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 | |
74f0711b GM |
98 | Move point forward to the start of the next code block, or the end of |
99 | the current block, whichever is encountered first. | |
8cf51b2c GM |
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 | ||
e1fbeef1 GM |
132 | The commands @code{fortran-beginning-of-subprogram} and |
133 | @code{fortran-end-of-subprogram} move to the start or end of the | |
74f0711b GM |
134 | current subprogram, respectively. The commands @code{fortran-mark-do} |
135 | and @code{fortran-mark-if} mark the end of the current @code{do} or | |
136 | @code{if} block, and move point to the start. | |
137 | ||
138 | ||
8cf51b2c GM |
139 | @node Fortran Indent |
140 | @subsection Fortran Indentation | |
141 | ||
74f0711b GM |
142 | Special commands and features are needed for indenting fixed (or tab) |
143 | form Fortran code in order to make sure various syntactic entities (line | |
144 | numbers, comment line indicators and continuation line flags) appear in | |
145 | the required columns. | |
8cf51b2c GM |
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 | |
74f0711b GM |
168 | Fill a comment block or statement (using @code{fortran-fill-paragraph} |
169 | or @code{fortran-fill-statement}). | |
8cf51b2c GM |
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 | |
74f0711b | 203 | Most Fortran 77 compilers allow two ways of writing continuation lines. |
8cf51b2c GM |
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 | |
74f0711b | 206 | form}. (In GNU Emacs we always count columns from 0; but note that |
8cf51b2c GM |
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 | |
74f0711b | 211 | continuation @dfn{tab format}. (Fortran 90 introduced ``free form,'' |
8cf51b2c GM |
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 | |
74f0711b GM |
224 | @code{fortran-tab-mode-default} (@code{nil} for fixed form, and |
225 | non-@code{nil} for tab format) is used. @samp{/t} | |
226 | (@code{fortran-tab-mode-string}) in the mode line indicates tab format | |
227 | is selected. Fortran mode sets the value of @code{indent-tabs-mode} | |
228 | accordingly. | |
8cf51b2c GM |
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 | |
74f0711b | 239 | editing in Fortran mode. In fixed form mode, the minimum column |
8cf51b2c GM |
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 | |
74f0711b | 324 | In Fortran 77, a numbered @samp{do} statement is ended by any statement |
8cf51b2c GM |
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 | |
74f0711b | 339 | Minimum indentation for Fortran statements when using fixed form |
8cf51b2c GM |
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 | |
74f0711b | 356 | line of code. In Fortran 77, the standard comment syntax requires an |
8cf51b2c GM |
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 | |
74f0711b GM |
361 | Fortran mode can also handle the Fortran 90 comment syntax where |
362 | comments start with @samp{!} and can follow other text. Because only | |
363 | some Fortran 77 compilers accept this syntax, Fortran mode will not | |
364 | insert such comments unless you have said in advance to do so. To do | |
365 | this, set the variable @code{fortran-comment-line-start} to @samp{"!"}. | |
366 | If you use an unusual value, you may also need to adjust | |
367 | @code{fortran-comment-line-start-skip}. | |
368 | ||
8cf51b2c GM |
369 | |
370 | @table @kbd | |
371 | @item M-; | |
87aae241 | 372 | Align comment or insert new comment (@code{comment-dwim}). |
8cf51b2c GM |
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 | ||
87aae241 GM |
382 | @kbd{M-;} in Fortran mode runs the standard @code{comment-dwim}. |
383 | This recognizes any kind of existing comment and aligns its text | |
384 | appropriately; if there is no existing comment, a comment is inserted | |
385 | and aligned. Inserting and aligning comments are not the same in | |
386 | Fortran mode as in other modes. | |
8cf51b2c GM |
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 | |
74f0711b | 409 | @code{fortran-minimum-statement-indent-fixed} for fixed form |
8cf51b2c GM |
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 | ||
bab23361 GM |
492 | @vindex fortran-line-length |
493 | In standard Fortran 77, anything beyond column 72 is ignored. | |
494 | Most compilers provide an option to change this (for example, | |
495 | @samp{-ffixed-line-length-N} in gfortran). Customize the variable | |
496 | @code{fortran-line-length} to change the line length in Fortran mode. | |
74f0711b GM |
497 | Anything beyond this point is font-locked as a comment. (Unless it is |
498 | inside a string: strings that extend beyond @code{fortran-line-length} | |
499 | will confuse font-lock.) | |
bab23361 | 500 | |
8cf51b2c GM |
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 | |
bab23361 GM |
506 | Split the current window horizontally temporarily so that it is |
507 | @code{fortran-line-length} columns wide | |
508 | (@code{fortran-window-create-momentarily}). This may help you avoid | |
509 | making lines longer than the character limit imposed by your Fortran | |
510 | compiler. | |
8cf51b2c | 511 | @item C-u C-c C-w |
bab23361 GM |
512 | Split the current window horizontally so that it is |
513 | @code{fortran-line-length} columns wide (@code{fortran-window-create}). | |
514 | You can then continue editing. | |
8cf51b2c | 515 | @item M-x fortran-strip-sequence-nos |
bab23361 | 516 | Delete all text in column @code{fortran-line-length} and beyond. |
8cf51b2c GM |
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 | |
bab23361 GM |
546 | splits the current window horizontally, making a window |
547 | @code{fortran-line-length} columns wide, so you can see any lines that | |
548 | are too long. Type a space to restore the normal width. | |
8cf51b2c GM |
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 | |
bab23361 GM |
559 | column @code{fortran-line-length} and beyond, on all lines in the |
560 | current buffer. This is the easiest way to get rid of old sequence | |
561 | numbers. | |
8cf51b2c GM |
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 | |
74f0711b | 577 | semicolon. For example, one built-in Fortran abbrev is @samp{;c} for |
8cf51b2c GM |
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. |