]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/f90.el
Fix capitalization and punctuation in menu bar.
[gnu-emacs] / lisp / progmodes / f90.el
index 607d45f4bb370bca9e23b60a729f21b593cacad7..190a107c842328eeef493a956b28ac48bc60e373 100644 (file)
@@ -1,8 +1,8 @@
-;; f90.el --- Fortran-90 mode (free format) for GNU Emacs.
+;; f90.el --- Fortran-90 mode (free format) for GNU Emacs and GNU XEmacs.
 ;; Copyright (C) 1995 Free Software Foundation, Inc.
 
 ;; Author: Torbj\"orn Einarsson <tfkte@fy.chalmers.se>
-;; Created: Jan 21, 1995
+;; Created: Apr. 13, 1995
 ;; Keywords: fortran, f90, languages
 
 ;; This program is free software; you can redistribute it and/or modify
@@ -86,7 +86,9 @@
 ;;                        f90-auto-keyword-case nil
 ;;                        f90-auto-hilit19 t
 ;;                        f90-leave-line-no  nil
-;;                        f90-startup-message t)
+;;                        f90-startup-message t
+;;                        indent-tabs-mode nil
+;;                  )
 ;;       ;;The rest is not default.
 ;;       (abbrev-mode 1)             ; turn on abbreviation mode
 ;;       (f90-auto-fill-mode 1)      ; turn on auto-filling
 ;;   b) To use font-lock-mode, nothing special is needed.
 ;; 4) For FIXED FORMAT code, use the ordinary fortran mode.
 ;; 5) This mode does not work under emacs-18.x.
+;; 6) 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 \ ).
 
 ;; List of user commands
 ;;   f90-previous-statement         f90-next-statement
 ;; of this code is built.
 
 ;;; Code:
-(defconst f90-mode-version "version 1.03")
 (defconst bug-f90-mode "tfkte@fy.chalmers.se"
   "Address of mailing list for F90 mode bugs.")
 
@@ -195,7 +199,7 @@ whether to blink the matching beginning.")
     "elseif" "elsewhere" "end" "enddo" "endfile" "endif" "entry" "equivalence"
     "exit" "external" "forall" "format" "function" "goto" "if" "implicit"
     "include" "inquire" "integer" "intent" "interface" "intrinsic" "logical"
-    "module" "namelist" "none" "nullify" "open" "optional" "parameter"
+    "module" "namelist" "none" "nullify" "only" "open" "optional" "parameter"
     "pause" "pointer" "precision" "print" "private" "procedure" "program"
     "public" "read" "real" "recursive" "return" "rewind" "save" "select"
     "sequence" "stop" "subroutine" "target" "then" "type" "use" "where"
@@ -263,6 +267,10 @@ whether to blink the matching beginning.")
                  'font-lock-function-name-face)
     '("^[ \t]*\\(type\\)[ \t]+\\sw+" 1 font-lock-keyword-face)
     '("^[ \t]*type[ \t]+\\(\\sw+\\)" 1 font-lock-function-name-face)
+    '("^[ \t]*\\(type[ \t]*,[ \t]*\\(private\\|public\\)\\)[ \t]*::\
+[ \t]*\\(\\sw+\\)" 1 font-lock-keyword-face)
+    '("^[ \t]*\\(type[ \t]*,[ \t]*\\(private\\|public\\)\\)[ \t]*::\
+[ \t]*\\(\\sw+\\)" 3 font-lock-function-name-face)
     '("^[ \t]*\\(end[ \t]*\\)?interface\\>" . font-lock-keyword-face)
     '("^[ \t]*contains\\>" . font-lock-keyword-face)))
   "For consideration as a value of `f90-font-lock-keywords-1'.
