Mercurial > emacs
comparison lisp/progmodes/fortran.el @ 5720:fe1a71db966f
(calculate-fortran-indent): Handle
Fortran 90 INTERFACE and SELECT/CASE blocks.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 01 Feb 1994 17:25:41 +0000 |
parents | cd3d59bc0b94 |
children | 23d9c2bc097b |
comparison
equal
deleted
inserted
replaced
5719:d3074ff90741 | 5720:fe1a71db966f |
---|---|
1 ;;; fortran.el --- Fortran mode for GNU Emacs | 1 ;;; fortran.el --- Fortran mode for GNU Emacs |
2 | 2 |
3 ;;; Copyright (c) 1986, 1993 Free Software Foundation, Inc. | 3 ;;; Copyright (c) 1986, 1993, 1994 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Michael D. Prange <prange@erl.mit.edu> | 5 ;; Author: Michael D. Prange <prange@erl.mit.edu> |
6 ;; Maintainer: bug-fortran-mode@erl.mit.edu | 6 ;; Maintainer: bug-fortran-mode@erl.mit.edu |
7 ;; Version 1.30.3 (November 16, 1993) | 7 ;; Version 1.30.4 (January 20, 1994) |
8 ;; Keywords: languages | 8 ;; Keywords: languages |
9 | 9 |
10 ;; This file is part of GNU Emacs. | 10 ;; This file is part of GNU Emacs. |
11 | 11 |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | 12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
44 ;;; comment-indent-function with comment-indent-hook | 44 ;;; comment-indent-function with comment-indent-hook |
45 ;;; (setq unread-command-events (list c)) with (setq unread-command-char c) | 45 ;;; (setq unread-command-events (list c)) with (setq unread-command-char c) |
46 | 46 |
47 ;;; Bugs to bug-fortran-mode@erl.mit.edu | 47 ;;; Bugs to bug-fortran-mode@erl.mit.edu |
48 | 48 |
49 (defconst fortran-mode-version "version 1.30.3") | 49 (defconst fortran-mode-version "version 1.30.4") |
50 | 50 |
51 ;;; Code: | 51 ;;; Code: |
52 | 52 |
53 ;;;###autoload | 53 ;;;###autoload |
54 (defvar fortran-tab-mode-default nil | 54 (defvar fortran-tab-mode-default nil |
57 A value of nil specifies that continuation lines are marked | 57 A value of nil specifies that continuation lines are marked |
58 with a character in column 6.") | 58 with a character in column 6.") |
59 | 59 |
60 ;; Buffer local, used to display mode line. | 60 ;; Buffer local, used to display mode line. |
61 (defvar fortran-tab-mode-string nil | 61 (defvar fortran-tab-mode-string nil |
62 "String to appear in mode line when TAB-format mode is on.") | 62 "String to appear in mode line when TAB format mode is on.") |
63 | 63 |
64 (defvar fortran-do-indent 3 | 64 (defvar fortran-do-indent 3 |
65 "*Extra indentation applied to DO blocks.") | 65 "*Extra indentation applied to DO blocks.") |
66 | 66 |
67 (defvar fortran-if-indent 3 | 67 (defvar fortran-if-indent 3 |
68 "*Extra indentation applied to IF blocks.") | 68 "*Extra indentation applied to IF blocks.") |
69 | 69 |
70 (defvar fortran-structure-indent 3 | 70 (defvar fortran-structure-indent 3 |
71 "*Extra indentation applied to STRUCTURE, UNION and MAP blocks.") | 71 "*Extra indentation applied to STRUCTURE, UNION, MAP and INTERFACE blocks.") |
72 | 72 |
73 (defvar fortran-continuation-indent 5 | 73 (defvar fortran-continuation-indent 5 |
74 "*Extra indentation applied to Fortran continuation lines.") | 74 "*Extra indentation applied to Fortran continuation lines.") |
75 | 75 |
76 (defvar fortran-comment-indent-style 'fixed | 76 (defvar fortran-comment-indent-style 'fixed |
136 "0 4 6 10 20 30 40 5\ | 136 "0 4 6 10 20 30 40 5\ |
137 0 60 70\n\ | 137 0 60 70\n\ |
138 [ ]|{ | | | | | | | | \ | 138 [ ]|{ | | | | | | | | \ |
139 | | | | |}\n" | 139 | | | | |}\n" |
140 "*String displayed above current line by \\[fortran-column-ruler]. | 140 "*String displayed above current line by \\[fortran-column-ruler]. |
141 This variable used in fixed-format mode.") | 141 This variable used in fixed format mode.") |
142 | 142 |
143 (defvar fortran-column-ruler-tab | 143 (defvar fortran-column-ruler-tab |
144 "0 810 20 30 40 5\ | 144 "0 810 20 30 40 5\ |
145 0 60 70\n\ | 145 0 60 70\n\ |
146 [ ]| { | | | | | | | | \ | 146 [ ]| { | | | | | | | | \ |
147 | | | | |}\n" | 147 | | | | |}\n" |
148 "*String displayed above current line by \\[fortran-column-ruler]. | 148 "*String displayed above current line by \\[fortran-column-ruler]. |
149 This variable used in TAB-format mode.") | 149 This variable used in TAB format mode.") |
150 | 150 |
151 (defconst bug-fortran-mode "bug-fortran-mode@erl.mit.edu" | 151 (defconst bug-fortran-mode "bug-fortran-mode@erl.mit.edu" |
152 "Address of mailing list for Fortran mode bugs.") | 152 "Address of mailing list for Fortran mode bugs.") |
153 | 153 |
154 (defvar fortran-mode-syntax-table nil | 154 (defvar fortran-mode-syntax-table nil |
293 fortran-do-indent | 293 fortran-do-indent |
294 Extra indentation within do blocks. (default 3) | 294 Extra indentation within do blocks. (default 3) |
295 fortran-if-indent | 295 fortran-if-indent |
296 Extra indentation within if blocks. (default 3) | 296 Extra indentation within if blocks. (default 3) |
297 fortran-structure-indent | 297 fortran-structure-indent |
298 Extra indentation within structure, union and map blocks. (default 3) | 298 Extra indentation within structure, union, map and interface blocks. |
299 (default 3) | |
299 fortran-continuation-indent | 300 fortran-continuation-indent |
300 Extra indentation applied to continuation statements. (default 5) | 301 Extra indentation applied to continuation statements. (default 5) |
301 fortran-comment-line-extra-indent | 302 fortran-comment-line-extra-indent |
302 Amount of extra indentation for text within full-line comments. (default 0) | 303 Amount of extra indentation for text within full-line comments. (default 0) |
303 fortran-comment-indent-style | 304 fortran-comment-indent-style |
489 (edit-abbrevs-mode)) | 490 (edit-abbrevs-mode)) |
490 (get-buffer-create "*Abbrevs*")) | 491 (get-buffer-create "*Abbrevs*")) |
491 | 492 |
492 (defun fortran-column-ruler () | 493 (defun fortran-column-ruler () |
493 "Inserts a column ruler momentarily above current line, till next keystroke. | 494 "Inserts a column ruler momentarily above current line, till next keystroke. |
494 The ruler is defined by the value of `fortran-column-ruler'. | 495 The ruler is defined by the value of `fortran-column-ruler-fixed' when in fixed |
496 format mode, and `fortran-column-ruler-tab' when in TAB format mode. | |
495 The key typed is executed unless it is SPC." | 497 The key typed is executed unless it is SPC." |
496 (interactive) | 498 (interactive) |
497 (momentary-string-display | 499 (momentary-string-display |
498 (if indent-tabs-mode | 500 (if indent-tabs-mode |
499 fortran-column-ruler-tab | 501 fortran-column-ruler-tab |
803 *[^ \t_$(=a-z0-9]"))))) | 805 *[^ \t_$(=a-z0-9]"))))) |
804 then-test)) | 806 then-test)) |
805 (setq icol (+ icol fortran-if-indent)))) | 807 (setq icol (+ icol fortran-if-indent)))) |
806 ((looking-at "\\(else\\|elseif\\)\\b") | 808 ((looking-at "\\(else\\|elseif\\)\\b") |
807 (setq icol (+ icol fortran-if-indent))) | 809 (setq icol (+ icol fortran-if-indent))) |
810 ((looking-at "select[ \t]*case[ \t](.*)\\b") | |
811 (setq icol (+ icol fortran-if-indent))) | |
812 ((looking-at "case[ \t]*(.*)[ \t]*\n") | |
813 (setq icol (+ icol fortran-if-indent))) | |
814 ((looking-at "case[ \t]*default\\b") | |
815 (setq icol (+ icol fortran-if-indent))) | |
808 ((looking-at "\\(otherwise\\|else[ \t]*where\\)\\b") | 816 ((looking-at "\\(otherwise\\|else[ \t]*where\\)\\b") |
809 (setq icol (+ icol fortran-if-indent))) | 817 (setq icol (+ icol fortran-if-indent))) |
810 ((looking-at "where[ \t]*(.*)[ \t]*\n") | 818 ((looking-at "where[ \t]*(.*)[ \t]*\n") |
811 (setq icol (+ icol fortran-if-indent))) | 819 (setq icol (+ icol fortran-if-indent))) |
812 ((looking-at "do\\b") | 820 ((looking-at "do\\b") |
813 (setq icol (+ icol fortran-do-indent))) | 821 (setq icol (+ icol fortran-do-indent))) |
814 ((looking-at | 822 ((looking-at |
815 "\\(structure\\|union\\|map\\)\\b[ \t]*[^ \t=(a-z]") | 823 "\\(structure\\|union\\|map\\|interface\\)\\b[ \t]*[^ \t=(a-z]") |
816 (setq icol (+ icol fortran-structure-indent))) | 824 (setq icol (+ icol fortran-structure-indent))) |
817 ((looking-at "end\\b[ \t]*[^ \t=(a-z]") | 825 ((looking-at "end\\b[ \t]*[^ \t=(a-z]") |
818 ;; Previous END resets indent to minimum | 826 ;; Previous END resets indent to minimum |
819 (setq icol fortran-minimum-statement-indent)))))) | 827 (setq icol fortran-minimum-statement-indent)))))) |
820 (save-excursion | 828 (save-excursion |
844 (skip-chars-forward " \t0-9") | 852 (skip-chars-forward " \t0-9") |
845 (cond ((looking-at "end[ \t]*if\\b") | 853 (cond ((looking-at "end[ \t]*if\\b") |
846 (setq icol (- icol fortran-if-indent))) | 854 (setq icol (- icol fortran-if-indent))) |
847 ((looking-at "\\(else\\|elseif\\)\\b") | 855 ((looking-at "\\(else\\|elseif\\)\\b") |
848 (setq icol (- icol fortran-if-indent))) | 856 (setq icol (- icol fortran-if-indent))) |
857 ((looking-at "case[ \t]*(.*)[ \t]*\n") | |
858 (setq icol (- icol fortran-if-indent))) | |
859 ((looking-at "case[ \t]*default\\b") | |
860 (setq icol (- icol fortran-if-indent))) | |
849 ((looking-at "\\(otherwise\\|else[ \t]*where\\)\\b") | 861 ((looking-at "\\(otherwise\\|else[ \t]*where\\)\\b") |
850 (setq icol (- icol fortran-if-indent))) | 862 (setq icol (- icol fortran-if-indent))) |
851 ((looking-at "end[ \t]*where\\b") | 863 ((looking-at "end[ \t]*where\\b") |
852 (setq icol (- icol fortran-if-indent))) | 864 (setq icol (- icol fortran-if-indent))) |
853 ((and (looking-at "continue\\b") | 865 ((and (looking-at "continue\\b") |
855 (setq icol (- icol fortran-do-indent))) | 867 (setq icol (- icol fortran-do-indent))) |
856 ((looking-at "end[ \t]*do\\b") | 868 ((looking-at "end[ \t]*do\\b") |
857 (setq icol (- icol fortran-do-indent))) | 869 (setq icol (- icol fortran-do-indent))) |
858 ((looking-at | 870 ((looking-at |
859 "end[ \t]*\ | 871 "end[ \t]*\ |
860 \\(structure\\|union\\|map\\)\\b[ \t]*[^ \t=(a-z]") | 872 \\(structure\\|union\\|map\\|interface\\)\\b[ \t]*[^ \t=(a-z]") |
861 (setq icol (- icol fortran-structure-indent))) | 873 (setq icol (- icol fortran-structure-indent))) |
874 ((looking-at | |
875 "end[ \t]*select\\b[ \t]*[^ \t=(a-z]") | |
876 (setq icol (- icol fortran-if-indent))) | |
862 ((and (looking-at "end\\b[ \t]*[^ \t=(a-z]") | 877 ((and (looking-at "end\\b[ \t]*[^ \t=(a-z]") |
863 (not (= icol fortran-minimum-statement-indent))) | 878 (not (= icol fortran-minimum-statement-indent))) |
864 (message "Warning: `end' not in column %d. Probably\ | 879 (message "Warning: `end' not in column %d. Probably\ |
865 an unclosed block." fortran-minimum-statement-indent)))))) | 880 an unclosed block." fortran-minimum-statement-indent)))))) |
866 (max fortran-minimum-statement-indent icol))) | 881 (max fortran-minimum-statement-indent icol))) |
1203 (delete-horizontal-space) | 1218 (delete-horizontal-space) |
1204 (indent-to (fortran-comment-hook)) | 1219 (indent-to (fortran-comment-hook)) |
1205 (insert comment-string))))) | 1220 (insert comment-string))))) |
1206 | 1221 |
1207 (defun fortran-analyze-file-format () | 1222 (defun fortran-analyze-file-format () |
1208 "Returns nil if Fixed format is used, t if TAB formatting is used. | 1223 "Returns nil if fixed format is used, t if TAB formatting is used. |
1209 Use `fortran-tab-mode-default' if no non-comment statements are found in the | 1224 Use `fortran-tab-mode-default' if no non-comment statements are found in the |
1210 file before the end or the first `fortran-analyze-depth' lines." | 1225 file before the end or the first `fortran-analyze-depth' lines." |
1211 (let ((i 0)) | 1226 (let ((i 0)) |
1212 (save-excursion | 1227 (save-excursion |
1213 (goto-char (point-min)) | 1228 (goto-char (point-min)) |