1 |
;;; fortran.el --- Fortran mode for GNU Emacs |
;;; fortran.el --- Fortran mode for GNU Emacs |
2 |
|
|
3 |
;; Copyright (c) 1986, 93, 94, 95, 97, 98, 99, 2000 |
;; Copyright (c) 1986, 93, 94, 95, 97, 98, 99, 2000, 2001 |
4 |
;; Free Software Foundation, Inc. |
;; Free Software Foundation, Inc. |
5 |
|
|
6 |
;; Author: Michael D. Prange <prange@erl.mit.edu> |
;; Author: Michael D. Prange <prange@erl.mit.edu> |
30 |
;; |
;; |
31 |
;; Note that it is for editing Fortran77 or Fortran90 fixed source |
;; Note that it is for editing Fortran77 or Fortran90 fixed source |
32 |
;; form. For editing Fortran 90 free format source, use `f90-mode' |
;; form. For editing Fortran 90 free format source, use `f90-mode' |
33 |
;; (f90.el). |
;; (f90.el). It is meant to support the GNU Fortran language |
34 |
|
;; implemented by g77 (its extensions to Fortran77 and |
35 |
|
;; interpretations, e.g. of blackslash in strings). |
36 |
|
|
37 |
;;; History: |
;;; History: |
38 |
|
|
51 |
;; * Implement insertion and removal of statement continuations in |
;; * Implement insertion and removal of statement continuations in |
52 |
;; mixed f77/f90 style, with the first `&' past column 72 and the |
;; mixed f77/f90 style, with the first `&' past column 72 and the |
53 |
;; second in column 6. |
;; second in column 6. |
54 |
;; * Support any other extensions to f77 grokked by GNU Fortran. |
;; * Support any other extensions to f77 grokked by GNU Fortran I've missed. |
55 |
|
|
56 |
(defgroup fortran nil |
(defgroup fortran nil |
57 |
"Fortran mode for Emacs" |
"Fortran mode for Emacs" |
234 |
(modify-syntax-entry ?/ "." table) |
(modify-syntax-entry ?/ "." table) |
235 |
(modify-syntax-entry ?\' "\"" table) |
(modify-syntax-entry ?\' "\"" table) |
236 |
(modify-syntax-entry ?\" "\"" table) |
(modify-syntax-entry ?\" "\"" table) |
237 |
|
;; Consistent with GNU Fortran -- see the manual. |
238 |
(modify-syntax-entry ?\\ "\\" table) |
(modify-syntax-entry ?\\ "\\" table) |
239 |
;; This might be better as punctuation, as for C, but this way you |
;; This might be better as punctuation, as for C, but this way you |
240 |
;; can treat floating-point numbers as symbols. |
;; can treat floating-point numbers as symbols. |
295 |
(regexp-opt '("continue" "format" "end" "enddo" "if" "then" |
(regexp-opt '("continue" "format" "end" "enddo" "if" "then" |
296 |
"else" "endif" "elseif" "while" "inquire" "stop" |
"else" "endif" "elseif" "while" "inquire" "stop" |
297 |
"return" "include" "open" "close" "read" "write" |
"return" "include" "open" "close" "read" "write" |
298 |
"format" "print" "select" "case" "cycle" "exit")))) |
"format" "print" "select" "case" "cycle" "exit" |
299 |
|
"rewind" "backspace")))) |
300 |
(fortran-logicals |
(fortran-logicals |
301 |
(eval-when-compile |
(eval-when-compile |
302 |
(regexp-opt '("and" "or" "not" "lt" "le" "eq" "ge" "gt" "ne" |
(regexp-opt '("and" "or" "not" "lt" "le" "eq" "ge" "gt" "ne" |
365 |
;; TAB-formatted line. |
;; TAB-formatted line. |
366 |
'("^ \\([^ 0]\\)" 1 font-lock-string-face) |
'("^ \\([^ 0]\\)" 1 font-lock-string-face) |
367 |
'("^\t\\([1-9]\\)" 1 font-lock-string-face)) |
'("^\t\\([1-9]\\)" 1 font-lock-string-face)) |
368 |
(list |
(list |
369 |
;; cpp stuff (ugh) |
;; cpp stuff (ugh) |
370 |
'("^# *[a-z]+" . font-lock-keyword-face)) |
'("^# *[a-z]+" . font-lock-keyword-face)) |
371 |
;; The list `fortran-font-lock-keywords-2' less that for types |
;; The list `fortran-font-lock-keywords-2' less that for types |
933 |
;; Note that you can't just check backwards for `subroutine' &c in |
;; Note that you can't just check backwards for `subroutine' &c in |
934 |
;; case of un-marked main programs not at the start of the file. |
;; case of un-marked main programs not at the start of the file. |
935 |
(defun fortran-beginning-of-subprogram () |
(defun fortran-beginning-of-subprogram () |
936 |
"Moves point to the beginning of the current Fortran subprogram." |
"Move point to the beginning of the current Fortran subprogram." |
937 |
(interactive) |
(interactive) |
938 |
(save-match-data |
(save-match-data |
939 |
(let ((case-fold-search t)) |
(let ((case-fold-search t)) |
945 |
(forward-line))))) |
(forward-line))))) |
946 |
|
|
947 |
(defun fortran-end-of-subprogram () |
(defun fortran-end-of-subprogram () |
948 |
"Moves point to the end of the current Fortran subprogram." |
"Move point to the end of the current Fortran subprogram." |
949 |
(interactive) |
(interactive) |
950 |
(save-match-data |
(save-match-data |
951 |
(let ((case-fold-search t)) |
(let ((case-fold-search t)) |
963 |
(forward-line))))) |
(forward-line))))) |
964 |
|
|
965 |
(defun fortran-previous-statement () |
(defun fortran-previous-statement () |
966 |
"Moves point to beginning of the previous Fortran statement. |
"Move point to beginning of the previous Fortran statement. |
967 |
Returns `first-statement' if that statement is the first |
Returns `first-statement' if that statement is the first |
968 |
non-comment Fortran statement in the file, and nil otherwise." |
non-comment Fortran statement in the file, and nil otherwise." |
969 |
(interactive) |
(interactive) |
989 |
'first-statement)))) |
'first-statement)))) |
990 |
|
|
991 |
(defun fortran-next-statement () |
(defun fortran-next-statement () |
992 |
"Moves point to beginning of the next Fortran statement. |
"Move point to beginning of the next Fortran statement. |
993 |
Returns `last-statement' if that statement is the last |
Returns `last-statement' if that statement is the last |
994 |
non-comment Fortran statement in the file, and nil otherwise." |
non-comment Fortran statement in the file, and nil otherwise." |
995 |
(interactive) |
(interactive) |
1101 |
(fortran-check-end-prog-re)))) |
(fortran-check-end-prog-re)))) |
1102 |
(skip-chars-forward " \t0-9") |
(skip-chars-forward " \t0-9") |
1103 |
(cond ((looking-at |
(cond ((looking-at |
1104 |
"\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?do[ \t]+[^0-9]") |
"\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?do[ \t]+[0-9]") |
1105 |
(setq count (1- count))) |
(setq count (1- count))) |
1106 |
((looking-at "end[ \t]*do\\b") |
((looking-at "end[ \t]*do\\b") |
1107 |
(setq count (1+ count))))) |
(setq count (1+ count))))) |
1218 |
(setq then-test |
(setq then-test |
1219 |
(looking-at |
(looking-at |
1220 |
(concat ".*then\\b[ \t]*" |
(concat ".*then\\b[ \t]*" |
1221 |
"[^ \t(=a-z[0-9]]")))))) |
"[^ \t(=a-z0-9]")))))) |
1222 |
then-test)) |
then-test)) |
1223 |
(setq count (- count 1))))) |
(setq count (- count 1))))) |
1224 |
((looking-at "end[ \t]*if\\b") |
((looking-at "end[ \t]*if\\b") |
1737 |
;; paragraph, delimited either by non-comment lines or empty |
;; paragraph, delimited either by non-comment lines or empty |
1738 |
;; comments. (Get positions as markers, since the |
;; comments. (Get positions as markers, since the |
1739 |
;; `indent-region' below can shift the block's end). |
;; `indent-region' below can shift the block's end). |
1740 |
(let* ((non-empty-comment |
(let* ((non-empty-comment |
1741 |
(concat fortran-comment-line-start-skip "[^ \t\n]")) |
(concat fortran-comment-line-start-skip "[^ \t\n]")) |
1742 |
(start (save-excursion |
(start (save-excursion |
1743 |
;; Find (start of) first line. |
;; Find (start of) first line. |
1748 |
(point-marker))) |
(point-marker))) |
1749 |
(end (save-excursion |
(end (save-excursion |
1750 |
;; Find start of first line past region to fill. |
;; Find start of first line past region to fill. |
1751 |
(while (progn |
(while (progn |
1752 |
(forward-line) |
(forward-line) |
1753 |
(looking-at non-empty-comment))) |
(looking-at non-empty-comment))) |
1754 |
(point-marker)))) |
(point-marker)))) |