+ (list (concat fortran-type-types "[ \t(/]*\\(*\\)?")
+ ;; Type specifier.
+ '(1 font-lock-type-face)
+ ;; Declaration item (or just /.../ block name).
+ `(font-lock-match-c-style-declaration-item-and-skip-to-next
+ ;; Start after any *(...) expression.
+ (condition-case nil
+ (and (match-beginning ,(1+ (regexp-opt-depth
+ fortran-type-types)))
+ (forward-sexp)
+ (forward-sexp))
+ (error nil))
+ ;; No need to clean up.
+ nil
+ ;; Fontify as a variable name, functions fontified elsewhere.
+ (1 font-lock-variable-name-face nil t))))
+ ;; Things extra to `fortran-font-lock-keywords-3' (must be done first).
+ (list
+ ;; Goto-like `err=label'/`end=label' in read/write statements.
+ '(", *\\(e\\(nd\\|rr\\)\\)\\> *\\(= *\\([0-9]+\\)\\)?"
+ (1 font-lock-keyword-face) (4 font-lock-constant-face nil t))
+ ;; Standard continuation character and in a TAB-formatted line.
+ '("^ \\{5\\}\\([^ 0\n]\\)" 1 font-lock-string-face)
+ '("^\t\\([1-9]\\)" 1 font-lock-string-face))
+ `((,fortran-directive-re (0 font-lock-keyword-face t)))
+ ;; `fortran-font-lock-keywords-2' without types (see above).
+ (cdr (nthcdr (length fortran-font-lock-keywords-1)
+ fortran-font-lock-keywords-2)))
+ "Gaudy level highlighting for Fortran mode.")
+
+;; Comments are real pain in Fortran because there is no way to
+;; represent the standard comment syntax in an Emacs syntax table.
+;; (We can do so for F90-style). Therefore an unmatched quote in a
+;; standard comment will throw fontification off on the wrong track.
+;; So we do syntactic fontification with regexps.
+(defvar fortran-font-lock-syntactic-keywords
+ '(("^[cd\\*]" 0 (11))
+ ("^[^cd\\*\t\n].\\{71\\}\\([^\n]+\\)" 1 (11)))
+ "`font-lock-syntactic-keywords' for Fortran.
+These get fixed-format comments fontified.")
+
+(defvar fortran-font-lock-keywords fortran-font-lock-keywords-1
+ "Default expressions to highlight in Fortran mode.")
+
+(defvar fortran-imenu-generic-expression
+ ;; These patterns could be confused by sequence nos. in cols 72+ and
+ ;; don't allow continuations everywhere.
+ (list
+ (list
+ nil
+ ;; [This will be fooled by `end function' allowed by G77. Also,
+ ;; it assumes sensible whitespace is employed.]
+ (concat
+ ;; leading whitespace:
+ "^\\s-+\\("
+ ;; function declaration with optional type, e.g. `real',
+ ;; `real*4', character(*), `double precision':
+ "\\(\\sw\\|\\s-\\|[*()+]\\)*"
+ "\\<function\\|subroutine\\|entry\\|block\\s-*data\\|program\\)"
+ ;; Possible statement continuation:
+ "[ \t" fortran-continuation-string "]+"
+ ;; Variable to index:
+ "\\(\\sw+\\)")
+ 3)
+ ;; Un-named block data.
+ '(nil "^\\s-+\\(block\\s-*data\\)\\s-*$" 1))
+ "Value for `imenu-generic-expression' in Fortran mode.")
+
+\f
+(defvar fortran-mode-syntax-table
+ (let ((table (make-syntax-table)))
+ ;; We might like `;' to be punctuation (g77 multi-statement
+ ;; lines), but that screws abbrevs.
+ (modify-syntax-entry ?\; "w" table)
+ (modify-syntax-entry ?\r " " table)
+ (modify-syntax-entry ?+ "." table)
+ (modify-syntax-entry ?- "." table)
+ (modify-syntax-entry ?= "." table)
+ (modify-syntax-entry ?* "." table)
+ (modify-syntax-entry ?/ "." table)
+ (modify-syntax-entry ?\' "\"" table)
+ (modify-syntax-entry ?\" "\"" table)
+ ;; Consistent with GNU Fortran -- see the manual.
+ (modify-syntax-entry ?\\ "\\" table)
+ ;; This might be better as punctuation, as for C, but this way you
+ ;; can treat floating-point numbers as symbols.
+ (modify-syntax-entry ?. "_" table) ; e.g. `a.ne.b'
+ (modify-syntax-entry ?_ "_" table)
+ (modify-syntax-entry ?$ "_" table) ; esp. VMSisms
+ (modify-syntax-entry ?\! "<" table)
+ (modify-syntax-entry ?\n ">" table)
+ table)
+ "Syntax table used in Fortran mode.")
+
+(defvar fortran-gud-syntax-table
+ (let ((st (make-syntax-table fortran-mode-syntax-table)))
+ (modify-syntax-entry ?\n "." st)
+ st)
+ "Syntax table used to parse Fortran expressions for printing in GUD.")
+
+(defvar fortran-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map ";" 'fortran-abbrev-start)
+ (define-key map "\C-c;" 'fortran-comment-region)
+ (define-key map "\M-;" 'fortran-indent-comment)
+ (define-key map "\M-\n" 'fortran-split-line)
+ (define-key map "\M-\C-q" 'fortran-indent-subprogram)
+ (define-key map "\C-c\C-w" 'fortran-window-create-momentarily)
+ (define-key map "\C-c\C-r" 'fortran-column-ruler)
+ (define-key map "\C-c\C-p" 'fortran-previous-statement)
+ (define-key map "\C-c\C-n" 'fortran-next-statement)
+ (define-key map "\C-c\C-d" 'fortran-join-line) ; like f90
+ (define-key map "\M-^" 'fortran-join-line) ; subvert delete-indentation
+ (define-key map "0" 'fortran-electric-line-number)
+ (define-key map "1" 'fortran-electric-line-number)
+ (define-key map "2" 'fortran-electric-line-number)
+ (define-key map "3" 'fortran-electric-line-number)
+ (define-key map "4" 'fortran-electric-line-number)
+ (define-key map "5" 'fortran-electric-line-number)
+ (define-key map "6" 'fortran-electric-line-number)
+ (define-key map "7" 'fortran-electric-line-number)
+ (define-key map "8" 'fortran-electric-line-number)
+ (define-key map "9" 'fortran-electric-line-number)
+
+ (easy-menu-define fortran-menu map "Menu for Fortran mode."
+ `("Fortran"
+ ["Manual" (info "(emacs)Fortran")]
+ ("Customization"
+ ,(custom-menu-create 'fortran)
+ ["Set" Custom-set t]
+ ["Save" Custom-save t]
+ ["Reset to Current" Custom-reset-current t]
+ ["Reset to Saved" Custom-reset-saved t]
+ ["Reset to Standard Settings" Custom-reset-standard t]
+ )
+ "--"
+ ["Comment Region" fortran-comment-region mark-active]
+ ["Uncomment Region"
+ (fortran-comment-region (region-beginning) (region-end) 1)
+ mark-active]
+ ["Indent Region" indent-region mark-active]
+ ["Indent Subprogram" fortran-indent-subprogram t]
+ "--"
+ ["Beginning of Subprogram" fortran-beginning-of-subprogram t]
+ ["End of Subprogram" fortran-end-of-subprogram t]
+ ("Mark"
+ ["Subprogram" mark-defun t]
+ ["IF Block" fortran-mark-if t]
+ ["DO Block" fortran-mark-do t]
+ )
+ ["Narrow to Subprogram" narrow-to-defun t]
+ ["Widen" widen t]
+ "--"
+ ["Temporary column ruler" fortran-column-ruler t]
+ ["72-column window" fortran-window-create t]
+ ["Full Width Window"
+ (enlarge-window-horizontally (- (frame-width) (window-width)))
+ (< (window-width) (frame-width))]
+ ["Momentary 72-column window" fortran-window-create-momentarily t]
+ "--"
+ ["Break Line at Point" fortran-split-line t]
+ ["Join Line" fortran-join-line t]
+ ["Fill Statement/Comment" fill-paragraph t]
+ "--"
+ ["Toggle auto-fill" auto-fill-mode :selected auto-fill-function
+ :style toggle]
+ ["Toggle abbrev-mode" abbrev-mode :selected abbrev-mode
+ :style toggle]
+ ["Add imenu Menu" imenu-add-menubar-index
+ :active (not (lookup-key (current-local-map) [menu-bar index]))
+ :included (fboundp 'imenu-add-to-menubar)]))
+ map)