Next: , Previous: , Up: Fortran   [Contents][Index]


21.13.3 Comments

The usual Emacs comment commands assume that a comment can follow a line of code. In Fortran, the standard comment syntax requires an entire line to be just a comment. Therefore, Fortran mode replaces the standard Emacs comment commands and defines some new variables.

Fortran mode can also handle a non-standard comment syntax where comments start with ‘!’ and can follow other text. Because only some Fortran compilers accept this syntax, Fortran mode will not insert such comments unless you have specified to do so in advance by setting the variable comment-start to ‘"!"’ (see Variables).

M-;

Align comment or insert new comment (fortran-comment-indent).

C-x ;

Applies to nonstandard ‘!’ comments only.

C-c ;

Turn all lines of the region into comments, or (with arg) turn them back into real code (fortran-comment-region).

M-; in Fortran mode is redefined as the command fortran-comment-indent. Like the usual M-; command, it recognizes an existing comment and aligns its text appropriately. If there is no existing comment, a comment is inserted and aligned.

Inserting and aligning comments is not the same in Fortran mode as in other modes. When a new comment must be inserted, a full-line comment is inserted if the current line is blank. On a non-blank line, a non-standard ‘!’ comment is inserted if you previously specified you wanted to use them. Otherwise a full-line comment is inserted on a new line before the current line.

Non-standard ‘!’ comments are aligned like comments in other languages, but full-line comments are aligned differently. In a standard full-line comment, the comment delimiter itself must always appear in column zero. What can be aligned is the text within the comment. You can choose from three styles of alignment by setting the variable fortran-comment-indent-style to one of these values:

fixed

The text is aligned at a fixed column, which is the value of fortran-comment-line-column. This is the default.

relative

The text is aligned as if it were a line of code, but with an additional fortran-comment-line-column columns of indentation.

nil

Text in full-line columns is not moved automatically.

You can also specify the character to be used to indent within full-line comments by setting the variable fortran-comment-indent-char to the character you want to use.

Fortran mode introduces two variables comment-line-start and comment-line-start-skip, which do for full-line comments what comment-start and comment-start-skip do for ordinary text-following comments. Normally these are set properly by Fortran mode, so you do not need to change them.

The normal Emacs comment command C-x ; has not been redefined. It can therefore be used if you use ‘!’ comments, but is useless in Fortran mode otherwise.

The command C-c ; (fortran-comment-region) turns all the lines of the region into comments by inserting the string ‘C$$$’ at the front of each one. With a numeric arg, the region is turned back into live code by deleting ‘C$$$’ from the front of each line. You can control the string used for the comments by setting the variable fortran-comment-region. Note that here we have an example of a command and a variable with the same name; the two uses of the name never conflict because in Lisp and in Emacs it is always clear from the context which one is referred to.


Next: , Previous: , Up: Fortran   [Contents][Index]