annotate lisp/progmodes/fortran.el @ 1736:c18775a6cf55

New version received.
author Richard M. Stallman <rms@gnu.org>
date Tue, 05 Jan 1993 22:25:05 +0000
parents 65af7bcd5e31
children 04fb1d3d6992
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
1 ;;; fortran.el --- Fortran mode for GNU Emacs
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
2
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
3 ;;; Copyright (c) 1986, 1992 Free Software Foundation, Inc.
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
4
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
5 ;; Author: Michael D. Prange <prange@erl.mit.edu>
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
6 ;; Maintainer: bug-fortran-mode@erl.mit.edu
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
7 ;; Version 1.30 (November 18, 1992)
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
8 ;; Keywords: languages
660
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
9
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
10 ;; This file is part of GNU Emacs.
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
11
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
15 ;; any later version.
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
16
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
20 ;; GNU General Public License for more details.
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
21
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
22 ;; You should have received a copy of the GNU General Public License
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
25
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
26 ;;; Commentary:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
27
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
28 ;; Fortran mode has been upgraded and is now maintained by Stephen A. Wood
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
29 ;; (saw@cebaf.gov). It now will use either fixed format continuation line
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
30 ;; markers (character in 6th column), or tab format coninuation line style
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
31 ;; (digit after a TAB character.) A auto-fill mode has been added to
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
32 ;; automatically wrap fortran lines that get too long.
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
33
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
34 ;; We acknowledge many contributions and valuable suggestions by
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
35 ;; Lawrence R. Dodd, Ralf Fassel, Ralph Finch, Stephen Gildea,
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
36 ;; Dr. Anil Gokhale, Ulrich Mueller, Mark Neale, Eric Prestemon,
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
37 ;; Gary Sabot and Richard Stallman.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
38
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
39 ;;; This file may be used with GNU Emacs version 18.xx if the following
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
40 ;;; variable and function substutions are made.
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
41 ;;; Replace:
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
42 ;;; unread-command-event with unread-command-char
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
43 ;;; frame-width with screen-width
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
44 ;;; auto-fill-function with auto-fill-hook
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 ;;; Bugs to bug-fortran-mode@erl.mit.edu
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
48 (defconst fortran-mode-version "version 1.30")
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
49
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
50 ;;; Code:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
51
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 ;;;###autoload
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 (defvar fortran-tab-mode-default nil
1485
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
54 "*Default tabbing/carriage control style for empty files in Fortran mode.
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
55 A value of t specifies tab-digit style of continuation control.
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
56 A value of nil specifies that continuation lines are marked
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
57 with a character in column 6.")
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
58
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
59 ;; Buffer local, used to display mode line.
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
60 (defvar fortran-tab-mode-string nil
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
61 "String to appear in mode line when TAB-format mode is on.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 (defvar fortran-do-indent 3
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
64 "*Extra indentation applied to DO blocks.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 (defvar fortran-if-indent 3
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
67 "*Extra indentation applied to IF blocks.")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
68
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
69 (defvar fortran-structure-indent 3
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
70 "*Extra indentation applied to STRUCTURE, UNION and MAP blocks.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 (defvar fortran-continuation-indent 5
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
73 "*Extra indentation applied to Fortran continuation lines.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 (defvar fortran-comment-indent-style 'fixed
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 "*nil forces comment lines not to be touched,
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
77 'fixed makes fixed comment indentation to `fortran-comment-line-extra-indent'
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
78 columns beyond `fortran-minimum-statement-indent-fixed' (for
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
79 `indent-tabs-mode' of nil) or `fortran-minimum-statement-indent-tab' (for
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
80 `indent-tabs-mode' of t), and 'relative indents to current
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
81 Fortran indentation plus `fortran-comment-line-extra-indent'.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
83 (defvar fortran-comment-line-extra-indent 0
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
84 "*Amount of extra indentation for text within full-line comments.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 (defvar comment-line-start nil
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 "*Delimiter inserted to start new full-line comment.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 (defvar comment-line-start-skip nil
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 "*Regexp to match the start of a full-line comment.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
92 (defvar fortran-minimum-statement-indent-fixed 6
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
93 "*Minimum statement indentation for fixed format continuation style.")
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
94
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
95 (defvar fortran-minimum-statement-indent-tab (max tab-width 6)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
96 "*Minimum statement indentation for TAB format continuation style.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 ;; Note that this is documented in the v18 manuals as being a string
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 ;; of length one rather than a single character.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 ;; The code in this file accepts either format for compatibility.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 (defvar fortran-comment-indent-char " "
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 "*Single-character string inserted for Fortran comment indentation.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 Normally a space.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 (defvar fortran-line-number-indent 1
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 "*Maximum indentation for Fortran line numbers.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 5 means right-justify them within their five-column field.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 (defvar fortran-check-all-num-for-matching-do nil
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
110 "*Non-nil causes all numbered lines to be treated as possible DO loop ends.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (defvar fortran-blink-matching-if nil
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
113 "*From a Fortran ENDIF statement, blink the matching IF statement.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 (defvar fortran-continuation-string "$"
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
116 "*Single-character string used for Fortran continuation lines.
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 In fixed format continuation style, this character is inserted in
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 column 6 by \\[fortran-split-line] to begin a continuation line.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 Also, if \\[fortran-indent-line] finds this at the beginning of a line, it will
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 convert the line into a continuation line of the appropriate style.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 Normally $.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 (defvar fortran-comment-region "c$$$"
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 "*String inserted by \\[fortran-comment-region]\
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 at start of each line in region.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 (defvar fortran-electric-line-number t
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 "*Non-nil causes line number digits to be moved to the correct column as\
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 typed.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 (defvar fortran-startup-message t
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 "*Non-nil displays a startup message when Fortran mode is first called.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
134 (defvar fortran-column-ruler-fixed
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
135 "0 4 6 10 20 30 40 5\
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
136 0 60 70\n\
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
137 [ ]|{ | | | | | | | | \
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
138 | | | | |}\n"
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
139 "*String displayed above current line by \\[fortran-column-ruler].
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
140 This variable used in fixed-format mode.")
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
141
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
142 (defvar fortran-column-ruler-tab
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
143 "0 810 20 30 40 5\
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
144 0 60 70\n\
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
145 [ ]| { | | | | | | | | \
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
146 | | | | |}\n"
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
147 "*String displayed above current line by \\[fortran-column-ruler].
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
148 This variable used in TAB-format mode.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 (defconst bug-fortran-mode "bug-fortran-mode@erl.mit.edu"
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 "Address of mailing list for Fortran mode bugs.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 (defvar fortran-mode-syntax-table nil
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 "Syntax table in use in Fortran mode buffers.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 (defvar fortran-analyze-depth 100
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
157 "Number of lines to scan to determine whether to use fixed or TAB format\
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 style.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
160 (defvar fortran-break-before-delimiters t
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
161 "*Non-nil causes `fortran-do-auto-fill' to break lines before delimeters.")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
162
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 (if fortran-mode-syntax-table
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 (setq fortran-mode-syntax-table (make-syntax-table))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 (modify-syntax-entry ?\; "w" fortran-mode-syntax-table)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 (modify-syntax-entry ?\r " " fortran-mode-syntax-table)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 (modify-syntax-entry ?+ "." fortran-mode-syntax-table)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 (modify-syntax-entry ?- "." fortran-mode-syntax-table)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 (modify-syntax-entry ?= "." fortran-mode-syntax-table)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 (modify-syntax-entry ?* "." fortran-mode-syntax-table)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 (modify-syntax-entry ?/ "." fortran-mode-syntax-table)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 (modify-syntax-entry ?\' "\"" fortran-mode-syntax-table)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 (modify-syntax-entry ?\" "\"" fortran-mode-syntax-table)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 (modify-syntax-entry ?\\ "/" fortran-mode-syntax-table)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 (modify-syntax-entry ?. "w" fortran-mode-syntax-table)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
177 (modify-syntax-entry ?_ "w" fortran-mode-syntax-table)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 (modify-syntax-entry ?\n ">" fortran-mode-syntax-table))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 (defvar fortran-mode-map ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
181 "Keymap used in Fortran mode.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 (if fortran-mode-map
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 (setq fortran-mode-map (make-sparse-keymap))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 (define-key fortran-mode-map ";" 'fortran-abbrev-start)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (define-key fortran-mode-map "\C-c;" 'fortran-comment-region)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 (define-key fortran-mode-map "\e\C-a" 'beginning-of-fortran-subprogram)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 (define-key fortran-mode-map "\e\C-e" 'end-of-fortran-subprogram)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 (define-key fortran-mode-map "\e;" 'fortran-indent-comment)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 (define-key fortran-mode-map "\e\C-h" 'mark-fortran-subprogram)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 (define-key fortran-mode-map "\e\n" 'fortran-split-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 (define-key fortran-mode-map "\n" 'fortran-reindent-then-newline-and-indent)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 (define-key fortran-mode-map "\e\C-q" 'fortran-indent-subprogram)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 (define-key fortran-mode-map "\C-c\C-w" 'fortran-window-create-momentarily)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 (define-key fortran-mode-map "\C-c\C-r" 'fortran-column-ruler)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 (define-key fortran-mode-map "\C-c\C-p" 'fortran-previous-statement)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 (define-key fortran-mode-map "\C-c\C-n" 'fortran-next-statement)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 (define-key fortran-mode-map "\t" 'fortran-indent-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 (define-key fortran-mode-map "0" 'fortran-electric-line-number)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 (define-key fortran-mode-map "1" 'fortran-electric-line-number)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 (define-key fortran-mode-map "2" 'fortran-electric-line-number)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 (define-key fortran-mode-map "3" 'fortran-electric-line-number)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 (define-key fortran-mode-map "4" 'fortran-electric-line-number)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 (define-key fortran-mode-map "5" 'fortran-electric-line-number)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 (define-key fortran-mode-map "6" 'fortran-electric-line-number)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 (define-key fortran-mode-map "7" 'fortran-electric-line-number)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (define-key fortran-mode-map "8" 'fortran-electric-line-number)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 (define-key fortran-mode-map "9" 'fortran-electric-line-number))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 (defvar fortran-mode-abbrev-table nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 (if fortran-mode-abbrev-table
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 (let ((ac abbrevs-changed))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 (define-abbrev-table 'fortran-mode-abbrev-table ())
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 (define-abbrev fortran-mode-abbrev-table ";au" "automatic" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 (define-abbrev fortran-mode-abbrev-table ";b" "byte" nil)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
217 (define-abbrev fortran-mode-abbrev-table ";bd" "block data" nil)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (define-abbrev fortran-mode-abbrev-table ";ch" "character" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 (define-abbrev fortran-mode-abbrev-table ";cl" "close" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 (define-abbrev fortran-mode-abbrev-table ";c" "continue" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (define-abbrev fortran-mode-abbrev-table ";cm" "common" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 (define-abbrev fortran-mode-abbrev-table ";cx" "complex" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 (define-abbrev fortran-mode-abbrev-table ";df" "define" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (define-abbrev fortran-mode-abbrev-table ";di" "dimension" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 (define-abbrev fortran-mode-abbrev-table ";do" "double" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 (define-abbrev fortran-mode-abbrev-table ";dc" "double complex" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 (define-abbrev fortran-mode-abbrev-table ";dp" "double precision" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (define-abbrev fortran-mode-abbrev-table ";dw" "do while" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 (define-abbrev fortran-mode-abbrev-table ";e" "else" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 (define-abbrev fortran-mode-abbrev-table ";ed" "enddo" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 (define-abbrev fortran-mode-abbrev-table ";el" "elseif" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (define-abbrev fortran-mode-abbrev-table ";en" "endif" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 (define-abbrev fortran-mode-abbrev-table ";eq" "equivalence" nil)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
234 (define-abbrev fortran-mode-abbrev-table ";ew" "endwhere" nil)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 (define-abbrev fortran-mode-abbrev-table ";ex" "external" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 (define-abbrev fortran-mode-abbrev-table ";ey" "entry" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 (define-abbrev fortran-mode-abbrev-table ";f" "format" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 (define-abbrev fortran-mode-abbrev-table ";fa" ".false." nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (define-abbrev fortran-mode-abbrev-table ";fu" "function" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 (define-abbrev fortran-mode-abbrev-table ";g" "goto" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (define-abbrev fortran-mode-abbrev-table ";im" "implicit" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 (define-abbrev fortran-mode-abbrev-table ";ib" "implicit byte" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 (define-abbrev fortran-mode-abbrev-table ";ic" "implicit complex" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 (define-abbrev fortran-mode-abbrev-table ";ich" "implicit character" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 (define-abbrev fortran-mode-abbrev-table ";ii" "implicit integer" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (define-abbrev fortran-mode-abbrev-table ";il" "implicit logical" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 (define-abbrev fortran-mode-abbrev-table ";ir" "implicit real" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 (define-abbrev fortran-mode-abbrev-table ";inc" "include" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 (define-abbrev fortran-mode-abbrev-table ";in" "integer" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 (define-abbrev fortran-mode-abbrev-table ";intr" "intrinsic" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 (define-abbrev fortran-mode-abbrev-table ";l" "logical" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 (define-abbrev fortran-mode-abbrev-table ";n" "namelist" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 (define-abbrev fortran-mode-abbrev-table ";o" "open" nil) ; was ;op
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 (define-abbrev fortran-mode-abbrev-table ";pa" "parameter" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 (define-abbrev fortran-mode-abbrev-table ";pr" "program" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 (define-abbrev fortran-mode-abbrev-table ";ps" "pause" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 (define-abbrev fortran-mode-abbrev-table ";p" "print" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 (define-abbrev fortran-mode-abbrev-table ";rc" "record" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 (define-abbrev fortran-mode-abbrev-table ";re" "real" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 (define-abbrev fortran-mode-abbrev-table ";r" "read" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 (define-abbrev fortran-mode-abbrev-table ";rt" "return" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (define-abbrev fortran-mode-abbrev-table ";rw" "rewind" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 (define-abbrev fortran-mode-abbrev-table ";s" "stop" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 (define-abbrev fortran-mode-abbrev-table ";sa" "save" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 (define-abbrev fortran-mode-abbrev-table ";st" "structure" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 (define-abbrev fortran-mode-abbrev-table ";sc" "static" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 (define-abbrev fortran-mode-abbrev-table ";su" "subroutine" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 (define-abbrev fortran-mode-abbrev-table ";tr" ".true." nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 (define-abbrev fortran-mode-abbrev-table ";ty" "type" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (define-abbrev fortran-mode-abbrev-table ";vo" "volatile" nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 (define-abbrev fortran-mode-abbrev-table ";w" "write" nil)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
272 (define-abbrev fortran-mode-abbrev-table ";wh" "where" nil)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 (setq abbrevs-changed ac)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 ;;;###autoload
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 (defun fortran-mode ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
277 "Major mode for editing Fortran code.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
278 \\[fortran-indent-line] indents the current Fortran line correctly.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
279 DO statements must not share a common CONTINUE.
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
281 Type ;? or ;\\[help-command] to display a list of built-in\
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 abbrevs for Fortran keywords.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 Key definitions:
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 \\{fortran-mode-map}
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 Variables controlling indentation style and extra features:
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 comment-start
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 Normally nil in Fortran mode. If you want to use comments
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 starting with `!', set this to the string \"!\".
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 fortran-do-indent
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 Extra indentation within do blocks. (default 3)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 fortran-if-indent
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 Extra indentation within if blocks. (default 3)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
296 fortran-structure-indent
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
297 Extra indentation within structure, union and map blocks. (default 3)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 fortran-continuation-indent
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
299 Extra indentation applied to continuation statements. (default 5)
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
300 fortran-comment-line-extra-indent
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
301 Amount of extra indentation for text within full-line comments. (default 0)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 fortran-comment-indent-style
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 nil means don't change indentation of text in full-line comments,
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
304 fixed means indent that text at `fortran-comment-line-extra-indent' beyond
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
305 the value of `fortran-minimum-statement-indent-fixed' (for fixed
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
306 format continuation style) or `fortran-minimum-statement-indent-tab'
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
307 (for TAB format continuation style).
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
308 relative means indent at `fortran-comment-line-extra-indent' beyond the
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 indentation for a line of code.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 (default 'fixed)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 fortran-comment-indent-char
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
312 Single-character string to be inserted instead of space for
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 full-line comment indentation. (default \" \")
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
314 fortran-minimum-statement-indent-fixed
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
315 Minimum indentation for Fortran statements in fixed format mode. (def.6)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
316 fortran-minimum-statement-indent-tab
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
317 Minimum indentation for Fortran statements in TAB format mode. (default 9)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 fortran-line-number-indent
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 Maximum indentation for line numbers. A line number will get
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 less than this much indentation if necessary to avoid reaching
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 column 5. (default 1)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 fortran-check-all-num-for-matching-do
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
323 Non-nil causes all numbered lines to be treated as possible \"continue\"
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 statements. (default nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 fortran-blink-matching-if
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
326 From a Fortran ENDIF statement, blink the matching IF statement.
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 (default nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 fortran-continuation-string
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 Single-character string to be inserted in column 5 of a continuation
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 line. (default \"$\")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 fortran-comment-region
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 String inserted by \\[fortran-comment-region] at start of each line in
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 region. (default \"c$$$\")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 fortran-electric-line-number
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 Non-nil causes line number digits to be moved to the correct column
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 as typed. (default t)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
337 fortran-break-before-delimiters
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
338 Non-nil causes `fortran-do-auto-fill' breaks lines before delimeters.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
339 (default t)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 fortran-startup-message
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 Set to nil to inhibit message first time Fortran mode is used.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
343 Turning on Fortran mode calls the value of the variable `fortran-mode-hook'
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 with no args, if that value is non-nil."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 (kill-all-local-variables)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 (if fortran-startup-message
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
348 (message "Emacs Fortran mode %s. Bugs to %s"
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 fortran-mode-version bug-fortran-mode))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 (setq fortran-startup-message nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 (setq local-abbrev-table fortran-mode-abbrev-table)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 (set-syntax-table fortran-mode-syntax-table)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
353 (make-local-variable 'fortran-break-before-delimiters)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
354 (setq fortran-break-before-delimiters t)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 (make-local-variable 'indent-line-function)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 (setq indent-line-function 'fortran-indent-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 (make-local-variable 'comment-indent-hook)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 (setq comment-indent-hook 'fortran-comment-hook)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 (make-local-variable 'comment-line-start-skip)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 (setq comment-line-start-skip
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
361 "^[Cc*]\\(\\([^ \t\n]\\)\\2\\2*\\)?[ \t]*\\|^#.*")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 (make-local-variable 'comment-line-start)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 (setq comment-line-start "c")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 (make-local-variable 'comment-start-skip)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 (setq comment-start-skip "![ \t]*")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 (make-local-variable 'comment-start)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 (setq comment-start nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 (make-local-variable 'require-final-newline)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 (setq require-final-newline t)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 (make-local-variable 'abbrev-all-caps)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 (setq abbrev-all-caps t)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 (make-local-variable 'indent-tabs-mode)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 (setq indent-tabs-mode nil)
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
374 ;;;(setq abbrev-mode t) ; ?? (abbrev-mode 1) instead??
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
375 (setq fill-column 72) ; Already local?
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 (use-local-map fortran-mode-map)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 (setq mode-name "Fortran")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 (setq major-mode 'fortran-mode)
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
379 ;;;(make-local-variable 'fortran-tab-mode)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
380 (make-local-variable 'fortran-comment-line-extra-indent)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
381 (make-local-variable 'fortran-minimum-statement-indent-fixed)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
382 (make-local-variable 'fortran-minimum-statement-indent-tab)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
383 (make-local-variable 'fortran-column-ruler-fixed)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
384 (make-local-variable 'fortran-column-ruler-tab)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 (make-local-variable 'fortran-tab-mode-string)
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
386 (setq fortran-tab-mode-string " TAB-format")
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
387 (setq indent-tabs-mode (fortran-analyze-file-format))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 (run-hooks 'fortran-mode-hook))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 (defun fortran-comment-hook ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 (skip-chars-backward " \t")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 (max (+ 1 (current-column))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 comment-column)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 (defun fortran-indent-comment ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 "Align or create comment on current line.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 Existing comments of all types are recognized and aligned.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 If the line has no comment, a side-by-side comment is inserted and aligned
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 if the value of comment-start is not nil.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 Otherwise, a separate-line comment is inserted, on this line
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 or on a new line inserted before this line if this line is not blank."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 ;; Recognize existing comments of either kind.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 (cond ((looking-at comment-line-start-skip)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 (fortran-indent-line))
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
408 ((fortran-find-comment-start-skip) ; catches any inline comment and
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
409 ; leaves point after comment-start-skip
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
410 (if comment-start-skip
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
411 (progn (goto-char (match-beginning 0))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
412 (if (not (= (current-column) (fortran-comment-hook)))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
413 (progn (delete-horizontal-space)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
414 (indent-to (fortran-comment-hook)))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
415 (end-of-line))) ; otherwise goto end of line or sth else?
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 ;; No existing comment.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 ;; If side-by-side comments are defined, insert one,
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 ;; unless line is now blank.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 ((and comment-start (not (looking-at "^[ \t]*$")))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 (end-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 (delete-horizontal-space)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 (indent-to (fortran-comment-hook))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 (insert comment-start))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 ;; Else insert separate-line comment, making a new line if nec.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 (t
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 (if (looking-at "^[ \t]*$")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 (delete-horizontal-space)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 (insert "\n")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 (forward-char -1))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 (insert comment-line-start)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 (insert-char (if (stringp fortran-comment-indent-char)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 (aref fortran-comment-indent-char 0)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
434 fortran-comment-indent-char)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 (- (calculate-fortran-indent) (current-column))))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 (defun fortran-comment-region (beg-region end-region arg)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 "Comments every line in the region.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 Puts fortran-comment-region at the beginning of every line in the region.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 BEG-REGION and END-REGION are args which specify the region boundaries.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 With non-nil ARG, uncomments the region."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 (interactive "*r\nP")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 (let ((end-region-mark (make-marker)) (save-point (point-marker)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 (set-marker end-region-mark end-region)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 (goto-char beg-region)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 (if (not arg) ;comment the region
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 (progn (insert fortran-comment-region)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 (while (and (= (forward-line 1) 0)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 (< (point) end-region-mark))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 (insert fortran-comment-region)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 (let ((com (regexp-quote fortran-comment-region))) ;uncomment the region
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 (if (looking-at com)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 (delete-region (point) (match-end 0)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 (while (and (= (forward-line 1) 0)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 (< (point) end-region-mark))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 (if (looking-at com)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 (delete-region (point) (match-end 0))))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 (goto-char save-point)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 (set-marker end-region-mark nil)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 (set-marker save-point nil)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 (defun fortran-abbrev-start ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
464 "Typing ;\\[help-command] or ;? lists all the Fortran abbrevs.
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 Any other key combination is executed normally."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 (let (c)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 (insert last-command-char)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 (if (or (= (setq c (read-char)) ??) ;insert char if not equal to `?'
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 (= c help-char))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 (fortran-abbrev-help)
1611
2701f8d53d25 * bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents: 1548
diff changeset
472 (setq unread-command-event c))))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 (defun fortran-abbrev-help ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 "List the currently defined abbrevs in Fortran mode."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 (message "Listing abbrev table...")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478 (require 'abbrevlist)
1485
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
479 (display-buffer (fortran-prepare-abbrev-list-buffer))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 (message "Listing abbrev table...done"))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481
1485
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
482 (defun fortran-prepare-abbrev-list-buffer ()
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
483 (save-excursion
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
484 (set-buffer (get-buffer-create "*Abbrevs*"))
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
485 (erase-buffer)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
486 (insert-abbrev-table-description fortran-mode-abbrev-table t)
1485
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
487 (goto-char (point-min))
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
488 (set-buffer-modified-p nil)
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
489 (edit-abbrevs-mode))
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
490 (get-buffer-create "*Abbrevs*"))
a6da00e1c5ad (fortran-tab-mode): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 1475
diff changeset
491
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 (defun fortran-column-ruler ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 "Inserts a column ruler momentarily above current line, till next keystroke.
1475
2596132752ff Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 845
diff changeset
494 The ruler is defined by the value of `fortran-column-ruler'.
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 The key typed is executed unless it is SPC."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 (momentary-string-display
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
498 (if indent-tabs-mode
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
499 fortran-column-ruler-tab
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
500 fortran-column-ruler-fixed)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
501 (save-excursion
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
502 (beginning-of-line)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
503 (if (eq (window-start (selected-window))
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
504 (window-point (selected-window)))
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
505 (progn (forward-line) (point))
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
506 (point)))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 nil "Type SPC or any command to erase ruler."))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 (defun fortran-window-create ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 "Makes the window 72 columns wide.
1475
2596132752ff Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 845
diff changeset
511 See also `fortran-window-create-momentarily'."
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 (condition-case error
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 (progn
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 (let ((window-min-width 2))
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
516 (if (< (window-width) (frame-width))
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
517 (enlarge-window-horizontally (- (frame-width)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 (window-width) 1)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 (split-window-horizontally 73)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 (other-window 1)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 (switch-to-buffer " fortran-window-extra" t)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 (select-window (previous-window))))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
523 (error (message "No room for Fortran window.")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 'error)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 (defun fortran-window-create-momentarily (&optional arg)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 "Momentarily makes the window 72 columns wide.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 Optional ARG non-nil and non-unity disables the momentary feature.
1475
2596132752ff Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 845
diff changeset
529 See also `fortran-window-create'."
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 (interactive "p")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 (if (or (not arg)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 (= arg 1))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 (save-window-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 (if (not (equal (fortran-window-create) 'error))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 (progn (message "Type SPC to continue editing.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 (let ((char (read-char)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 (or (equal char (string-to-char " "))
1611
2701f8d53d25 * bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents: 1548
diff changeset
538 (setq unread-command-event char))))))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 (fortran-window-create)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 (defun fortran-split-line ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 "Break line at point and insert continuation marker and alignment."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 (delete-horizontal-space)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 (if (save-excursion (beginning-of-line) (looking-at comment-line-start-skip))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 (insert "\n" comment-line-start " ")
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
547 (if indent-tabs-mode
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 (progn
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 (insert "\n\t")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550 (insert-char (fortran-numerical-continuation-char) 1))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
551 (insert "\n " fortran-continuation-string)));Space after \n important
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
552 (fortran-indent-line)) ;when the cont string is C, c or *.
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 (defun fortran-numerical-continuation-char ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 "Return a digit for tab-digit style of continution lines.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 If, previous line is a tab-digit continuation line, returns that digit
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 plus one. Otherwise return 1. Zero not allowed."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559 (forward-line -1)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560 (if (looking-at "\t[1-9]")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 (+ ?1 (% (- (char-after (+ (point) 1)) ?0) 9))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 ?1)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 (defun delete-horizontal-regexp (chars)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 "Delete all characters in CHARS around point.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 CHARS is like the inside of a [...] in a regular expression
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 except that ] is never special and \ quotes ^, - or \."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 (interactive "*s")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 (skip-chars-backward chars)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 (delete-region (point) (progn (skip-chars-forward chars) (point))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 (defun fortran-electric-line-number (arg)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 "Self insert, but if part of a Fortran line number indent it automatically.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 Auto-indent does not happen if a numeric arg is used."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 (interactive "P")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 (if (or arg (not fortran-electric-line-number))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 (if arg
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
578 (self-insert-command (prefix-numeric-value arg))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 (self-insert-command 1))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 (if (or (and (= 5 (current-column))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 (looking-at " ")));In col 5 with only spaces to left.
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
584 (and (= (if indent-tabs-mode
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
585 fortran-minimum-statement-indent-tab
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
586 fortran-minimum-statement-indent-fixed) (current-column))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 (looking-at "\t"));In col 8 with a single tab to the left.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 (not (or (eq last-command 'fortran-indent-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 (eq last-command
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 'fortran-reindent-then-newline-and-indent))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 (re-search-backward "[^ \t0-9]"
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 (point))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598 t)) ;not a line number
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599 (looking-at "[0-9]") ;within a line number
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600 )
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
601 (self-insert-command (prefix-numeric-value arg))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
602 (skip-chars-backward " \t")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
603 (insert last-command-char)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
604 (fortran-indent-line))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
605
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 (defun beginning-of-fortran-subprogram ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
607 "Moves point to the beginning of the current Fortran subprogram."
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
608 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609 (let ((case-fold-search t))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 (beginning-of-line -1)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
611 (re-search-backward "^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]" nil 'move)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
612 (if (looking-at "^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
613 (forward-line 1))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
614
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
615 (defun end-of-fortran-subprogram ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
616 "Moves point to the end of the current Fortran subprogram."
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
617 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
618 (let ((case-fold-search t))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
619 (beginning-of-line 2)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
620 (re-search-forward "^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]" nil 'move)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
621 (goto-char (match-beginning 0))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
622 (forward-line 1)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
623
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
624 (defun mark-fortran-subprogram ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
625 "Put mark at end of Fortran subprogram, point at beginning.
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
626 The marks are pushed."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
627 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
628 (end-of-fortran-subprogram)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
629 (push-mark (point))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
630 (beginning-of-fortran-subprogram))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
631
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
632 (defun fortran-previous-statement ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
633 "Moves point to beginning of the previous Fortran statement.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
634 Returns `first-statement' if that statement is the first
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
635 non-comment Fortran statement in the file, and nil otherwise."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
636 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
637 (let (not-first-statement continue-test)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
638 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
639 (setq continue-test
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
640 (and
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
641 (not (looking-at comment-line-start-skip))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
642 (or (looking-at
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
643 (concat "[ \t]*" (regexp-quote fortran-continuation-string)))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
644 (or (looking-at " [^ 0\n]")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
645 (looking-at "\t[1-9]")))))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
646 (while (and (setq not-first-statement (= (forward-line -1) 0))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
647 (or (looking-at comment-line-start-skip)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
648 (looking-at "[ \t]*$")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
649 (looking-at " [^ 0\n]")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
650 (looking-at "\t[1-9]")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
651 (looking-at (concat "[ \t]*" comment-start-skip)))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
652 (cond ((and continue-test
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
653 (not not-first-statement))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
654 (message "Incomplete continuation statement."))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
655 (continue-test
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
656 (fortran-previous-statement))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
657 ((not not-first-statement)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
658 'first-statement))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
659
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
660 (defun fortran-next-statement ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
661 "Moves point to beginning of the next Fortran statement.
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
662 Returns `last-statement' if that statement is the last
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
663 non-comment Fortran statement in the file, and nil otherwise."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
664 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
665 (let (not-last-statement)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
666 (beginning-of-line)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
667 (while (and (setq not-last-statement
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
668 (and (= (forward-line 1) 0)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
669 (not (eobp))))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
670 (or (looking-at comment-line-start-skip)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
671 (looking-at "[ \t]*$")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
672 (looking-at " [^ 0\n]")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
673 (looking-at "\t[1-9]")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
674 (looking-at (concat "[ \t]*" comment-start-skip)))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
675 (if (not not-last-statement)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
676 'last-statement)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
677
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
678 (defun fortran-blink-matching-if ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
679 "From a Fortran ENDIF statement, blink the matching IF statement."
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
680 (let ((count 1) (top-of-window (window-start)) matching-if
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
681 (endif-point (point)) message)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
682 (if (save-excursion (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
683 (skip-chars-forward " \t0-9")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
684 (looking-at "end[ \t]*if\\b"))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
685 (progn
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
686 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
687 (while (and (not (= count 0))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
688 (not (eq (fortran-previous-statement)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
689 'first-statement))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
690 (not (looking-at
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
691 "^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]")))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
692 ; Keep local to subprogram
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
693 (skip-chars-forward " \t0-9")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
694 (cond ((looking-at "if[ \t]*(")
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
695 (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
696 (if (or
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
697 (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
698 (let (then-test);multi-line if-then
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
699 (while
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
700 (and (= (forward-line 1) 0)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
701 ;search forward for then
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
702 (or (looking-at " [^ 0\n]")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
703 (looking-at "\t[1-9]"))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
704 (not
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
705 (setq
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
706 then-test
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
707 (looking-at
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
708 ".*then\\b[ \t]*[^ \t(=a-z0-9]")))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
709 then-test))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
710 (setq count (- count 1)))))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
711 ((looking-at "end[ \t]*if\\b")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
712 (setq count (+ count 1)))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
713 (if (not (= count 0))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
714 (setq message "No matching if.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
715 (if (< (point) top-of-window)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
716 (setq message (concat "Matches " (buffer-substring
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
717 (progn (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
718 (point))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
719 (progn (end-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
720 (point)))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
721 (setq matching-if (point)))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
722 (if message
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
723 (message "%s" message)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
724 (goto-char matching-if)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
725 (sit-for 1)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
726 (goto-char endif-point))))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
727
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
728 (defun fortran-indent-line ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
729 "Indents current Fortran line based on its contents and on previous lines."
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
730 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
731 (let ((cfi (calculate-fortran-indent)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
732 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
733 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
734 (if (or (not (= cfi (fortran-current-line-indentation)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
735 (and (re-search-forward "^[ \t]*[0-9]+" (+ (point) 4) t)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
736 (not (fortran-line-number-indented-correctly-p))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
737 (fortran-indent-to-column cfi)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
738 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
739 (if (and (not (looking-at comment-line-start-skip))
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
740 (fortran-find-comment-start-skip))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
741 (fortran-indent-comment))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
742 ;; Never leave point in left margin.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
743 (if (< (current-column) cfi)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
744 (move-to-column cfi))
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
745 (if (and auto-fill-function
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
746 (> (save-excursion (end-of-line) (current-column)) fill-column))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
747 (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
748 (end-of-line)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
749 (fortran-do-auto-fill)))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
750 (if fortran-blink-matching-if
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
751 (fortran-blink-matching-if))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
752
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
753 (defun fortran-reindent-then-newline-and-indent ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
754 "Reindent the current Fortran line, insert a newline and indent the newline.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
755 An abbrev before point is expanded if `abbrev-mode' is non-nil."
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
756 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
757 (if abbrev-mode (expand-abbrev))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
758 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
759 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
760 (skip-chars-forward " \t")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
761 (if (or (looking-at "[0-9]") ;Reindent only where it is most
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
762 (looking-at "end") ;likely to be necessary
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
763 (looking-at "else")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
764 (looking-at (regexp-quote fortran-continuation-string)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
765 (fortran-indent-line)))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
766 (newline)
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
767 (fortran-indent-line))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
768
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
769 (defun fortran-indent-subprogram ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
770 "Properly indents the Fortran subprogram which contains point."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
771 (interactive)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
772 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
773 (mark-fortran-subprogram)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
774 (message "Indenting subprogram...")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
775 (indent-region (point) (mark) nil))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
776 (message "Indenting subprogram...done."))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
777
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
778 (defun calculate-fortran-indent ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
779 "Calculates the Fortran indent column based on previous lines."
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
780 (let (icol first-statement (case-fold-search t)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
781 (fortran-minimum-statement-indent
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
782 (if indent-tabs-mode
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
783 fortran-minimum-statement-indent-tab
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
784 fortran-minimum-statement-indent-fixed)))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
785 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
786 (setq first-statement (fortran-previous-statement))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
787 (if first-statement
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
788 (setq icol fortran-minimum-statement-indent)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
789 (progn
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
790 (if (= (point) (point-min))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
791 (setq icol fortran-minimum-statement-indent)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
792 (setq icol (fortran-current-line-indentation)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
793 (skip-chars-forward " \t0-9")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
794 (cond ((looking-at "if[ \t]*(")
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
795 (if (or (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t_$(=a-z0-9]")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
796 (let (then-test) ;multi-line if-then
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
797 (while (and (= (forward-line 1) 0)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
798 ;;search forward for then
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
799 (or (looking-at " [^ 0\n]")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
800 (looking-at "\t[1-9]"))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
801 (not (setq then-test (looking-at
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
802 ".*then\\b[ \t]\
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
803 *[^ \t_$(=a-z0-9]")))))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
804 then-test))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
805 (setq icol (+ icol fortran-if-indent))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
806 ((looking-at "\\(else\\|elseif\\)\\b")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
807 (setq icol (+ icol fortran-if-indent)))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
808 ((looking-at "\\(otherwise\\|else[ \t]*where\\)\\b")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
809 (setq icol (+ icol fortran-if-indent)))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
810 ((looking-at "where.*(.*)[ \t]*\n")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
811 (setq icol (+ icol fortran-if-indent)))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
812 ((looking-at "do\\b")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
813 (setq icol (+ icol fortran-do-indent)))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
814 ((looking-at
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
815 "\\(structure\\|union\\|map\\)\\b[ \t]*[^ \t=(a-z]")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
816 (setq icol (+ icol fortran-structure-indent)))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
817 ((looking-at "end\\b[ \t]*[^ \t=(a-z]")
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
818 ;; Previous END resets indent to minimum
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
819 (setq icol fortran-minimum-statement-indent))))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
820 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
821 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
822 (cond ((looking-at "[ \t]*$"))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
823 ((looking-at comment-line-start-skip)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
824 (cond ((eq fortran-comment-indent-style 'relative)
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
825 (setq icol (+ icol fortran-comment-line-extra-indent)))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
826 ((eq fortran-comment-indent-style 'fixed)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
827 (setq icol (+ fortran-minimum-statement-indent
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
828 fortran-comment-line-extra-indent))))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
829 (setq fortran-minimum-statement-indent 0))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
830 ((or (looking-at (concat "[ \t]*"
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
831 (regexp-quote
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
832 fortran-continuation-string)))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
833 (looking-at " [^ 0\n]")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
834 (looking-at "\t[1-9]"))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
835 (setq icol (+ icol fortran-continuation-indent)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
836 (first-statement)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
837 ((and fortran-check-all-num-for-matching-do
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
838 (looking-at "[ \t]*[0-9]+")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
839 (fortran-check-for-matching-do))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
840 (setq icol (- icol fortran-do-indent)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
841 (t
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
842 (skip-chars-forward " \t0-9")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
843 (cond ((looking-at "end[ \t]*if\\b")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
844 (setq icol (- icol fortran-if-indent)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
845 ((looking-at "\\(else\\|elseif\\)\\b")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
846 (setq icol (- icol fortran-if-indent)))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
847 ((looking-at "\\(otherwise\\|else[ \t]*where\\)\\b")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
848 (setq icol (- icol fortran-if-indent)))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
849 ((looking-at "end[ \t]*where\\b")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
850 (setq icol (- icol fortran-if-indent)))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
851 ((and (looking-at "continue\\b")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
852 (fortran-check-for-matching-do))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
853 (setq icol (- icol fortran-do-indent)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
854 ((looking-at "end[ \t]*do\\b")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
855 (setq icol (- icol fortran-do-indent)))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
856 ((looking-at
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
857 "end[ \t]*\
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
858 \\(structure\\|union\\|map\\)\\b[ \t]*[^ \t=(a-z]")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
859 (setq icol (- icol fortran-structure-indent)))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
860 ((and (looking-at "end\\b[ \t]*[^ \t=(a-z]")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
861 (not (= icol fortran-minimum-statement-indent)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
862 (message "Warning: `end' not in column %d. Probably\
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
863 an unclosed block." fortran-minimum-statement-indent))))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
864 (max fortran-minimum-statement-indent icol)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
865
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
866 (defun fortran-current-line-indentation ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
867 "Indentation of current line, ignoring Fortran line number or continuation.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
868 This is the column position of the first non-whitespace character
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
869 aside from the line number and/or column 5/8 line-continuation character.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
870 For comment lines, returns indentation of the first
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
871 non-indentation text within the comment."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
872 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
873 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
874 (cond ((looking-at comment-line-start-skip)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
875 (goto-char (match-end 0))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
876 (skip-chars-forward
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
877 (if (stringp fortran-comment-indent-char)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
878 fortran-comment-indent-char
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
879 (char-to-string fortran-comment-indent-char))))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
880 ((or (looking-at " [^ 0\n]")
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
881 (looking-at "\t[1-9]"))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
882 (goto-char (match-end 0)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
883 (t
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
884 ;; Move past line number.
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
885 (skip-chars-forward "[ \t0-9]");From Uli
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
886 ))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
887 ;; Move past whitespace.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
888 (skip-chars-forward " \t")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
889 (current-column)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
890
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
891 (defun fortran-indent-to-column (col)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
892 "Indents current line with spaces to column COL.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
893 notes: 1) A non-zero/non-blank character in column 5 indicates a continuation
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
894 line, and this continuation character is retained on indentation;
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
895 2) If `fortran-continuation-string' is the first non-whitespace
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
896 character, this is a continuation line;
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
897 3) A non-continuation line which has a number as the first
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
898 non-whitespace character is a numbered line.
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
899 4) A TAB followed by a digit indicates a continuation line."
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
900 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
901 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
902 (if (looking-at comment-line-start-skip)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
903 (if fortran-comment-indent-style
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
904 (let ((char (if (stringp fortran-comment-indent-char)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
905 (aref fortran-comment-indent-char 0)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
906 fortran-comment-indent-char)))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
907 (goto-char (match-end 0))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
908 (delete-horizontal-regexp (concat " \t" (char-to-string char)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
909 (insert-char char (- col (current-column)))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
910 (if (looking-at "\t[1-9]")
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
911 (if indent-tabs-mode
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
912 (goto-char (match-end 0))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
913 (delete-char 2)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
914 (insert " ")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
915 (insert fortran-continuation-string))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
916 (if (looking-at " [^ 0\n]")
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
917 (if indent-tabs-mode
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
918 (progn (delete-char 6)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
919 (insert "\t")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
920 (insert-char (fortran-numerical-continuation-char) 1))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
921 (forward-char 6))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
922 (delete-horizontal-space)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
923 ;; Put line number in columns 0-4
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
924 ;; or put continuation character in column 5.
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
925 (cond ((eobp))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
926 ((looking-at (regexp-quote fortran-continuation-string))
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
927 (if indent-tabs-mode
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
928 (progn
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
929 (indent-to
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
930 (if indent-tabs-mode
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
931 fortran-minimum-statement-indent-tab
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
932 fortran-minimum-statement-indent-fixed))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
933 (delete-char 1)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
934 (insert-char (fortran-numerical-continuation-char) 1))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
935 (indent-to 5)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
936 (forward-char 1)))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
937 ((looking-at "[0-9]+")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
938 (let ((extra-space (- 5 (- (match-end 0) (point)))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
939 (if (< extra-space 0)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
940 (message "Warning: line number exceeds 5-digit limit.")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
941 (indent-to (min fortran-line-number-indent extra-space))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
942 (skip-chars-forward "0-9")))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
943 ;; Point is now after any continuation character or line number.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
944 ;; Put body of statement where specified.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
945 (delete-horizontal-space)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
946 (indent-to col)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
947 ;; Indent any comment following code on the same line.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
948 (if (and comment-start-skip
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
949 (fortran-find-comment-start-skip))
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
950 (progn (goto-char (match-beginning 0))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
951 (if (not (= (current-column) (fortran-comment-hook)))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
952 (progn (delete-horizontal-space)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
953 (indent-to (fortran-comment-hook)))))))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
954
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
955 (defun fortran-line-number-indented-correctly-p ()
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
956 "Return t if current line's line number is correctly indented.
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
957 Do not call if there is no line number."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
958 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
959 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
960 (skip-chars-forward " \t")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
961 (and (<= (current-column) fortran-line-number-indent)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
962 (or (= (current-column) fortran-line-number-indent)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
963 (progn (skip-chars-forward "0-9")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
964 (= (current-column) 5))))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
965
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
966 (defun fortran-check-for-matching-do ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
967 "When called from a numbered statement, returns t if matching DO is found.
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
968 Otherwise return a nil."
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
969 (let (charnum
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
970 (case-fold-search t))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
971 (save-excursion
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
972 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
973 (if (looking-at "[ \t]*[0-9]+")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
974 (progn
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
975 (skip-chars-forward " \t")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
976 (skip-chars-forward "0") ;skip past leading zeros
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
977 (setq charnum (buffer-substring (point)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
978 (progn (skip-chars-forward "0-9")
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
979 (point))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
980 (beginning-of-line)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
981 (and (re-search-backward
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
982 (concat
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
983 "\\(^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]\\)\\|\\(^[ \t0-9]*do\
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
984 [ \t]*0*"
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
985 charnum "\\b\\)\\|\\(^[ \t]*0*" charnum "\\b\\)")
332
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
986 nil t)
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
987 (looking-at (concat "^[ \t0-9]*do[ \t]*0*" charnum))))))))
3cb8418b827a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
988
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
989 (defun fortran-find-comment-start-skip ()
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
990 "Move to past `comment-start-skip' found on current line.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
991 Return t if `comment-start-skip' found, nil if not."
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
992 ;;; In order to move point only if comment-start-skip is found,
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
993 ;;; this one uses a lot of save-excursions. Note that re-search-forward
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
994 ;;; moves point even if comment-start-skip is inside a string-constant.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
995 ;;; Some code expects certain values for match-beginning and end
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
996 (interactive)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
997 (let ((save-match-beginning) (save-match-end))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
998 (if (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
999 (re-search-forward comment-start-skip
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1000 (save-excursion (end-of-line) (point)) t))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1001 (progn
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1002 (setq save-match-beginning (match-beginning 0))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1003 (setq save-match-end (match-end 0))
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1004 (if (fortran-is-in-string-p (match-beginning 0))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1005 (progn
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1006 (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1007 (goto-char save-match-end)
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1008 (fortran-find-comment-start-skip)) ; recurse for rest of line
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1009 )
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1010 (goto-char save-match-beginning)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1011 (re-search-forward comment-start-skip
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1012 (save-excursion (end-of-line) (point)) t)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1013 (goto-char (match-end 0))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1014 t))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1015 nil)))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1016
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1017 (defun fortran-is-in-string-p (pos)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1018 "Return t if POS (a buffer position) is inside a standard Fortran string.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1019 Fortran strings are delimeted by apostrophes (\'). Quote-Escape-sequences
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1020 (\\'), strings delimited by \" and detection of syntax-errors
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1021 (unbalanced quotes) are NOT supported."
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1022 ;;; The algorithm is simple: start at point with value nil
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1023 ;;; and toggle value at each quote found until end of line.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1024 ;;; The quote skip is hard-coded, maybe it's possible to change this
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1025 ;;; and use something like 'string-constant-delimiter' (which
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1026 ;;; doesn't exist yet) so this function can be used by other modes,
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1027 ;;; but then one must pay attention to escape sequences, multi-line-constants
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1028 ;;; and such things.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1029 (let ((is-in-fortran-string nil))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1030 (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1031 (goto-char pos)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1032 (fortran-previous-statement)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1033 (fortran-next-statement)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1034 (while (< (point) pos)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1035 ;; Make sure we don't count quotes in continuation column.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1036 (if (looking-at "^ ")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1037 (goto-char (+ 1 (match-end 0)))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1038 (if (and (not is-in-fortran-string)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1039 (looking-at comment-start-skip))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1040 (beginning-of-line 2)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1041 (if (looking-at "'")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1042 (setq is-in-fortran-string (not is-in-fortran-string)))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1043 (forward-char 1)))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1044 is-in-fortran-string))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1045
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1046 (defun fortran-auto-fill-mode (arg)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1047 "Toggle fortran-auto-fill mode.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1048 With ARG, turn `fortran-auto-fill' mode on iff ARG is positive.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1049 In `fortran-auto-fill' mode, inserting a space at a column beyond `fill-column'
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1050 automatically breaks the line at a previous space."
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1051 (interactive "P")
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1052 (prog1 (setq auto-fill-function
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1053 (if (if (null arg)
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1054 (not auto-fill-function)
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1055 (> (prefix-numeric-value arg) 0))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1056 'fortran-indent-line
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1057 nil))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1058 ;; update mode-line
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1059 (set-buffer-modified-p (buffer-modified-p))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1060
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1061 (defun fortran-do-auto-fill ()
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1062 (interactive)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1063 (let* ((opoint (point))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1064 (bol (save-excursion (beginning-of-line) (point)))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1065 (eol (save-excursion (end-of-line) (point)))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1066 (bos (min eol (+ bol (fortran-current-line-indentation))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1067 (quote
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1068 (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1069 (goto-char bol)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1070 (if (looking-at comment-line-start-skip)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1071 nil ; OK to break quotes on comment lines.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1072 (move-to-column fill-column)
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1073 (cond ((fortran-is-in-string-p (point))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1074 (save-excursion (re-search-backward "[^']'[^']" bol t)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1075 (if fortran-break-before-delimiters
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1076 (point)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1077 (1+ (point)))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1078 (t nil)))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1079 ;;
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1080 ;; decide where to split the line. If a position for a quoted
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1081 ;; string was found above then use that, else break the line
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1082 ;; before the last delimiter.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1083 ;; Delimeters are whitespace, commas, and operators.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1084 ;; Will break before a pair of *'s.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1085 ;;
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1086 (fill-point
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1087 (or quote
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1088 (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1089 (move-to-column (1+ fill-column))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1090 (skip-chars-backward "^ \t\n,'+-/*=)"
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1091 ;;; (if fortran-break-before-delimiters
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1092 ;;; "^ \t\n,'+-/*=" "^ \t\n,'+-/*=)")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1093 )
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1094 (if (<= (point) (1+ bos))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1095 (progn
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1096 (move-to-column (1+ fill-column))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1097 (if (not (re-search-forward "[\t\n,'+-/*)=]" eol t))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1098 (goto-char bol))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1099 (if (bolp)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1100 (re-search-forward "[ \t]" opoint t)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1101 (forward-char -1)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1102 (if (looking-at "'")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1103 (forward-char 1)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1104 (skip-chars-backward " \t\*")))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1105 (if fortran-break-before-delimiters
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1106 (point)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1107 (1+ (point))))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1108 )
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1109 ;; if we are in an in-line comment, don't break unless the
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1110 ;; line of code is longer than it should be. Otherwise
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1111 ;; break the line at the column computed above.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1112 ;;
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1113 ;; Need to use fortran-find-comment-start-skip to make sure that quoted !'s
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1114 ;; don't prevent a break.
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1115 (if (not (or (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1116 (if (and (re-search-backward comment-start-skip bol t)
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1117 (not (fortran-is-in-string-p (point))))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1118 (progn
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1119 (skip-chars-backward " \t")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1120 (< (current-column) (1+ fill-column)))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1121 (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1122 (goto-char fill-point)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1123 (bolp))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1124 (if (> (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1125 (goto-char fill-point) (current-column))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1126 (1+ fill-column))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1127 (progn (goto-char fill-point)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1128 (fortran-break-line))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1129 (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1130 (if (> (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1131 (goto-char fill-point)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1132 (current-column))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1133 (+ (calculate-fortran-indent) fortran-continuation-indent))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1134 (progn
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1135 (goto-char fill-point)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1136 (fortran-break-line))))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1137 ))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1138 (defun fortran-break-line ()
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1139 (let ((opoint (point))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1140 (bol (save-excursion (beginning-of-line) (point)))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1141 (eol (save-excursion (end-of-line) (point)))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1142 (comment-string nil))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1143
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1144 (save-excursion
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1145 (if (and comment-start-skip (fortran-find-comment-start-skip))
1548
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1146 (progn
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1147 (re-search-backward comment-start-skip bol t)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1148 (setq comment-string (buffer-substring (point) eol))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1149 (delete-region (point) eol))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1150 ;;; Forward line 1 really needs to go to next non white line
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1151 (if (save-excursion (forward-line 1)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1152 (or (looking-at " [^ 0\n]")
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1153 (looking-at "\t[1-9]")))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1154 (progn
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1155 (forward-line 1)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1156 (delete-indentation)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1157 (delete-char 2)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1158 (delete-horizontal-space)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1159 (fortran-do-auto-fill))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1160 (fortran-split-line))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1161 (if comment-string
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1162 (save-excursion
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1163 (goto-char bol)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1164 (end-of-line)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1165 (delete-horizontal-space)
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1166 (indent-to (fortran-comment-hook))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1167 (insert comment-string)))))
cbed5e520f81 version 1.28.8
Richard M. Stallman <rms@gnu.org>
parents: 1488
diff changeset
1168
1633
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1169 (defun fortran-analyze-file-format ()
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1170 "Returns nil if Fixed format is used, t if TAB formatting is used.
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1171 Use `fortran-tab-mode-default' if no non-comment statements are found in the
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1172 file before the end or the first `fortran-analyze-depth' lines."
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1173 (let ((i 0))
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1174 (save-excursion
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1175 (goto-char (point-min))
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1176 (setq i 0)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1177 (while (not (or
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1178 (eobp)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1179 (looking-at "\t")
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1180 (looking-at " ")
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1181 (> i fortran-analyze-depth)))
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1182 (forward-line)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1183 (setq i (1+ i)))
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1184 (cond
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1185 ((looking-at "\t") t)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1186 ((looking-at " ") nil)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1187 (fortran-tab-mode-default t)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1188 (t nil)))))
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1189
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1190 (or (assq 'fortran-tab-mode-string minor-mode-alist)
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1191 (setq minor-mode-alist (cons
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1192 '(fortran-tab-mode-string
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1193 (indent-tabs-mode fortran-tab-mode-string))
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1194 minor-mode-alist)))
65af7bcd5e31 * fortran.el: New version of version 1.30 (!) from Stephen A. Wood
Jim Blandy <jimb@redhat.com>
parents: 1611
diff changeset
1195
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 332
diff changeset
1196 (provide 'fortran)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 332
diff changeset
1197
660
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
1198 ;;; fortran.el ends here