]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/f90.el
(compilation-start): Resurrect the version for systems that don't support
[gnu-emacs] / lisp / progmodes / f90.el
index 2c152d91512d08629969c965cafe76aca4a20f49..a53e103c6f81ebb19294959973b1695e14960c93 100644 (file)
@@ -9,10 +9,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,9 +20,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -39,7 +37,6 @@
 
 ;; To facilitate typing, a fairly complete list of abbreviations is provided.
 ;; All abbreviations begin with the backquote character "`"
-;; (this requires modification of the syntax-table).
 ;; For example, `i expands to integer (if abbrev-mode is on).
 
 ;; There are two separate features for altering the appearance of code:
@@ -443,7 +440,7 @@ The options are 'downcase-word, 'upcase-word, 'capitalize-word and nil."
 Set the match data so that subexpression 1,2 are the TYPE, and
 type-name parts, respectively."
   (let (found l)
-    (while (and (re-search-forward "\\<\\(\\(?:end[ \t]*\\)?type\\)[ \t]*"
+    (while (and (re-search-forward "\\<\\(\\(?:end[ \t]*\\)?type\\)\\>[ \t]*"
                                    limit t)
                 (not (setq found
                            (progn
@@ -601,11 +598,12 @@ logical\\|double[ \t]*precision\\|type[ \t]*(\\sw+)\\|none\\)[ \t]*"
           (list
            f90-keywords-level-3-re
            f90-operators-re
+           ;; FIXME why isn't this font-lock-builtin-face, which
+           ;; otherwise we hardly use, as in fortran.el?
            (list f90-procedures-re '(1 font-lock-keyword-face keep))
            "\\<real\\>"                 ; avoid overwriting real defs
            ;; As an attribute, but not as an optional argument.
-           '("\\<\\(asynchronous\\)[ \t]*[^=]" . 1)
-           ))
+           '("\\<\\(asynchronous\\)[ \t]*[^=]" . 1)))
   "Highlights all F90 keywords and intrinsic procedures.")
 
 (defvar f90-font-lock-keywords-4
@@ -624,17 +622,20 @@ Can be overridden by the value of `font-lock-maximum-decoration'.")
   (let ((table (make-syntax-table)))
     (modify-syntax-entry ?\! "<"  table) ; begin comment
     (modify-syntax-entry ?\n ">"  table) ; end comment
+    ;; FIXME: This goes against the convention: it should be "_".
     (modify-syntax-entry ?_  "w"  table) ; underscore in names
     (modify-syntax-entry ?\' "\"" table) ; string quote
     (modify-syntax-entry ?\" "\"" table) ; string quote
-    (modify-syntax-entry ?\` "w"  table) ; for abbrevs
+    ;; FIXME: We used to set ` to word syntax for the benefit of abbrevs, but
+    ;; we do not need it any more.  Not sure if it should be "_" or "." now.
+    (modify-syntax-entry ?\` "_"  table)
     (modify-syntax-entry ?\r " "  table) ; return is whitespace
     (modify-syntax-entry ?+  "."  table) ; punctuation
     (modify-syntax-entry ?-  "."  table)
     (modify-syntax-entry ?=  "."  table)
     (modify-syntax-entry ?*  "."  table)
     (modify-syntax-entry ?/  "."  table)
-    ;; I think that the f95 standard leaves the behaviour of \
+    ;; I think that the f95 standard leaves the behavior of \
     ;; unspecified, but that f2k will require it to be non-special.
     ;; Use `f90-backslash-not-special' to change.
     (modify-syntax-entry ?\\ "\\" table) ; escape chars
@@ -652,7 +653,7 @@ Can be overridden by the value of `font-lock-maximum-decoration'.")
     (define-key map "\C-\M-p"  'f90-beginning-of-block)
     (define-key map "\C-\M-q"  'f90-indent-subprogram)
     (define-key map "\C-j"     'f90-indent-new-line) ; LFD equals C-j
-    (define-key map "\r"       'newline)
+;;;    (define-key map "\r"       'newline)
     (define-key map "\C-c\r"   'f90-break-line)
 ;;;  (define-key map [M-return] 'f90-break-line)
     (define-key map "\C-c\C-a" 'f90-previous-block)
@@ -662,7 +663,8 @@ Can be overridden by the value of `font-lock-maximum-decoration'.")
     (define-key map "\C-c\C-p" 'f90-previous-statement)
     (define-key map "\C-c\C-n" 'f90-next-statement)
     (define-key map "\C-c\C-w" 'f90-insert-end)
-    (define-key map "\t"       'f90-indent-line)
+    ;; Standard tab binding will call this, and also handle regions.
+;;;    (define-key map "\t"       'f90-indent-line)
     (define-key map ","        'f90-electric-insert)
     (define-key map "+"        'f90-electric-insert)
     (define-key map "-"        'f90-electric-insert)
@@ -726,34 +728,32 @@ Can be overridden by the value of `font-lock-maximum-decoration'.")
   "Keymap used in F90 mode.")
 
 
+(defun f90-font-lock-n (n)
+  "Set `font-lock-keywords' to F90 level N keywords."
+  (font-lock-mode 1)
+  (setq font-lock-keywords
+        (symbol-value (intern-soft (format "f90-font-lock-keywords-%d" n))))
+  (font-lock-fontify-buffer))
+
 (defun f90-font-lock-1 ()
   "Set `font-lock-keywords' to `f90-font-lock-keywords-1'."
   (interactive)
-  (font-lock-mode 1)
-  (setq font-lock-keywords f90-font-lock-keywords-1)
-  (font-lock-fontify-buffer))
+  (f90-font-lock-n 1))
 
 (defun f90-font-lock-2 ()
   "Set `font-lock-keywords' to `f90-font-lock-keywords-2'."
   (interactive)
-  (font-lock-mode 1)
-  (setq font-lock-keywords f90-font-lock-keywords-2)
-  (font-lock-fontify-buffer))
+  (f90-font-lock-n 2))
 
 (defun f90-font-lock-3 ()
   "Set `font-lock-keywords' to `f90-font-lock-keywords-3'."
   (interactive)
-  (font-lock-mode 1)
-  (setq font-lock-keywords f90-font-lock-keywords-3)
-  (font-lock-fontify-buffer))
+  (f90-font-lock-n 3))
 
 (defun f90-font-lock-4 ()
   "Set `font-lock-keywords' to `f90-font-lock-keywords-4'."
   (interactive)
-  (font-lock-mode 1)
-  (setq font-lock-keywords f90-font-lock-keywords-4)
-  (font-lock-fontify-buffer))
-
+  (f90-font-lock-n 4))
 \f
 ;; Regexps for finding program structures.
 (defconst f90-blocks-re
@@ -869,7 +869,7 @@ Used in the F90 entry in `hs-special-modes-alist'.")
 (defun f90-imenu-type-matcher ()
   "Search backward for the start of a derived type.
 Set subexpression 1 in the match-data to the name of the type."
-  (let (found l)
+  (let (found)
     (while (and (re-search-backward "^[ \t0-9]*type[ \t]*" nil t)
                 (not (setq found
                            (save-excursion
@@ -884,7 +884,8 @@ Set subexpression 1 in the match-data to the name of the type."
 (defvar f90-imenu-generic-expression
   (let ((good-char "[^!\"\&\n \t]") (not-e "[^e!\n\"\& \t]")
         (not-n "[^n!\n\"\& \t]") (not-d "[^d!\n\"\& \t]")
-        (not-ib "[^i(!\n\"\& \t]") (not-s "[^s!\n\"\& \t]"))
+        ;; (not-ib "[^i(!\n\"\& \t]") (not-s "[^s!\n\"\& \t]")
+        )
     (list
      '(nil "^[ \t0-9]*program[ \t]+\\(\\sw+\\)" 1)
      '("Modules" "^[ \t0-9]*module[ \t]+\\(\\sw+\\)[ \t]*\\(!\\|$\\)" 1)
@@ -925,84 +926,71 @@ Set subexpression 1 in the match-data to the name of the type."
 
 \f
 ;; Abbrevs have generally two letters, except standard types `c, `i, `r, `t.
-(defvar f90-mode-abbrev-table
-  (progn
-    (define-abbrev-table 'f90-mode-abbrev-table nil)
-    f90-mode-abbrev-table)
-  "Abbrev table for F90 mode.")
-
-(let (abbrevs-changed)
-  ;; Use the 6th arg (SYSTEM-FLAG) of define-abbrev if possible.
-  ;; A little baroque to quieten the byte-compiler.
-  (mapc
-   (function (lambda (element)
-               (condition-case nil
-                   (apply 'define-abbrev f90-mode-abbrev-table
-                          (append element '(nil 0 t)))
-                 (wrong-number-of-arguments
-                  (apply 'define-abbrev f90-mode-abbrev-table
-                         (append element '(nil 0)))))))
-   '(("`al"  "allocate"     )
-     ("`ab"  "allocatable"  )
-     ("`ai"  "abstract interface")
-     ("`as"  "assignment"   )
-     ("`asy" "asynchronous" )
-     ("`ba"  "backspace"    )
-     ("`bd"  "block data"   )
-     ("`c"   "character"    )
-     ("`cl"  "close"        )
-     ("`cm"  "common"       )
-     ("`cx"  "complex"      )
-     ("`cn"  "contains"     )
-     ("`cy"  "cycle"        )
-     ("`de"  "deallocate"   )
-     ("`df"  "define"       )
-     ("`di"  "dimension"    )
-     ("`dp"  "double precision")
-     ("`dw"  "do while"     )
-     ("`el"  "else"         )
-     ("`eli" "else if"      )
-     ("`elw" "elsewhere"    )
-     ("`em"  "elemental"    )
-     ("`e"   "enumerator"   )
-     ("`eq"  "equivalence"  )
-     ("`ex"  "external"     )
-     ("`ey"  "entry"        )
-     ("`fl"  "forall"       )
-     ("`fo"  "format"       )
-     ("`fu"  "function"     )
-     ("`fa"  ".false."      )
-     ("`im"  "implicit none")
-     ("`in"  "include"      )
-     ("`i"   "integer"      )
-     ("`it"  "intent"       )
-     ("`if"  "interface"    )
-     ("`lo"  "logical"      )
-     ("`mo"  "module"       )
-     ("`na"  "namelist"     )
-     ("`nu"  "nullify"      )
-     ("`op"  "optional"     )
-     ("`pa"  "parameter"    )
-     ("`po"  "pointer"      )
-     ("`pr"  "print"        )
-     ("`pi"  "private"      )
-     ("`pm"  "program"      )
-     ("`pr"  "protected"    )
-     ("`pu"  "public"       )
-     ("`r"   "real"         )
-     ("`rc"  "recursive"    )
-     ("`rt"  "return"       )
-     ("`rw"  "rewind"       )
-     ("`se"  "select"       )
-     ("`sq"  "sequence"     )
-     ("`su"  "subroutine"   )
-     ("`ta"  "target"       )
-     ("`tr"  ".true."       )
-     ("`t"   "type"         )
-     ("`vo"  "volatile"     )
-     ("`wh"  "where"        )
-     ("`wr"  "write"        ))))
-
+(define-abbrev-table 'f90-mode-abbrev-table
+  (mapcar (lambda (e) (list (car e) (cdr e) nil :system t))
+          '(("`al"  . "allocate"     )
+            ("`ab"  . "allocatable"  )
+            ("`ai"  . "abstract interface")
+            ("`as"  . "assignment"   )
+            ("`asy" . "asynchronous" )
+            ("`ba"  . "backspace"    )
+            ("`bd"  . "block data"   )
+            ("`c"   . "character"    )
+            ("`cl"  . "close"        )
+            ("`cm"  . "common"       )
+            ("`cx"  . "complex"      )
+            ("`cn"  . "contains"     )
+            ("`cy"  . "cycle"        )
+            ("`de"  . "deallocate"   )
+            ("`df"  . "define"       )
+            ("`di"  . "dimension"    )
+            ("`dp"  . "double precision")
+            ("`dw"  . "do while"     )
+            ("`el"  . "else"         )
+            ("`eli" . "else if"      )
+            ("`elw" . "elsewhere"    )
+            ("`em"  . "elemental"    )
+            ("`e"   . "enumerator"   )
+            ("`eq"  . "equivalence"  )
+            ("`ex"  . "external"     )
+            ("`ey"  . "entry"        )
+            ("`fl"  . "forall"       )
+            ("`fo"  . "format"       )
+            ("`fu"  . "function"     )
+            ("`fa"  . ".false."      )
+            ("`im"  . "implicit none")
+            ("`in"  . "include"      )
+            ("`i"   . "integer"      )
+            ("`it"  . "intent"       )
+            ("`if"  . "interface"    )
+            ("`lo"  . "logical"      )
+            ("`mo"  . "module"       )
+            ("`na"  . "namelist"     )
+            ("`nu"  . "nullify"      )
+            ("`op"  . "optional"     )
+            ("`pa"  . "parameter"    )
+            ("`po"  . "pointer"      )
+            ("`pr"  . "print"        )
+            ("`pi"  . "private"      )
+            ("`pm"  . "program"      )
+            ("`pr"  . "protected"    )
+            ("`pu"  . "public"       )
+            ("`r"   . "real"         )
+            ("`rc"  . "recursive"    )
+            ("`rt"  . "return"       )
+            ("`rw"  . "rewind"       )
+            ("`se"  . "select"       )
+            ("`sq"  . "sequence"     )
+            ("`su"  . "subroutine"   )
+            ("`ta"  . "target"       )
+            ("`tr"  . ".true."       )
+            ("`t"   . "type"         )
+            ("`vo"  . "volatile"     )
+            ("`wh"  . "where"        )
+            ("`wr"  . "write"        )))
+  "Abbrev table for F90 mode."
+  ;; Accept ` as the first char of an abbrev.  Also allow _ in abbrevs.
+  :regexp "\\(?:[^[:word:]_`]\\|^\\)\\(`?[[:word:]_]+\\)[^[:word:]_]*")
 \f
 ;;;###autoload
 (defun f90-mode ()
@@ -1226,7 +1214,7 @@ NAME is nil if the statement has no label."
 NAME is non-nil only for type."
   (cond
    ((save-excursion
-      (and (looking-at "\\<type[ \t]*")
+      (and (looking-at "\\<type\\>[ \t]*")
            (goto-char (match-end 0))
            (not (looking-at "\\(is\\>\\|(\\)"))
            (or (looking-at "\\(\\sw+\\)")
@@ -1452,8 +1440,7 @@ Does not check type and subprogram indentation."
                                (setq icol (- icol f90-associate-indent)))
                               ((or (looking-at "contains[ \t]*\\(!\\|$\\)")
                                    (f90-looking-at-program-block-end))
-                               (setq icol (- icol f90-program-indent))))))
-                 ))))
+                               (setq icol (- icol f90-program-indent))))))))))
     icol))
 \f
 (defun f90-previous-statement ()
@@ -1500,7 +1487,7 @@ Return (TYPE NAME), or nil if not found."
         matching-beg
       ;; Note this includes the case of an un-named main program,
       ;; in which case we go to (point-min).
-      (message "No beginning found.")
+      (if (interactive-p) (message "No beginning found"))
       nil)))
 
 (defun f90-end-of-subprogram ()
@@ -1508,7 +1495,7 @@ Return (TYPE NAME), or nil if not found."
 Return (TYPE NAME), or nil if not found."
   (interactive)
   (let ((case-fold-search t)
-        (count 1) 
+        (count 1)
         matching-end)
     (end-of-line)
     (while (and (> count 0)
@@ -1525,7 +1512,7 @@ Return (TYPE NAME), or nil if not found."
 ;;;    (forward-line 1)
     (if (zerop count)
         matching-end
-      (message "No end found.")
+      (if (interactive-p) (message "No end found"))
       nil)))
 
 
@@ -1837,8 +1824,8 @@ If run in the middle of a line, the line is not broken."
                    block-list (cdr block-list))
              (if f90-smart-end
                  (save-excursion
-                   (f90-block-match (car beg-struct) (car (cdr beg-struct))
-                                    (car end-struct) (car (cdr end-struct)))))
+                   (f90-block-match (car beg-struct) (cadr beg-struct)
+                                    (car end-struct) (cadr end-struct))))
              (setq ind-b
                    (cond ((looking-at f90-end-if-re) f90-if-indent)
                          ((looking-at "end[ \t]*do\\>")  f90-do-indent)
@@ -1878,10 +1865,10 @@ If run in the middle of a line, the line is not broken."
       (if program
           (progn
             (message "Indenting %s %s..."
-                     (car program) (car (cdr program)))
+                     (car program) (cadr program))
             (indent-region (point) (mark) nil)
             (message "Indenting %s %s...done"
-                     (car program) (car (cdr program))))
+                     (car program) (cadr program)))
         (message "Indenting the whole file...")
         (indent-region (point) (mark) nil)
         (message "Indenting the whole file...done")))))
@@ -2028,7 +2015,7 @@ Leave point at the end of line."
     (when (save-excursion (beginning-of-line) (skip-chars-forward " \t0-9")
                           (setq end-struct (f90-looking-at-program-block-end)))
       (setq end-block (car end-struct)
-            end-name  (car (cdr end-struct)))
+            end-name  (cadr end-struct))
       (save-excursion
         (beginning-of-line)
         (while (and (> count 0)
@@ -2069,7 +2056,7 @@ Leave point at the end of line."
                             (line-end-position)))
                 (sit-for blink-matching-delay)))
           (setq beg-block (car matching-beg)
-                beg-name (car (cdr matching-beg)))
+                beg-name (cadr matching-beg))
           (goto-char end-point)
           (beginning-of-line)
           (f90-block-match beg-block beg-name end-block end-name))))))
@@ -2109,8 +2096,7 @@ Any other key combination is executed normally."
 
 (defun f90-prepare-abbrev-list-buffer ()
   "Create a buffer listing the F90 mode abbreviations."
-  (save-excursion
-    (set-buffer (get-buffer-create "*Abbrevs*"))
+  (with-current-buffer (get-buffer-create "*Abbrevs*")
     (erase-buffer)
     (insert-abbrev-table-description 'f90-mode-abbrev-table t)
     (goto-char (point-min))
@@ -2179,7 +2165,7 @@ CHANGE-WORD should be one of 'upcase-word, 'downcase-word, 'capitalize-word."
               (funcall change-word -1)
               (or (string= saveword (buffer-substring back-point ref-point))
                   (setq modified t))))
-        (or modified (set-buffer-modified-p nil))))))
+        (or modified (restore-buffer-modified-p nil))))))
 
 
 (defun f90-current-defun ()
@@ -2202,5 +2188,5 @@ escape character."
 
 (provide 'f90)
 
-;;; arch-tag: fceac97c-c147-44bd-aec0-172d4b560ef8
+;; arch-tag: fceac97c-c147-44bd-aec0-172d4b560ef8
 ;;; f90.el ends here