@@ -273,8 +281,8 @@ This does fairly subdued highlighting of comments and function names.")
    (append f90-font-lock-keywords-1
     (list
      ;; Variable declarations
-     '("\\(\\(real\\|integer\\|character\\|complex\\|logical\\|type\\).*\\)::"
-       1 font-lock-type-face)
+     '("\\(\\(real\\|integer\\|character\\|complex\\|logical\\|\
+type[ \t]*(\\sw+)\\).*\\)::" 1 font-lock-type-face)
      '("implicit[ \t]*none" . font-lock-keyword-face)
      '("^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(do\\([ \t]*while\\)?\\)\\>"
        2 font-lock-keyword-face)
@@ -315,7 +323,9 @@ This does fairly subdued highlighting of comments and function names.")
   "For consideration as a value of `f90-font-lock-keywords'.
 This highlights variable types, \"keywords,\" etc.")
 
-(defvar f90-font-lock-keywords f90-font-lock-keywords-2
+(defvar f90-font-lock-keywords (if font-lock-maximum-decoration
+                                  f90-font-lock-keywords-2
+                                f90-font-lock-keywords-1)
   "*Additional expressions to highlight in F90 mode.")
 
 ;; hilit19 customization and expressions
@@ -351,7 +361,7 @@ This highlights variable types, \"keywords,\" etc.")
            nil f90-face-string)
       (list "!" "$" f90-face-comment)
       (list "\\(\\(real\\|integer\\|character\\|complex\\|logical\
-\\|type\\).*\\)::" 1 f90-face-decl)
+\\|type[ \t]*(\\sw+)\\).*\\)::" 1 f90-face-decl)
       (list "implicit[ \t]*none" nil f90-face-decl)
       (list "^[ \t]*\\(program\\|module\\)[ \t]+\\sw+" 1 f90-face-prog)
       (list "^[ \t]*\\(program\\|module\\)[ \t]+\\(\\sw+\\)" 2 f90-face-label)
@@ -365,6 +375,8 @@ This highlights variable types, \"keywords,\" etc.")
                    "subroutine\\|type\\)[ \t]+\\(\\sw+\\)") 2 f90-face-label)
       (list "^[ \t]*\\(type\\)[ \t]+\\sw+" 1 f90-face-type)
       (list "^[ \t]*type[ \t]+\\(\\sw+\\)" 1 f90-face-label)
