Homepage: https://www.gnu.org/software/emacs
Author: Torbjörn Einarsson
Fortran-90 mode (free format)
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, or C-h v . 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.