File: f90.el.html
Major mode for editing F90 programs in FREE FORMAT.
The minor language revision F95 is also supported (with font-locking). Some/many (?) aspects of F2003 are supported. Some aspects of F2008 are supported.
Knows about continuation lines, named structured statements, and other features in F90 including HPF (High Performance Fortran) structures. The basic feature provides accurate indentation of F90 programs. In addition, there are many more features like automatic matching of all end statements, an auto-fill function to break long lines, a join-lines function which joins continued lines, etc.
To facilitate typing, a fairly complete list of abbreviations is provided. All abbreviations begin with the backquote character "`" For example, `i expands to integer (if abbrev-mode is on).
There are two separate features for altering the appearance of code:
1) Upcasing or capitalizing of all keywords.
2) Colors/fonts using font-lock-mode.
Automatic upcase or downcase of keywords is controlled by the variable
f90-auto-keyword-case.
The indentations of lines starting with ! is determined by the first of the following matches (values in the left column are the defaults):
start-string/regexp indent variable holding start-string/regexp
!!! 0
!hpf\\$ (re) 0 f90-directive-comment-re
!!$ 0 f90-comment-region
! (re) as code f90-indented-comment-re
default comment-column
Ex: Here is the result of 3 different settings of f90-indented-comment-re
f90-indented-comment-re !-indentation !!-indentation
! as code as code
!! comment-column as code
![^!] as code comment-column
Trailing comments are indented to comment-column with indent-for-comment.
The function f90-comment-region toggles insertion of
the variable f90-comment-region in every line of the region.
One common convention for free vs. fixed format is that free format
files have the ending ".f90" or ".f95" while fixed format files have
the ending ".f". Emacs automatically loads Fortran files in the
appropriate mode based on extension. You can modify this by
adjusting the variable auto-mode-alist.
For example:
(add-to-list 'auto-mode-alist '("\\\\.f\\\\'" . f90-mode))
Once you have entered f90-mode, you can get more info by using the command describe-mode (C-h m). For help use C-h f <Name of function you want described>, or C-h v <Name of variable you want described>.
To customize f90-mode for your taste, use, for example:
(you don't have to specify values for all the parameters below)
(add-hook 'f90-mode-hook
;; These are the default values.
(lambda () (setq f90-do-indent 3
f90-if-indent 3
f90-type-indent 3
f90-program-indent 2
f90-continuation-indent 5
f90-comment-region "!!$"
f90-directive-comment-re "!hpf\\\\$"
f90-indented-comment-re "!"
f90-break-delimiters "[-+\\\\*/><=,% \\t]"
f90-break-before-delimiters t
f90-beginning-ampersand t
f90-smart-end 'blink
f90-auto-keyword-case nil
f90-leave-line-no nil
indent-tabs-mode nil
f90-font-lock-keywords f90-font-lock-keywords-2
)
;; These are not default.
(abbrev-mode 1) ; turn on abbreviation mode
(f90-add-imenu-menu) ; extra menu with functions etc.
(if f90-auto-keyword-case ; change case of all keywords on startup
(f90-change-keywords f90-auto-keyword-case))))
in your init file. You can also customize the lists
f90-font-lock-keywords, etc.
The auto-fill and abbreviation minor modes are accessible from the F90 menu, or by using M-x auto-fill-mode and M-x abbrev-mode, respectively.
Remarks
1) Line numbers are by default left-justified. If f90-leave-line-no is
non-nil, the line numbers are never touched.
2) Multi-; statements like "do i=1,20 ; j=j+i ; end do" are not handled
correctly, but I imagine them to be rare.
3) For FIXED FORMAT code, use fortran mode.
4) Preprocessor directives, i.e., lines starting with # are left-justified
and are untouched by all case-changing commands. There is, at present, no
mechanism for treating multi-line directives (continued by \ ).
5) f77 do-loops do 10 i=.. ; ; 10 continue are not correctly indented.
You are urged to use f90-do loops (with labels if you wish).
List of user commands
f90-previous-statement f90-next-statement
f90-beginning-of-subprogram f90-end-of-subprogram f90-mark-subprogram
f90-comment-region
f90-indent-line f90-indent-new-line
f90-indent-region (can be called by calling indent-region)
f90-indent-subprogram
f90-break-line f90-join-lines
f90-fill-region f90-fill-paragraph
f90-insert-end
f90-upcase-keywords f90-upcase-region-keywords
f90-downcase-keywords f90-downcase-region-keywords
f90-capitalize-keywords f90-capitalize-region-keywords
f90-add-imenu-menu
f90-font-lock-1, f90-font-lock-2, f90-font-lock-3, f90-font-lock-4
Original author's thanks Thanks to all the people who have tested the mode. Special thanks to Jens Bloch Helmers for encouraging me to write this code, for creative suggestions as well as for the lists of hpf-commands. Also thanks to the authors of the fortran and pascal modes, on which some of this code is built.
Defined variables (47)
f90-associate-indent | Extra indentation applied to ASSOCIATE blocks. |
f90-auto-keyword-case | Automatic case conversion of keywords. |
f90-beginning-ampersand | Non-nil gives automatic insertion of ‘&’ at start of continuation line. |
f90-blocks-re | Regexp potentially indicating a "block" of F90 code. |
f90-break-before-delimiters | Non-nil causes ‘f90-do-auto-fill’ to break lines before delimiters. |
f90-break-delimiters | Regexp matching delimiter characters at which lines may be broken. |
f90-cache-position | Temporary position used to speed up region operations. |
f90-comment-region | String inserted by M-x f90-comment-region at start of each line in region. |
f90-constants-re | Regexp for Fortran intrinsic constants. |
f90-continuation-indent | Extra indentation applied to continuation lines. |
f90-critical-indent | Extra indentation applied to BLOCK, CRITICAL blocks. |
f90-directive-comment-re | Regexp of comment-like directive like "!HPF\\$", not to be indented. |
f90-do-indent | Extra indentation applied to DO blocks. |
f90-else-like-re | Regexp matching an ELSE IF, ELSEWHERE, CASE, CLASS/TYPE IS statement. |
f90-end-associate-re | Regexp matching the end of an ASSOCIATE block. |
f90-end-block-optional-name | Block types where including the name in the end statement is optional. |
f90-end-block-re | Regexp matching the end of an F90 "block", from the line start. |
f90-end-if-re | Regexp matching the end of an IF, SELECT, WHERE, FORALL block. |
f90-end-type-re | Regexp matching the end of a TYPE, ENUM, INTERFACE, BLOCK DATA section. |
f90-font-lock-keywords | Default expressions to highlight in F90 mode. |
f90-font-lock-keywords-1 | This does fairly subdued highlighting of comments and function calls. |
f90-font-lock-keywords-2 | Highlights declarations, do-loops and other constructs. |
f90-font-lock-keywords-3 | Highlights all F90 keywords and intrinsic procedures. |
f90-font-lock-keywords-4 | Highlights all F90 and HPF keywords and constants. |
f90-hpf-keywords-re | Regexp for all HPF keywords, procedures and directives. |
f90-if-indent | Extra indentation applied to IF, SELECT CASE, WHERE and FORALL blocks. |
f90-imenu-generic-expression | Value for ‘imenu-generic-expression’ in F90 mode. |
f90-indented-comment-re | Regexp matching comments to indent as code. |
f90-keywords-level-3-re | Keyword-regexp for font-lock level >= 3. |
f90-keywords-re | Regexp used by the function ‘f90-change-keywords’. |
f90-leave-line-no | If non-nil, line numbers are not left justified. |
f90-menu | Menu for F90 mode. |
f90-mode-abbrev-table | Abbrev table for F90 mode. |
f90-mode-hook | Hook run when entering F90 mode. |
f90-mode-map | Keymap used in F90 mode. |
f90-mode-syntax-table | Syntax table used in F90 mode. |
f90-no-break-re | Regexp specifying two-character tokens not to split when breaking lines. |
f90-operators-re | Regexp matching intrinsic operators. |
f90-procedures-re | Regexp whose first part matches F90 intrinsic procedures. |
f90-program-block-re | Regexp used to locate the start/end of a "subprogram". |
f90-program-indent | Extra indentation applied to PROGRAM, MODULE, SUBROUTINE, FUNCTION blocks. |
f90-smart-end | Qualification of END statements according to the matching block start. |
f90-smart-end-names | Whether completion of END statements should insert optional block names. |
f90-start-block-re | Regexp matching the start of an F90 "block", from the line start. |
f90-type-def-re | Regexp matching the definition of a derived type. |
f90-type-indent | Extra indentation applied to TYPE, ENUM, INTERFACE and BLOCK DATA blocks. |
f90-typeis-re | Regexp matching a CLASS/TYPE IS statement. |