+      (list "^[ \t]*\\(type[ \t]*,[ \t]*\\(private\\|public\\)\\)[ \t]*::[ \t]*\\(\\sw+\\)" 1 f90-face-type)
+      (list "^[ \t]*\\(type[ \t]*,[ \t]*\\(private\\|public\\)\\)[ \t]*::[ \t]*\\(\\sw+\\)" 3 f90-face-label)
       (list "^[ \t]*\\(end[ \t]*\\)?interface\\>" nil f90-face-interface)
       (list "^[ \t]*contains\\>" nil f90-face-contains)
       (list "^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(do\\([ \t]*while\\)?\\)\\>"
@@ -452,28 +464,28 @@ This highlights variable types, \"keywords,\" etc.")
     (progn
       (add-menu nil "F90"
                '(
-                 ["Indent subprogram"       f90-indent-subprogram t]
-                 ["Mark subprogram"         f90-mark-subprogram t]
-                 ["Beginning of subprogram" f90-beginning-of-subprogram t]
-                 ["End of subprogram"       f90-end-of-subprogram t]
+                 ["Indent Subprogram"       f90-indent-subprogram t]
+                 ["Mark Subprogram"         f90-mark-subprogram t]
+                 ["Beginning of Subprogram" f90-beginning-of-subprogram t]
+                 ["End of Subprogram"       f90-end-of-subprogram t]
                  "-----"
-                 ["(Un)Comment region"      f90-comment-region t]
-                 ["Indent region"           indent-region t]
-                 ["Fill region"             f90-fill-region t]
+                 ["(Un)Comment Region"      f90-comment-region t]
+                 ["Indent Region"           indent-region t]
+                 ["Fill Region"             f90-fill-region t]
                  "-----"
-                 ["Break line at point"     f90-break-line t]
-                 ["Join with next line"     f90-join-lines t]
-                 ["Insert newline."         newline t]
-                 ["Insert end."             f90-insert-end t]
+                 ["Break Line at Point"     f90-break-line t]
+                 ["Join with Next Line"     f90-join-lines t]
+                 ["Insert Newline"          newline t]
+                 ["Insert End"              f90-insert-end t]
                  "-----"
-                 ["UPCASE keywords (buffer)"      f90-upcase-keywords t]
-                 ["UPCASE keywords (region)"      f90-upcase-region-keywords
+                 ["Upcase Keywords (buffer)"      f90-upcase-keywords t]
+                 ["Upcase Keywords (region)"      f90-upcase-region-keywords
                   t]
-                 ["Capitalize keywords (buffer)"  f90-capitalize-keywords t]
-                 ["Capitalize keywords (region)" 
+                 ["Capitalize Keywords (buffer)"  f90-capitalize-keywords t]
+                 ["Capitalize Keywords (region)" 
                   f90-capitalize-region-keywords t]
-                 ["downcase keywords (buffer)"    f90-downcase-keywords t]
-                 ["downcase keywords (region)"   
+                 ["Downcase Keywords (buffer)"    f90-downcase-keywords t]
+                 ["Downcase Keywords (region)"   
                   f90-downcase-region-keywords t]
                  "-----"
                  ["Toggle abbrev-mode"   abbrev-mode             t]
@@ -487,23 +499,23 @@ This highlights variable types, \"keywords,\" etc.")
   (define-key f90-mode-map [menu-bar f90 f90-auto-fill-mode]
     '("Toggle auto-fill" . f90-auto-fill-mode))
   (define-key f90-mode-map [menu-bar f90 f90-downcase-region-keywords]
-    '("downcase keywords (region)" . f90-downcase-region-keywords))
+    '("Downcase Keywords (region)" . f90-downcase-region-keywords))
   (define-key f90-mode-map [menu-bar f90 f90-downcase-keywords]
-    '("downcase keywords (buffer)" . f90-downcase-keywords))
+    '("Downcase Keywords (buffer)" . f90-downcase-keywords))
   (define-key f90-mode-map [menu-bar f90 f90-capitalize-keywords]
-    '("Capitalize keywords (region)" . f90-capitalize-region-keywords))
+    '("Capitalize Keywords (region)" . f90-capitalize-region-keywords))
   (define-key f90-mode-map [menu-bar f90 f90-capitalize-region-keywords]
-    '("Capitalize keywords (buffer)" . f90-capitalize-keywords))
+    '("Capitalize Keywords (buffer)" . f90-capitalize-keywords))
   (define-key f90-mode-map [menu-bar f90 f90-upcase-region-keywords]
-    '("UPCASE keywords (region)" . f90-upcase-region-keywords))
+    '("Upcase keywords (region)" . f90-upcase-region-keywords))
   (define-key f90-mode-map [menu-bar f90 f90-upcase-keywords]
-    '("UPCASE keywords (buffer)" . f90-upcase-keywords))
+    '("Upcase keywords (buffer)" . f90-upcase-keywords))
   (define-key f90-mode-map [menu-bar f90 f90-insert-end]
-    '("Insert end." . f90-insert-end))
+    '("Insert end" . f90-insert-end))
   (define-key f90-mode-map [menu-bar f90 f90-join-lines]
-    '("Join with next line." . f90-join-lines))
+    '("Join with Next Line" . f90-join-lines))
   (define-key f90-mode-map [menu-bar f90 f90-break-line]
-    '("Break line at point" . f90-break-line))
+    '("Break Line at Point" . f90-break-line))
   (define-key f90-mode-map [menu-bar f90 f90-fill-region]
     '("Fill Region" . f90-fill-region))
   (define-key f90-mode-map [menu-bar f90 indent-region]
@@ -532,6 +544,9 @@ program\\|select\\|subroutine\\|type\\|where\\|forall\\)\\>")
 (defconst f90-end-type-re 
   "end[ \t]*\\(type\\|interface\\|block[ \t]*data\\)\\>")
 (defconst f90-no-break-re  "\\(\\*\\*\\|//\\|=>\\)")
+(defconst f90-p-type-re
+  (concat "\\(type\\)[ \t]*,[ \t]*\\(public\\|private\\)"
+         "[ \t]*::[ \t]*\\(" f90-symbol-re "\\)\\>"))
 ;; A temporary position to make region operators faster
 (defvar f90-cache-position nil)
 (make-variable-buffer-local 'f90-cache-position)
@@ -681,19 +696,20 @@ with no args, if that value is non-nil."
   (setq comment-indent-function 'f90-comment-indent)
   (make-local-variable 'abbrev-all-caps)
   (setq abbrev-all-caps t)
+  (setq indent-tabs-mode nil)
   ;; Setting up things for font-lock
   (if (string-match "Lucid" emacs-version)
       (put 'f90-mode 'font-lock-keywords-case-fold-search t)
-    ;; (make-local-variable 'font-lock-keywords) ; for version <= 19.28 
+    ;; (make-local-variable 'font-lock-keywords) ; for Emacs version <= 19.28 
     ;; (setq font-lock-keywords f90-font-lock-keywords)
-    (make-local-variable 'font-lock-defaults) ; for version > 19.28
+    (make-local-variable 'font-lock-defaults) ; for Emacs version > 19.28
     (setq font-lock-defaults '(f90-font-lock-keywords t))
     )
   (make-local-variable 'font-lock-keywords-case-fold-search)
   (setq font-lock-keywords-case-fold-search t)
   (run-hooks 'f90-mode-hook)
   (if f90-startup-message
-      (message "Emacs F90 mode %s. Bugs to %s" f90-mode-version bug-f90-mode))
+      (message "Emacs F90 mode; please report bugs to %s" bug-f90-mode))
   (setq f90-startup-message nil))
 \f
 ;; inline-functions
@@ -834,6 +850,8 @@ Name is non-nil only for type."
   (cond 
    ((looking-at (concat "\\(type\\)[ \t]+\\(" f90-symbol-re "\\)\\>"))
     (list (f90-match-piece 1) (f90-match-piece 2)))
+   ((looking-at f90-p-type-re)
+    (list (f90-match-piece 1) (f90-match-piece 3)))
    ((looking-at "\\(interface\\)\\>")
     (list (f90-match-piece 1) nil))
    ((looking-at "\\(block[ \t]*data\\)\\>")
@@ -901,6 +919,7 @@ case\\|where\\|forall\\)\\>")
 block[ \t]*data\\)\\>")
               (looking-at "\\(contains\\|continue\\|\\sw+[ \t]*:\\)")
               (looking-at "type[ \t]+\\sw+")
+              (looking-at f90-p-type-re)
               (re-search-forward "\\(function\\|subroutine\\)" eol t))))))
 
 (defsubst f90-update-line ()
@@ -1319,8 +1338,7 @@ automatically breaks the line at a previous space."
                       (not auto-fill-function)
                     (> (prefix-numeric-value arg) 0))
                   'f90-do-auto-fill))
-    ;; update mode-line
-    (set-buffer-modified-p (buffer-modified-p))))
+    (force-mode-line-update)))
 
 (defun f90-do-auto-fill ()
   "Break line if non-white characters beyond fill-column."
@@ -1552,10 +1570,14 @@ Any other key combination is executed normally."
       (while (re-search-forward keyword-re end t)
        (if (progn
              (setq state (parse-partial-sexp ref-point (point)))
-             (and (not (nth 3 state)) (not (nth 4 state))))
-           (progn
-             (setq ref-point (point))
-             (funcall change-word -1)))))))
+             (or (nth 3 state) (nth 4 state)
+                 (save-excursion       ; Check for cpp directive.
+                   (beginning-of-line)
+                   (skip-chars-forward " \t0-9")
+                   (looking-at "#"))))
+           ()
+         (setq ref-point (point))
+         (funcall change-word -1))))))
 
 (provide 'f90)