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