changeset 23754:53a4f2e0fccc

Various minor doc fixes. (fortran-font-lock-keywords-1): Add `d' to comment-chars. (fortran-with-subprogram-narrowing): New macro. fortran-check-for-matching-do): Use it. (fortran-end-do): Use fortran-check-end-prog-re. (fortran-beginning-do, fortran-end-if, fortran-beginning-if) (fortran-calculate-indent, fortran-calculate-indent): Likewise.
author Dave Love <fx@gnu.org>
date Mon, 23 Nov 1998 15:15:09 +0000
parents c1bedc24e8af
children 63628f8fe648
files lisp/progmodes/fortran.el
diffstat 1 files changed, 75 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/progmodes/fortran.el	Mon Nov 23 11:14:33 1998 +0000
+++ b/lisp/progmodes/fortran.el	Mon Nov 23 15:15:09 1998 +0000
@@ -28,7 +28,7 @@
 ;; This mode is documented in the Emacs manual.
 ;;
 ;; Note that it is for editing Fortran77 or Fortran90 fixed source
-;; form.  For editing Fortran90 free format source, use `f90-mode'
+;; form.  For editing Fortran 90 free format source, use `f90-mode'
 ;; (f90.el).
 
 ;;; History:
@@ -42,12 +42,17 @@
 
 ;;; Code:
 
-;; Todo: 
+;; Todo:
 
+;; * Tidy it all up!  (including renaming non-`fortran' prefixed
+;;   functions).
 ;; * Implement insertion and removal of statement continuations in
 ;;   mixed f77/f90 style, with the first `&' past column 72 and the
 ;;   second in column 6.
-;; * Support other f90-style stuff grokked by GNU Fortran.
+;; * Support any other extensions to f77 grokked by GNU Fortran.
+;; * Change fontification to use font-lock-syntactic-keywords for
+;;   fixed-form comments.  (Done, but doesn't work properly with
+;;   lazy-lock in pre-20.4.)
 
 (require 'easymenu)
 
@@ -262,7 +267,7 @@
 	  ((string= "\"" match)
 	   (re-search-forward "\\([^\"\n]*\"?\\)" limit)))))
 
-(let ((comment-chars "c!*")
+(let ((comment-chars "c!*d")		; `d' for `debugging' comments
       (fortran-type-types
 ;       (eval-when-compile
 ;         (regexp-opt
@@ -317,7 +322,7 @@
                 (list
                  ;;
                  ;; Fontify all type specifiers (must be first; see below).
-                 (cons (concat "\\<\\(" fortran-type-types "\\)\\>") 
+                 (cons (concat "\\<\\(" fortran-type-types "\\)\\>")
                        'font-lock-type-face)
                  ;;
                  ;; Fontify all builtin keywords (except logical, do
@@ -396,7 +401,7 @@
     3)
    ;; Un-named block data
    (list nil "^\\s-+\\(block\\s-*data\\)\\s-*$" 1))
-  "imenu generic expression for `imenu-default-create-index-function'.")
+  "Imenu generic expression for `imenu-default-create-index-function'.")
 
 (defvar fortran-mode-map ()
   "Keymap used in Fortran mode.")
@@ -557,21 +562,21 @@
 
 Variables controlling indentation style and extra features:
 
- comment-start
+ `comment-start'
     Normally nil in Fortran mode.  If you want to use comments
     starting with `!', set this to the string \"!\".
- fortran-do-indent
+ `fortran-do-indent'
     Extra indentation within do blocks.  (default 3)
- fortran-if-indent
+ `fortran-if-indent'
     Extra indentation within if blocks.  (default 3)
- fortran-structure-indent
+ `fortran-structure-indent'
     Extra indentation within structure, union, map and interface blocks.
     (default 3)
- fortran-continuation-indent
+ `fortran-continuation-indent'
     Extra indentation applied to continuation statements.  (default 5)
- fortran-comment-line-extra-indent
-    Amount of extra indentation for text within full-line comments. (default 0)
- fortran-comment-indent-style
+ `fortran-comment-line-extra-indent'
+    Amount of extra indentation for text within full-line comments.  (default 0)
+ `fortran-comment-indent-style'
     nil    means don't change indentation of text in full-line comments,
     fixed  means indent that text at `fortran-comment-line-extra-indent' beyond
            the value of `fortran-minimum-statement-indent-fixed' (for fixed
@@ -580,34 +585,34 @@
     relative  means indent at `fortran-comment-line-extra-indent' beyond the
  	      indentation for a line of code.
     (default 'fixed)
- fortran-comment-indent-char
+ `fortran-comment-indent-char'
     Single-character string to be inserted instead of space for
     full-line comment indentation.  (default \" \")
- fortran-minimum-statement-indent-fixed
-    Minimum indentation for Fortran statements in fixed format mode. (def.6)
- fortran-minimum-statement-indent-tab
-    Minimum indentation for Fortran statements in TAB format mode. (default 9)
- fortran-line-number-indent
+ `fortran-minimum-statement-indent-fixed'
+    Minimum indentation for Fortran statements in fixed format mode.  (def.6)
+ `fortran-minimum-statement-indent-tab'
+    Minimum indentation for Fortran statements in TAB format mode.  (default 9)
+ `fortran-line-number-indent'
     Maximum indentation for line numbers.  A line number will get
     less than this much indentation if necessary to avoid reaching
     column 5.  (default 1)
- fortran-check-all-num-for-matching-do
+ `fortran-check-all-num-for-matching-do'
     Non-nil causes all numbered lines to be treated as possible \"continue\"
     statements.  (default nil)
- fortran-blink-matching-if
+ `fortran-blink-matching-if'
     Non-nil causes \\[fortran-indent-line] on an ENDIF statement to blink on
     matching IF.  Also, from an ENDDO statement, blink on matching DO [WHILE]
     statement.  (default nil)
- fortran-continuation-string
+ `fortran-continuation-string'
     Single-character string to be inserted in column 5 of a continuation
     line.  (default \"$\")
- fortran-comment-region
+ `fortran-comment-region'
     String inserted by \\[fortran-comment-region] at start of each line in
     region.  (default \"c$$$\")
- fortran-electric-line-number
+ `fortran-electric-line-number'
     Non-nil causes line number digits to be moved to the correct column
     as typed.  (default t)
- fortran-break-before-delimiters
+ `fortran-break-before-delimiters'
     Non-nil causes `fortran-fill' to break lines before delimiters.
     (default t)
 
@@ -654,7 +659,7 @@
   (make-local-variable 'fortran-minimum-statement-indent-fixed)
   (make-local-variable 'fortran-minimum-statement-indent-tab)
   (make-local-variable 'fortran-column-ruler-fixed)
-  (make-local-variable 'fortran-column-ruler-tab) 
+  (make-local-variable 'fortran-column-ruler-tab)
   (setq fortran-tab-mode-string " TAB-format")
   (setq indent-tabs-mode (fortran-analyze-file-format))
   (setq imenu-case-fold-search t)
@@ -911,7 +916,6 @@
   "end\
 \\([ \t]*\\(program\\|subroutine\\|function\\|block[ \t]*data\\)\\>\
 \\([ \t]*\\(\\sw\\|\\s_\\)+\\)?\\)?")
-
 (defvar fortran-end-prog-re
   (concat "^[ \t0-9]*" fortran-end-prog-re1)
   "Regexp possibly marking subprogram end.")
@@ -1018,9 +1022,22 @@
           (mark-fortran-subprogram)
           (narrow-to-region (region-beginning)
                             (region-end))))
+
+(defmacro fortran-with-subprogram-narrowing (&rest forms)
+  "Execute FORMS with buffer temporarily narrowed to current subprogram.
+Doesn't push a mark."
+  `(save-restriction
+     (save-excursion
+       (narrow-to-region (progn
+			   (beginning-of-fortran-subprogram)
+			   (point))
+			 (progn
+			   (end-of-fortran-subprogram)
+			   (point))))
+     ,@forms))
 
 (defun fortran-blink-matching-if ()
-  ;; From a Fortran ENDIF statement, blink the matching IF statement.
+  "From an ENDIF statement, blink the matching IF statement."
   (let ((top-of-window (window-start))
 	(endif-point (point))
 	(case-fold-search t)
@@ -1047,8 +1064,8 @@
 	    (goto-char endif-point))))))
 
 (defun fortran-blink-matching-do ()
-  ;; From a Fortran ENDDO statement, blink on the matching DO or DO WHILE
-  ;; statement.  This is basically copied from fortran-blink-matching-if.
+  "From an ENDDO statement, blink the matching DO or DO WHILE statement."
+  ;; This is basically copied from fortran-blink-matching-if.
   (let ((top-of-window (window-start))
 	(enddo-point (point))
 	(case-fold-search t)
@@ -1088,7 +1105,8 @@
           (goto-char do-point)))))
 
 (defun fortran-end-do ()
-  ;; Search forward for first unmatched ENDDO.  Return point or nil.
+  "Search forward for first unmatched ENDDO.
+Return point or nil."
   (let ((case-fold-search t))
     (if (save-excursion (beginning-of-line)
 			(skip-chars-forward " \t0-9")
@@ -1101,7 +1119,8 @@
         (while (and (not (= count 0))
 		      (not (eq (fortran-next-statement) 'last-statement))
 		      ;; Keep local to subprogram
-		      (not (looking-at fortran-end-prog-re)))
+		      (not (and (looking-at fortran-end-prog-re)
+				(fortran-check-end-prog-re))))
 
 	    (skip-chars-forward " \t0-9")
 	    (cond ((looking-at "end[ \t]*do\\b")
@@ -1113,7 +1132,8 @@
 	       (point)))))))
 
 (defun fortran-beginning-do ()
-  ;; Search backwards for first unmatched DO [WHILE].  Return point or nil.
+  "Search backwards for first unmatched DO [WHILE].
+Return point or nil."
   (let ((case-fold-search t))
     (if (save-excursion (beginning-of-line)
 			(skip-chars-forward " \t0-9")
@@ -1126,7 +1146,8 @@
         (while (and (not (= count 0))
 		      (not (eq (fortran-previous-statement) 'first-statement))
 		      ;; Keep local to subprogram
-		      (not (looking-at fortran-end-prog-re)))
+		      (not (and (looking-at fortran-end-prog-re)
+				(fortran-check-end-prog-re))))
 
 	    (skip-chars-forward " \t0-9")
 	    (cond ((looking-at "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?do[ \t]+[^0-9]")
@@ -1154,7 +1175,8 @@
 (defvar fortran-if-start-re "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?if[ \t]*(")
 
 (defun fortran-end-if ()
-  ;; Search forwards for first unmatched ENDIF.  Return point or nil.
+  "Search forwards for first unmatched ENDIF.
+Return point or nil."
   (let ((case-fold-search t))
     (if (save-excursion (beginning-of-line)
 			(skip-chars-forward " \t0-9")
@@ -1168,7 +1190,8 @@
         (while (and (not (= count 0))
 		      (not (eq (fortran-next-statement) 'last-statement))
 		      ;; Keep local to subprogram.
-		      (not (looking-at fortran-end-prog-re)))
+		      (not (and (looking-at fortran-end-prog-re)
+				(fortran-check-end-prog-re))))
 
 	    (skip-chars-forward " \t0-9")
 	    (cond ((looking-at "end[ \t]*if\\b")
@@ -1196,7 +1219,8 @@
 	       (point)))))))
 
 (defun fortran-beginning-if ()
-  ;; Search backwards for first unmatched IF-THEN.  Return point or nil.
+  "Search backwards for first unmatched IF-THEN.
+Return point or nil."
   (let ((case-fold-search t))
     (if (save-excursion
 	  ;; May be sitting on multi-line if-then statement, first move to
@@ -1230,7 +1254,8 @@
         (while (and (not (= count 0))
 		      (not (eq (fortran-previous-statement) 'first-statement))
 		      ;; Keep local to subprogram.
-		      (not (looking-at fortran-end-prog-re)))
+		      (not (and (looking-at fortran-end-prog-re)
+				(fortran-check-end-prog-re))))
 
 	    (skip-chars-forward " \t0-9")
 	    (cond ((looking-at fortran-if-start-re)
@@ -1285,7 +1310,7 @@
 
 (defun fortran-indent-new-line ()
   "Reindent the current Fortran line, insert a newline and indent the newline.
-An abbrev before point is expanded if `abbrev-mode' is non-nil."
+An abbrev before point is expanded if variable `abbrev-mode' is non-nil."
   (interactive)
   (if abbrev-mode (expand-abbrev))
   (save-excursion
@@ -1354,7 +1379,8 @@
 		((looking-at
 		  "\\(structure\\|union\\|map\\|interface\\)\\b[ \t]*[^ \t=(a-z]")
 		 (setq icol (+ icol fortran-structure-indent)))
-		((looking-at fortran-end-prog-re1)
+		((and (looking-at fortran-end-prog-re1)
+		      (fortran-check-end-prog-re))
 		 ;; Previous END resets indent to minimum
 		 (setq icol fortran-minimum-statement-indent))))))
     (save-excursion
@@ -1399,6 +1425,7 @@
 \\(structure\\|union\\|map\\|interface\\)\\b[ \t]*[^ \t=(a-z]")
 		    (setq icol (- icol fortran-structure-indent)))
 		   ((and (looking-at fortran-end-prog-re1)
+			 (fortran-check-end-prog-re)
 			 (not (= icol fortran-minimum-statement-indent)))
  		    (message "Warning: `end' not in column %d.  Probably\
  an unclosed block." fortran-minimum-statement-indent))))))
@@ -1519,12 +1546,12 @@
 					    (progn (skip-chars-forward "0-9")
 						   (point))))
 	    (beginning-of-line)
-	    (and (re-search-backward
-		  (concat "\\(" fortran-end-prog-re "\\)\\|"
-			  "\\(^[ \t0-9]*do[ \t]*0*" charnum "\\b\\)\\|"
-			  "\\(^[ \t]*0*" charnum "\\b\\)")
-		  nil t)
-		 (looking-at (concat "^[ \t0-9]*do[ \t]*0*" charnum))))))))
+	    (fortran-with-subprogram-narrowing
+	     (and (re-search-backward
+		   (concat "\\(^[ \t0-9]*do[ \t]*0*" charnum "\\b\\)\\|"
+			   "\\(^[ \t]*0*" charnum "\\b\\)")
+		   nil t)
+		  (looking-at (concat "^[ \t0-9]*do[ \t]*0*" charnum)))))))))
 
 (defun fortran-find-comment-start-skip ()
   "Move to past `comment-start-skip' found on current line.
@@ -1840,7 +1867,7 @@
         (fortran-indent-line)
         ;; Replace newline plus continuation field plus indentation with
         ;; single space.
-        (while (progn 
+        (while (progn
                  (forward-line)
                  (fortran-remove-continuation)))
         (fortran-previous-statement)))