aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Love1998-11-23 15:15:09 +0000
committerDave Love1998-11-23 15:15:09 +0000
commit45cf60ae1a7d8f39d0f215ab615124cbb17f49e2 (patch)
tree303ce9206a4859aaf19a15570b4de61e3a102baa
parent58523e005bfad5ae9ac9ce1ff67699dc75c8ec4b (diff)
downloademacs-45cf60ae1a7d8f39d0f215ab615124cbb17f49e2.tar.gz
emacs-45cf60ae1a7d8f39d0f215ab615124cbb17f49e2.zip
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.
-rw-r--r--lisp/progmodes/fortran.el123
1 files changed, 75 insertions, 48 deletions
diff --git a/lisp/progmodes/fortran.el b/lisp/progmodes/fortran.el
index d32e547ba9d..10ff6f93a23 100644
--- a/lisp/progmodes/fortran.el
+++ b/lisp/progmodes/fortran.el
@@ -28,7 +28,7 @@
28;; This mode is documented in the Emacs manual. 28;; This mode is documented in the Emacs manual.
29;; 29;;
30;; Note that it is for editing Fortran77 or Fortran90 fixed source 30;; Note that it is for editing Fortran77 or Fortran90 fixed source
31;; form. For editing Fortran90 free format source, use `f90-mode' 31;; form. For editing Fortran 90 free format source, use `f90-mode'
32;; (f90.el). 32;; (f90.el).
33 33
34;;; History: 34;;; History:
@@ -42,12 +42,17 @@
42 42
43;;; Code: 43;;; Code:
44 44
45;; Todo: 45;; Todo:
46 46
47;; * Tidy it all up! (including renaming non-`fortran' prefixed
48;; functions).
47;; * Implement insertion and removal of statement continuations in 49;; * Implement insertion and removal of statement continuations in
48;; mixed f77/f90 style, with the first `&' past column 72 and the 50;; mixed f77/f90 style, with the first `&' past column 72 and the
49;; second in column 6. 51;; second in column 6.
50;; * Support other f90-style stuff grokked by GNU Fortran. 52;; * Support any other extensions to f77 grokked by GNU Fortran.
53;; * Change fontification to use font-lock-syntactic-keywords for
54;; fixed-form comments. (Done, but doesn't work properly with
55;; lazy-lock in pre-20.4.)
51 56
52(require 'easymenu) 57(require 'easymenu)
53 58
@@ -262,7 +267,7 @@ format style.")
262 ((string= "\"" match) 267 ((string= "\"" match)
263 (re-search-forward "\\([^\"\n]*\"?\\)" limit))))) 268 (re-search-forward "\\([^\"\n]*\"?\\)" limit)))))
264 269
265(let ((comment-chars "c!*") 270(let ((comment-chars "c!*d") ; `d' for `debugging' comments
266 (fortran-type-types 271 (fortran-type-types
267; (eval-when-compile 272; (eval-when-compile
268; (regexp-opt 273; (regexp-opt
@@ -317,7 +322,7 @@ format style.")
317 (list 322 (list
318 ;; 323 ;;
319 ;; Fontify all type specifiers (must be first; see below). 324 ;; Fontify all type specifiers (must be first; see below).
320 (cons (concat "\\<\\(" fortran-type-types "\\)\\>") 325 (cons (concat "\\<\\(" fortran-type-types "\\)\\>")
321 'font-lock-type-face) 326 'font-lock-type-face)
322 ;; 327 ;;
323 ;; Fontify all builtin keywords (except logical, do 328 ;; Fontify all builtin keywords (except logical, do
@@ -396,7 +401,7 @@ format style.")
396 3) 401 3)
397 ;; Un-named block data 402 ;; Un-named block data
398 (list nil "^\\s-+\\(block\\s-*data\\)\\s-*$" 1)) 403 (list nil "^\\s-+\\(block\\s-*data\\)\\s-*$" 1))
399 "imenu generic expression for `imenu-default-create-index-function'.") 404 "Imenu generic expression for `imenu-default-create-index-function'.")
400 405
401(defvar fortran-mode-map () 406(defvar fortran-mode-map ()
402 "Keymap used in Fortran mode.") 407 "Keymap used in Fortran mode.")
@@ -557,21 +562,21 @@ Key definitions:
557 562
558Variables controlling indentation style and extra features: 563Variables controlling indentation style and extra features:
559 564
560 comment-start 565 `comment-start'
561 Normally nil in Fortran mode. If you want to use comments 566 Normally nil in Fortran mode. If you want to use comments
562 starting with `!', set this to the string \"!\". 567 starting with `!', set this to the string \"!\".
563 fortran-do-indent 568 `fortran-do-indent'
564 Extra indentation within do blocks. (default 3) 569 Extra indentation within do blocks. (default 3)
565 fortran-if-indent 570 `fortran-if-indent'
566 Extra indentation within if blocks. (default 3) 571 Extra indentation within if blocks. (default 3)
567 fortran-structure-indent 572 `fortran-structure-indent'
568 Extra indentation within structure, union, map and interface blocks. 573 Extra indentation within structure, union, map and interface blocks.
569 (default 3) 574 (default 3)
570 fortran-continuation-indent 575 `fortran-continuation-indent'
571 Extra indentation applied to continuation statements. (default 5) 576 Extra indentation applied to continuation statements. (default 5)
572 fortran-comment-line-extra-indent 577 `fortran-comment-line-extra-indent'
573 Amount of extra indentation for text within full-line comments. (default 0) 578 Amount of extra indentation for text within full-line comments. (default 0)
574 fortran-comment-indent-style 579 `fortran-comment-indent-style'
575 nil means don't change indentation of text in full-line comments, 580 nil means don't change indentation of text in full-line comments,
576 fixed means indent that text at `fortran-comment-line-extra-indent' beyond 581 fixed means indent that text at `fortran-comment-line-extra-indent' beyond
577 the value of `fortran-minimum-statement-indent-fixed' (for fixed 582 the value of `fortran-minimum-statement-indent-fixed' (for fixed
@@ -580,34 +585,34 @@ Variables controlling indentation style and extra features:
580 relative means indent at `fortran-comment-line-extra-indent' beyond the 585 relative means indent at `fortran-comment-line-extra-indent' beyond the
581 indentation for a line of code. 586 indentation for a line of code.
582 (default 'fixed) 587 (default 'fixed)
583 fortran-comment-indent-char 588 `fortran-comment-indent-char'
584 Single-character string to be inserted instead of space for 589 Single-character string to be inserted instead of space for
585 full-line comment indentation. (default \" \") 590 full-line comment indentation. (default \" \")
586 fortran-minimum-statement-indent-fixed 591 `fortran-minimum-statement-indent-fixed'
587 Minimum indentation for Fortran statements in fixed format mode. (def.6) 592 Minimum indentation for Fortran statements in fixed format mode. (def.6)
588 fortran-minimum-statement-indent-tab 593 `fortran-minimum-statement-indent-tab'
589 Minimum indentation for Fortran statements in TAB format mode. (default 9) 594 Minimum indentation for Fortran statements in TAB format mode. (default 9)
590 fortran-line-number-indent 595 `fortran-line-number-indent'
591 Maximum indentation for line numbers. A line number will get 596 Maximum indentation for line numbers. A line number will get
592 less than this much indentation if necessary to avoid reaching 597 less than this much indentation if necessary to avoid reaching
593 column 5. (default 1) 598 column 5. (default 1)
594 fortran-check-all-num-for-matching-do 599 `fortran-check-all-num-for-matching-do'
595 Non-nil causes all numbered lines to be treated as possible \"continue\" 600 Non-nil causes all numbered lines to be treated as possible \"continue\"
596 statements. (default nil) 601 statements. (default nil)
597 fortran-blink-matching-if 602 `fortran-blink-matching-if'
598 Non-nil causes \\[fortran-indent-line] on an ENDIF statement to blink on 603 Non-nil causes \\[fortran-indent-line] on an ENDIF statement to blink on
599 matching IF. Also, from an ENDDO statement, blink on matching DO [WHILE] 604 matching IF. Also, from an ENDDO statement, blink on matching DO [WHILE]
600 statement. (default nil) 605 statement. (default nil)
601 fortran-continuation-string 606 `fortran-continuation-string'
602 Single-character string to be inserted in column 5 of a continuation 607 Single-character string to be inserted in column 5 of a continuation
603 line. (default \"$\") 608 line. (default \"$\")
604 fortran-comment-region 609 `fortran-comment-region'
605 String inserted by \\[fortran-comment-region] at start of each line in 610 String inserted by \\[fortran-comment-region] at start of each line in
606 region. (default \"c$$$\") 611 region. (default \"c$$$\")
607 fortran-electric-line-number 612 `fortran-electric-line-number'
608 Non-nil causes line number digits to be moved to the correct column 613 Non-nil causes line number digits to be moved to the correct column
609 as typed. (default t) 614 as typed. (default t)
610 fortran-break-before-delimiters 615 `fortran-break-before-delimiters'
611 Non-nil causes `fortran-fill' to break lines before delimiters. 616 Non-nil causes `fortran-fill' to break lines before delimiters.
612 (default t) 617 (default t)
613 618
@@ -654,7 +659,7 @@ with no args, if that value is non-nil."
654 (make-local-variable 'fortran-minimum-statement-indent-fixed) 659 (make-local-variable 'fortran-minimum-statement-indent-fixed)
655 (make-local-variable 'fortran-minimum-statement-indent-tab) 660 (make-local-variable 'fortran-minimum-statement-indent-tab)
656 (make-local-variable 'fortran-column-ruler-fixed) 661 (make-local-variable 'fortran-column-ruler-fixed)
657 (make-local-variable 'fortran-column-ruler-tab) 662 (make-local-variable 'fortran-column-ruler-tab)
658 (setq fortran-tab-mode-string " TAB-format") 663 (setq fortran-tab-mode-string " TAB-format")
659 (setq indent-tabs-mode (fortran-analyze-file-format)) 664 (setq indent-tabs-mode (fortran-analyze-file-format))
660 (setq imenu-case-fold-search t) 665 (setq imenu-case-fold-search t)
@@ -911,7 +916,6 @@ Auto-indent does not happen if a numeric ARG is used."
911 "end\ 916 "end\
912\\([ \t]*\\(program\\|subroutine\\|function\\|block[ \t]*data\\)\\>\ 917\\([ \t]*\\(program\\|subroutine\\|function\\|block[ \t]*data\\)\\>\
913\\([ \t]*\\(\\sw\\|\\s_\\)+\\)?\\)?") 918\\([ \t]*\\(\\sw\\|\\s_\\)+\\)?\\)?")
914
915(defvar fortran-end-prog-re 919(defvar fortran-end-prog-re
916 (concat "^[ \t0-9]*" fortran-end-prog-re1) 920 (concat "^[ \t0-9]*" fortran-end-prog-re1)
917 "Regexp possibly marking subprogram end.") 921 "Regexp possibly marking subprogram end.")
@@ -1018,9 +1022,22 @@ The subprogram visible is the one that contains or follows point."
1018 (mark-fortran-subprogram) 1022 (mark-fortran-subprogram)
1019 (narrow-to-region (region-beginning) 1023 (narrow-to-region (region-beginning)
1020 (region-end)))) 1024 (region-end))))
1025
1026(defmacro fortran-with-subprogram-narrowing (&rest forms)
1027 "Execute FORMS with buffer temporarily narrowed to current subprogram.
1028Doesn't push a mark."
1029 `(save-restriction
1030 (save-excursion
1031 (narrow-to-region (progn
1032 (beginning-of-fortran-subprogram)
1033 (point))
1034 (progn
1035 (end-of-fortran-subprogram)
1036 (point))))
1037 ,@forms))
1021 1038
1022(defun fortran-blink-matching-if () 1039(defun fortran-blink-matching-if ()
1023 ;; From a Fortran ENDIF statement, blink the matching IF statement. 1040 "From an ENDIF statement, blink the matching IF statement."
1024 (let ((top-of-window (window-start)) 1041 (let ((top-of-window (window-start))
1025 (endif-point (point)) 1042 (endif-point (point))
1026 (case-fold-search t) 1043 (case-fold-search t)
@@ -1047,8 +1064,8 @@ The subprogram visible is the one that contains or follows point."
1047 (goto-char endif-point)))))) 1064 (goto-char endif-point))))))
1048 1065
1049(defun fortran-blink-matching-do () 1066(defun fortran-blink-matching-do ()
1050 ;; From a Fortran ENDDO statement, blink on the matching DO or DO WHILE 1067 "From an ENDDO statement, blink the matching DO or DO WHILE statement."
1051 ;; statement. This is basically copied from fortran-blink-matching-if. 1068 ;; This is basically copied from fortran-blink-matching-if.
1052 (let ((top-of-window (window-start)) 1069 (let ((top-of-window (window-start))
1053 (enddo-point (point)) 1070 (enddo-point (point))
1054 (case-fold-search t) 1071 (case-fold-search t)
@@ -1088,7 +1105,8 @@ The marks are pushed."
1088 (goto-char do-point))))) 1105 (goto-char do-point)))))
1089 1106
1090(defun fortran-end-do () 1107(defun fortran-end-do ()
1091 ;; Search forward for first unmatched ENDDO. Return point or nil. 1108 "Search forward for first unmatched ENDDO.
1109Return point or nil."
1092 (let ((case-fold-search t)) 1110 (let ((case-fold-search t))
1093 (if (save-excursion (beginning-of-line) 1111 (if (save-excursion (beginning-of-line)
1094 (skip-chars-forward " \t0-9") 1112 (skip-chars-forward " \t0-9")
@@ -1101,7 +1119,8 @@ The marks are pushed."
1101 (while (and (not (= count 0)) 1119 (while (and (not (= count 0))
1102 (not (eq (fortran-next-statement) 'last-statement)) 1120 (not (eq (fortran-next-statement) 'last-statement))
1103 ;; Keep local to subprogram 1121 ;; Keep local to subprogram
1104 (not (looking-at fortran-end-prog-re))) 1122 (not (and (looking-at fortran-end-prog-re)
1123 (fortran-check-end-prog-re))))
1105 1124
1106 (skip-chars-forward " \t0-9") 1125 (skip-chars-forward " \t0-9")
1107 (cond ((looking-at "end[ \t]*do\\b") 1126 (cond ((looking-at "end[ \t]*do\\b")
@@ -1113,7 +1132,8 @@ The marks are pushed."
1113 (point))))))) 1132 (point)))))))
1114 1133
1115(defun fortran-beginning-do () 1134(defun fortran-beginning-do ()
1116 ;; Search backwards for first unmatched DO [WHILE]. Return point or nil. 1135 "Search backwards for first unmatched DO [WHILE].
1136Return point or nil."
1117 (let ((case-fold-search t)) 1137 (let ((case-fold-search t))
1118 (if (save-excursion (beginning-of-line) 1138 (if (save-excursion (beginning-of-line)
1119 (skip-chars-forward " \t0-9") 1139 (skip-chars-forward " \t0-9")
@@ -1126,7 +1146,8 @@ The marks are pushed."
1126 (while (and (not (= count 0)) 1146 (while (and (not (= count 0))
1127 (not (eq (fortran-previous-statement) 'first-statement)) 1147 (not (eq (fortran-previous-statement) 'first-statement))
1128 ;; Keep local to subprogram 1148 ;; Keep local to subprogram
1129 (not (looking-at fortran-end-prog-re))) 1149 (not (and (looking-at fortran-end-prog-re)
1150 (fortran-check-end-prog-re))))
1130 1151
1131 (skip-chars-forward " \t0-9") 1152 (skip-chars-forward " \t0-9")
1132 (cond ((looking-at "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?do[ \t]+[^0-9]") 1153 (cond ((looking-at "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?do[ \t]+[^0-9]")
@@ -1154,7 +1175,8 @@ The marks are pushed."
1154(defvar fortran-if-start-re "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?if[ \t]*(") 1175(defvar fortran-if-start-re "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?if[ \t]*(")
1155 1176
1156(defun fortran-end-if () 1177(defun fortran-end-if ()
1157 ;; Search forwards for first unmatched ENDIF. Return point or nil. 1178 "Search forwards for first unmatched ENDIF.
1179Return point or nil."
1158 (let ((case-fold-search t)) 1180 (let ((case-fold-search t))
1159 (if (save-excursion (beginning-of-line) 1181 (if (save-excursion (beginning-of-line)
1160 (skip-chars-forward " \t0-9") 1182 (skip-chars-forward " \t0-9")
@@ -1168,7 +1190,8 @@ The marks are pushed."
1168 (while (and (not (= count 0)) 1190 (while (and (not (= count 0))
1169 (not (eq (fortran-next-statement) 'last-statement)) 1191 (not (eq (fortran-next-statement) 'last-statement))
1170 ;; Keep local to subprogram. 1192 ;; Keep local to subprogram.
1171 (not (looking-at fortran-end-prog-re))) 1193 (not (and (looking-at fortran-end-prog-re)
1194 (fortran-check-end-prog-re))))
1172 1195
1173 (skip-chars-forward " \t0-9") 1196 (skip-chars-forward " \t0-9")
1174 (cond ((looking-at "end[ \t]*if\\b") 1197 (cond ((looking-at "end[ \t]*if\\b")
@@ -1196,7 +1219,8 @@ The marks are pushed."
1196 (point))))))) 1219 (point)))))))
1197 1220
1198(defun fortran-beginning-if () 1221(defun fortran-beginning-if ()
1199 ;; Search backwards for first unmatched IF-THEN. Return point or nil. 1222 "Search backwards for first unmatched IF-THEN.
1223Return point or nil."
1200 (let ((case-fold-search t)) 1224 (let ((case-fold-search t))
1201 (if (save-excursion 1225 (if (save-excursion
1202 ;; May be sitting on multi-line if-then statement, first move to 1226 ;; May be sitting on multi-line if-then statement, first move to
@@ -1230,7 +1254,8 @@ The marks are pushed."
1230 (while (and (not (= count 0)) 1254 (while (and (not (= count 0))
1231 (not (eq (fortran-previous-statement) 'first-statement)) 1255 (not (eq (fortran-previous-statement) 'first-statement))
1232 ;; Keep local to subprogram. 1256 ;; Keep local to subprogram.
1233 (not (looking-at fortran-end-prog-re))) 1257 (not (and (looking-at fortran-end-prog-re)
1258 (fortran-check-end-prog-re))))
1234 1259
1235 (skip-chars-forward " \t0-9") 1260 (skip-chars-forward " \t0-9")
1236 (cond ((looking-at fortran-if-start-re) 1261 (cond ((looking-at fortran-if-start-re)
@@ -1285,7 +1310,7 @@ The marks are pushed."
1285 1310
1286(defun fortran-indent-new-line () 1311(defun fortran-indent-new-line ()
1287 "Reindent the current Fortran line, insert a newline and indent the newline. 1312 "Reindent the current Fortran line, insert a newline and indent the newline.
1288An abbrev before point is expanded if `abbrev-mode' is non-nil." 1313An abbrev before point is expanded if variable `abbrev-mode' is non-nil."
1289 (interactive) 1314 (interactive)
1290 (if abbrev-mode (expand-abbrev)) 1315 (if abbrev-mode (expand-abbrev))
1291 (save-excursion 1316 (save-excursion
@@ -1354,7 +1379,8 @@ An abbrev before point is expanded if `abbrev-mode' is non-nil."
1354 ((looking-at 1379 ((looking-at
1355 "\\(structure\\|union\\|map\\|interface\\)\\b[ \t]*[^ \t=(a-z]") 1380 "\\(structure\\|union\\|map\\|interface\\)\\b[ \t]*[^ \t=(a-z]")
1356 (setq icol (+ icol fortran-structure-indent))) 1381 (setq icol (+ icol fortran-structure-indent)))
1357 ((looking-at fortran-end-prog-re1) 1382 ((and (looking-at fortran-end-prog-re1)
1383 (fortran-check-end-prog-re))
1358 ;; Previous END resets indent to minimum 1384 ;; Previous END resets indent to minimum
1359 (setq icol fortran-minimum-statement-indent)))))) 1385 (setq icol fortran-minimum-statement-indent))))))
1360 (save-excursion 1386 (save-excursion
@@ -1399,6 +1425,7 @@ An abbrev before point is expanded if `abbrev-mode' is non-nil."
1399\\(structure\\|union\\|map\\|interface\\)\\b[ \t]*[^ \t=(a-z]") 1425\\(structure\\|union\\|map\\|interface\\)\\b[ \t]*[^ \t=(a-z]")
1400 (setq icol (- icol fortran-structure-indent))) 1426 (setq icol (- icol fortran-structure-indent)))
1401 ((and (looking-at fortran-end-prog-re1) 1427 ((and (looking-at fortran-end-prog-re1)
1428 (fortran-check-end-prog-re)
1402 (not (= icol fortran-minimum-statement-indent))) 1429 (not (= icol fortran-minimum-statement-indent)))
1403 (message "Warning: `end' not in column %d. Probably\ 1430 (message "Warning: `end' not in column %d. Probably\
1404 an unclosed block." fortran-minimum-statement-indent)))))) 1431 an unclosed block." fortran-minimum-statement-indent))))))
@@ -1519,12 +1546,12 @@ Otherwise return nil."
1519 (progn (skip-chars-forward "0-9") 1546 (progn (skip-chars-forward "0-9")
1520 (point)))) 1547 (point))))
1521 (beginning-of-line) 1548 (beginning-of-line)
1522 (and (re-search-backward 1549 (fortran-with-subprogram-narrowing
1523 (concat "\\(" fortran-end-prog-re "\\)\\|" 1550 (and (re-search-backward
1524 "\\(^[ \t0-9]*do[ \t]*0*" charnum "\\b\\)\\|" 1551 (concat "\\(^[ \t0-9]*do[ \t]*0*" charnum "\\b\\)\\|"
1525 "\\(^[ \t]*0*" charnum "\\b\\)") 1552 "\\(^[ \t]*0*" charnum "\\b\\)")
1526 nil t) 1553 nil t)
1527 (looking-at (concat "^[ \t0-9]*do[ \t]*0*" charnum)))))))) 1554 (looking-at (concat "^[ \t0-9]*do[ \t]*0*" charnum)))))))))
1528 1555
1529(defun fortran-find-comment-start-skip () 1556(defun fortran-find-comment-start-skip ()
1530 "Move to past `comment-start-skip' found on current line. 1557 "Move to past `comment-start-skip' found on current line.
@@ -1840,7 +1867,7 @@ Intended as the value of `fill-paragraph-function'."
1840 (fortran-indent-line) 1867 (fortran-indent-line)
1841 ;; Replace newline plus continuation field plus indentation with 1868 ;; Replace newline plus continuation field plus indentation with
1842 ;; single space. 1869 ;; single space.
1843 (while (progn 1870 (while (progn
1844 (forward-line) 1871 (forward-line)
1845 (fortran-remove-continuation))) 1872 (fortran-remove-continuation)))
1846 (fortran-previous-statement))) 1873 (fortran-previous-statement)))