0
|
1 ;;; fortran.el --- Fortran mode for GNU Emacs
|
|
2
|
2
|
3 ;; Copyright (c) 1986, 1993, 1994, 1995 Free Software Foundation, Inc.
|
0
|
4
|
|
5 ;; Author: Michael D. Prange <prange@erl.mit.edu>
|
|
6 ;; Maintainer: bug-fortran-mode@erl.mit.edu
|
|
7 ;; Version 1.30.6 (July 27, 1995)
|
|
8 ;; Keywords: languages
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
2
|
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
25 ;; 02111-1307, USA.
|
0
|
26
|
2
|
27 ;;; Synched up with: FSF 19.34.
|
0
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
31 ;; Fortran mode has been upgraded and is now maintained by Stephen A. Wood
|
|
32 ;; (saw@cebaf.gov). It now will use either fixed format continuation line
|
|
33 ;; markers (character in 6th column), or tab format continuation line style
|
|
34 ;; (digit after a TAB character.) A auto-fill mode has been added to
|
|
35 ;; automatically wrap fortran lines that get too long.
|
|
36
|
|
37 ;; We acknowledge many contributions and valuable suggestions by
|
|
38 ;; Lawrence R. Dodd, Ralf Fassel, Ralph Finch, Stephen Gildea,
|
|
39 ;; Dr. Anil Gokhale, Ulrich Mueller, Mark Neale, Eric Prestemon,
|
|
40 ;; Gary Sabot and Richard Stallman.
|
|
41
|
2
|
42 ;; This file may be used with GNU Emacs version 18.xx if the following
|
|
43 ;; variable and function substitutions are made.
|
|
44 ;; Replace:
|
|
45 ;; frame-width with screen-width
|
|
46 ;; auto-fill-function with auto-fill-hook
|
|
47 ;; comment-indent-function with comment-indent-hook
|
|
48 ;; (setq unread-command-events (list c)) with (setq unread-command-char c)
|
0
|
49
|
2
|
50 ;; Bugs to bug-fortran-mode@erl.mit.edu
|
|
51
|
|
52 ;;; Code:
|
0
|
53
|
|
54 (defconst fortran-mode-version "version 1.30.6")
|
|
55
|
|
56 ;;;###autoload
|
|
57 (defvar fortran-tab-mode-default nil
|
|
58 "*Default tabbing/carriage control style for empty files in Fortran mode.
|
|
59 A value of t specifies tab-digit style of continuation control.
|
|
60 A value of nil specifies that continuation lines are marked
|
|
61 with a character in column 6.")
|
|
62
|
|
63 ;; Buffer local, used to display mode line.
|
|
64 (defvar fortran-tab-mode-string nil
|
|
65 "String to appear in mode line when TAB format mode is on.")
|
|
66
|
|
67 (defvar fortran-do-indent 3
|
|
68 "*Extra indentation applied to DO blocks.")
|
|
69
|
|
70 (defvar fortran-if-indent 3
|
|
71 "*Extra indentation applied to IF blocks.")
|
|
72
|
|
73 (defvar fortran-structure-indent 3
|
|
74 "*Extra indentation applied to STRUCTURE, UNION, MAP and INTERFACE blocks.")
|
|
75
|
|
76 (defvar fortran-continuation-indent 5
|
|
77 "*Extra indentation applied to Fortran continuation lines.")
|
|
78
|
|
79 (defvar fortran-comment-indent-style 'fixed
|
|
80 "*nil forces comment lines not to be touched,
|
|
81 'fixed makes fixed comment indentation to `fortran-comment-line-extra-indent'
|
|
82 columns beyond `fortran-minimum-statement-indent-fixed' (for
|
|
83 `indent-tabs-mode' of nil) or `fortran-minimum-statement-indent-tab' (for
|
|
84 `indent-tabs-mode' of t), and 'relative indents to current
|
|
85 Fortran indentation plus `fortran-comment-line-extra-indent'.")
|
|
86
|
|
87 (defvar fortran-comment-line-extra-indent 0
|
|
88 "*Amount of extra indentation for text within full-line comments.")
|
|
89
|
|
90 (defvar comment-line-start nil
|
|
91 "*Delimiter inserted to start new full-line comment.")
|
|
92
|
|
93 (defvar comment-line-start-skip nil
|
|
94 "*Regexp to match the start of a full-line comment.")
|
|
95
|
|
96 (defvar fortran-minimum-statement-indent-fixed 6
|
|
97 "*Minimum statement indentation for fixed format continuation style.")
|
|
98
|
|
99 (defvar fortran-minimum-statement-indent-tab (max tab-width 6)
|
|
100 "*Minimum statement indentation for TAB format continuation style.")
|
|
101
|
|
102 ;; Note that this is documented in the v18 manuals as being a string
|
|
103 ;; of length one rather than a single character.
|
|
104 ;; The code in this file accepts either format for compatibility.
|
|
105 (defvar fortran-comment-indent-char " "
|
|
106 "*Single-character string inserted for Fortran comment indentation.
|
|
107 Normally a space.")
|
|
108
|
|
109 (defvar fortran-line-number-indent 1
|
|
110 "*Maximum indentation for Fortran line numbers.
|
|
111 5 means right-justify them within their five-column field.")
|
|
112
|
|
113 (defvar fortran-check-all-num-for-matching-do nil
|
|
114 "*Non-nil causes all numbered lines to be treated as possible DO loop ends.")
|
|
115
|
|
116 (defvar fortran-blink-matching-if nil
|
|
117 "*Non-nil causes \\[fortran-indent-line] on ENDIF statement to blink on matching IF.
|
|
118 Also, from an ENDDO statement blink on matching DO [WHILE] statement.")
|
|
119
|
|
120 (defvar fortran-continuation-string "$"
|
|
121 "*Single-character string used for Fortran continuation lines.
|
|
122 In fixed format continuation style, this character is inserted in
|
|
123 column 6 by \\[fortran-split-line] to begin a continuation line.
|
|
124 Also, if \\[fortran-indent-line] finds this at the beginning of a line, it will
|
|
125 convert the line into a continuation line of the appropriate style.
|
|
126 Normally $.")
|
|
127
|
|
128 (defvar fortran-comment-region "c$$$"
|
|
129 "*String inserted by \\[fortran-comment-region]\
|
|
130 at start of each line in region.")
|
|
131
|
|
132 (defvar fortran-electric-line-number t
|
|
133 "*Non-nil causes line number digits to be moved to the correct column as\
|
|
134 typed.")
|
|
135
|
|
136 (defvar fortran-startup-message t
|
|
137 "*Non-nil displays a startup message when Fortran mode is first called.")
|
|
138
|
|
139 (defvar fortran-column-ruler-fixed
|
|
140 "0 4 6 10 20 30 40 5\
|
|
141 \0 60 70\n\
|
|
142 \[ ]|{ | | | | | | | | \
|
|
143 \| | | | |}\n"
|
|
144 "*String displayed above current line by \\[fortran-column-ruler].
|
|
145 This variable used in fixed format mode.")
|
|
146
|
|
147 (defvar fortran-column-ruler-tab
|
|
148 "0 810 20 30 40 5\
|
|
149 \0 60 70\n\
|
|
150 \[ ]| { | | | | | | | | \
|
|
151 \| | | | |}\n"
|
|
152 "*String displayed above current line by \\[fortran-column-ruler].
|
|
153 This variable used in TAB format mode.")
|
|
154
|
|
155 (defconst bug-fortran-mode "bug-fortran-mode@erl.mit.edu"
|
|
156 "Address of mailing list for Fortran mode bugs.")
|
|
157
|
|
158 (defvar fortran-mode-syntax-table nil
|
|
159 "Syntax table in use in Fortran mode buffers.")
|
|
160
|
|
161 (defvar fortran-analyze-depth 100
|
|
162 "Number of lines to scan to determine whether to use fixed or TAB format\
|
|
163 style.")
|
|
164
|
|
165 (defvar fortran-break-before-delimiters t
|
|
166 "*Non-nil causes `fortran-fill' to break lines before delimiters.")
|
|
167
|
|
168 (if fortran-mode-syntax-table
|
|
169 ()
|
|
170 (setq fortran-mode-syntax-table (make-syntax-table))
|
|
171 (modify-syntax-entry ?\; "w" fortran-mode-syntax-table)
|
|
172 (modify-syntax-entry ?\r " " fortran-mode-syntax-table)
|
|
173 (modify-syntax-entry ?+ "." fortran-mode-syntax-table)
|
|
174 (modify-syntax-entry ?- "." fortran-mode-syntax-table)
|
|
175 (modify-syntax-entry ?= "." fortran-mode-syntax-table)
|
2
|
176 ;; XEmacs change
|
0
|
177 ;;(modify-syntax-entry ?* "." fortran-mode-syntax-table)
|
|
178 (modify-syntax-entry ?/ "." fortran-mode-syntax-table)
|
|
179 (modify-syntax-entry ?\' "\"" fortran-mode-syntax-table)
|
|
180 (modify-syntax-entry ?\" "\"" fortran-mode-syntax-table)
|
|
181 (modify-syntax-entry ?\\ "/" fortran-mode-syntax-table)
|
|
182 (modify-syntax-entry ?. "w" fortran-mode-syntax-table)
|
|
183 (modify-syntax-entry ?_ "w" fortran-mode-syntax-table)
|
|
184 (modify-syntax-entry ?\! "<" fortran-mode-syntax-table)
|
2
|
185 ;; XEmacs change
|
0
|
186 ;;(modify-syntax-entry ?\n ">" fortran-mode-syntax-table)
|
|
187
|
|
188 ;; XEmacs: an attempt to make font-lock understand fortran comments.
|
|
189 (modify-syntax-entry ?\n "> 1" fortran-mode-syntax-table)
|
|
190 (modify-syntax-entry ?* ". 2" fortran-mode-syntax-table)
|
|
191 (modify-syntax-entry ?c "w 2" fortran-mode-syntax-table)
|
|
192 (modify-syntax-entry ?C "w 2" fortran-mode-syntax-table)
|
|
193
|
|
194 )
|
|
195
|
|
196 ;; Comments are real pain in Fortran because there is no way to represent the
|
|
197 ;; standard comment syntax in an Emacs syntax table (we can for VAX-style).
|
|
198 ;; Therefore an unmatched quote in a standard comment will throw fontification
|
|
199 ;; off on the wrong track. So we do syntactic fontification with regexps.
|
|
200
|
|
201 ;; Regexps done by simon@gnu with help from Ulrik Dickow <dickow@nbi.dk> and
|
|
202 ;; probably others Si's forgotten about (sorry).
|
|
203
|
|
204 (defconst fortran-font-lock-keywords-1 nil
|
|
205 "Subdued level highlighting for Fortran mode.")
|
|
206
|
|
207 (defconst fortran-font-lock-keywords-2 nil
|
|
208 "Medium level highlighting for Fortran mode.")
|
|
209
|
|
210 (defconst fortran-font-lock-keywords-3 nil
|
|
211 "Gaudy level highlighting for Fortran mode.")
|
|
212
|
|
213 (let ((comment-chars "c!*")
|
|
214 (fortran-type-types
|
|
215 ; (make-regexp
|
|
216 ; (let ((simple-types '("character" "byte" "integer" "logical"
|
|
217 ; "none" "real" "complex"
|
|
218 ; "double[ \t]*precision" "double[ \t]*complex"))
|
|
219 ; (structured-types '("structure" "union" "map"))
|
|
220 ; (other-types '("record" "dimension" "parameter" "common" "save"
|
|
221 ; "external" "intrinsic" "data" "equivalence")))
|
|
222 ; (append
|
|
223 ; (mapcar (lambda (x) (concat "implicit[ \t]*" x)) simple-types)
|
|
224 ; simple-types
|
|
225 ; (mapcar (lambda (x) (concat "end[ \t]*" x)) structured-types)
|
|
226 ; structured-types
|
|
227 ; other-types)))
|
|
228 (concat "byte\\|c\\(haracter\\|om\\(mon\\|plex\\)\\)\\|"
|
|
229 "d\\(ata\\|imension\\|ouble"
|
|
230 "[ \t]*\\(complex\\|precision\\)\\)\\|"
|
|
231 "e\\(nd[ \t]*\\(map\\|structure\\|union\\)\\|"
|
|
232 "quivalence\\|xternal\\)\\|"
|
|
233 "i\\(mplicit[ \t]*\\(byte\\|"
|
|
234 "c\\(haracter\\|omplex\\)\\|"
|
|
235 "double[ \t]*\\(complex\\|precision\\)\\|"
|
|
236 "integer\\|logical\\|none\\|real\\)\\|"
|
|
237 "nt\\(eger\\|rinsic\\)\\)\\|"
|
|
238 "logical\\|map\\|none\\|parameter\\|re\\(al\\|cord\\)\\|"
|
|
239 "s\\(ave\\|tructure\\)\\|union"))
|
|
240 (fortran-keywords
|
|
241 ; ("continue" "format" "end" "enddo" "if" "then" "else" "endif"
|
|
242 ; "elseif" "while" "inquire" "stop" "return" "include" "open"
|
|
243 ; "close" "read" "write" "format" "print")
|
|
244 (concat "c\\(lose\\|ontinue\\)\\|"
|
|
245 "e\\(lse\\(\\|if\\)\\|nd\\(\\|do\\|if\\)\\)\\|format\\|"
|
|
246 "i\\(f\\|n\\(clude\\|quire\\)\\)\\|open\\|print\\|"
|
|
247 "re\\(ad\\|turn\\)\\|stop\\|then\\|w\\(hile\\|rite\\)"))
|
|
248 (fortran-logicals
|
|
249 ; ("and" "or" "not" "lt" "le" "eq" "ge" "gt" "ne" "true" "false")
|
|
250 "and\\|eq\\|false\\|g[et]\\|l[et]\\|n\\(e\\|ot\\)\\|or\\|true"))
|
|
251
|
|
252 (setq fortran-font-lock-keywords-1
|
|
253 (list
|
|
254 ;;
|
|
255 ;; Fontify syntactically (assuming strings cannot be quoted or span lines).
|
|
256 (cons (concat "^[" comment-chars "].*") 'font-lock-comment-face)
|
|
257 '(fortran-match-!-comment . font-lock-comment-face)
|
|
258 (list (concat "^[^" comment-chars "\t\n]" (make-string 71 ?.) "\\(.*\\)")
|
|
259 '(1 font-lock-comment-face))
|
|
260 '("'[^'\n]*'?" . font-lock-string-face)
|
|
261 ;;
|
|
262 ;; Program, subroutine and function declarations, plus calls.
|
|
263 (list (concat "\\<\\(block[ \t]*data\\|call\\|entry\\|function\\|"
|
|
264 "program\\|subroutine\\)\\>[ \t]*\\(\\sw+\\)?")
|
|
265 '(1 font-lock-keyword-face)
|
|
266 '(2 font-lock-function-name-face nil t))))
|
|
267
|
|
268 (setq fortran-font-lock-keywords-2
|
|
269 (append fortran-font-lock-keywords-1
|
|
270 (list
|
|
271 ;;
|
|
272 ;; Fontify all type specifiers (must be first; see below).
|
|
273 (cons (concat "\\<\\(" fortran-type-types "\\)\\>") 'font-lock-type-face)
|
|
274 ;;
|
|
275 ;; Fontify all builtin keywords (except logical, do and goto; see below).
|
|
276 (concat "\\<\\(" fortran-keywords "\\)\\>")
|
|
277 ;;
|
|
278 ;; Fontify all builtin operators.
|
|
279 (concat "\\.\\(" fortran-logicals "\\)\\.")
|
|
280 ;;
|
|
281 ;; Fontify do/goto keywords and targets, and goto tags.
|
|
282 (list "\\<\\(do\\|go *to\\)\\>[ \t]*\\([0-9]+\\)?"
|
|
283 '(1 font-lock-keyword-face)
|
|
284 '(2 font-lock-reference-face nil t))
|
|
285 (cons "^ *\\([0-9]+\\)" 'font-lock-reference-face))))
|
|
286
|
|
287 (setq fortran-font-lock-keywords-3
|
|
288 (append
|
|
289 ;;
|
|
290 ;; The list `fortran-font-lock-keywords-1'.
|
|
291 fortran-font-lock-keywords-1
|
|
292 ;;
|
|
293 ;; Fontify all type specifiers plus their declared items.
|
|
294 (list
|
|
295 (list (concat "\\<\\(" fortran-type-types "\\)\\>[ \t(/]*\\(*\\)?")
|
|
296 ;; Fontify the type specifier.
|
|
297 '(1 font-lock-type-face)
|
|
298 ;; Fontify each declaration item (or just the /.../ block name).
|
|
299 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
300 ;; Start after any *(...) expression.
|
|
301 (and (match-beginning 15) (forward-sexp 1))
|
|
302 ;; No need to clean up.
|
|
303 nil
|
|
304 ;; Fontify as a variable name, functions are fontified elsewhere.
|
|
305 (1 font-lock-variable-name-face nil t))))
|
|
306 ;;
|
|
307 ;; Things extra to `fortran-font-lock-keywords-3' (must be done first).
|
|
308 (list
|
|
309 ;;
|
|
310 ;; Fontify goto-like `err=label'/`end=label' in read/write statements.
|
|
311 '(", *\\(e\\(nd\\|rr\\)\\)\\> *\\(= *\\([0-9]+\\)\\)?"
|
|
312 (1 font-lock-keyword-face) (4 font-lock-reference-face nil t))
|
|
313 ;;
|
|
314 ;; Highlight standard continuation character and in a TAB-formatted line.
|
|
315 '("^ \\([^ 0]\\)" 1 font-lock-string-face)
|
|
316 '("^\t\\([1-9]\\)" 1 font-lock-string-face))
|
|
317 ;;
|
|
318 ;; The list `fortran-font-lock-keywords-2' less that for types (see above).
|
|
319 (cdr (nthcdr (length fortran-font-lock-keywords-1)
|
|
320 fortran-font-lock-keywords-2))))
|
|
321 )
|
|
322
|
|
323 (defvar fortran-font-lock-keywords fortran-font-lock-keywords-1
|
|
324 "Default expressions to highlight in Fortran mode.")
|
|
325
|
2
|
326 ;; XEmacs change
|
0
|
327 (put 'fortran-mode 'font-lock-defaults '((fortran-font-lock-keywords
|
|
328 fortran-font-lock-keywords-1
|
|
329 fortran-font-lock-keywords-2
|
|
330 fortran-font-lock-keywords-3)
|
|
331 t t ((?/ . "$/"))))
|
|
332
|
|
333 ;; Our previous version.
|
|
334
|
|
335 ;(defconst fortran-font-lock-keywords-1
|
|
336 ; (purecopy
|
|
337 ; (list
|
|
338 ; ;; fontify comments
|
|
339 ; '("^[cC*].*$" . font-lock-comment-face)
|
|
340 ; ;;
|
|
341 ; ;; fontify preprocessor directives.
|
|
342 ; '("^#[ \t]*[a-z]+" . font-lock-preprocessor-face)
|
|
343 ; ;;
|
|
344 ; ;; fontify names being defined.
|
|
345 ; '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2
|
|
346 ; font-lock-function-name-face)
|
|
347 ; ;;
|
|
348 ; ;; fontify other preprocessor lines.
|
|
349 ; '("^#[ \t]*\\(if\\|ifn?def\\|elif\\)[ \t]+\\([^\n]+\\)"
|
|
350 ; 2 font-lock-function-name-face t)
|
|
351
|
|
352 ; ;; Subroutine and function declarations
|
|
353 ; '("^[ \t]*subroutine.*$" . font-lock-function-name-face)
|
|
354 ; '("^[ \t].*function.*$" . font-lock-function-name-face)
|
|
355 ; '("^[ \t].*program.*$" . font-lock-function-name-face)
|
|
356 ; '("^[ \t].*entry.*$" . font-lock-function-name-face)
|
|
357 ; ))
|
|
358 ; "For consideration as a value of `fortran-font-lock-keywords'.
|
|
359 ;This does fairly subdued highlighting of comments and function names.")
|
|
360
|
|
361 ;(defconst fortran-font-lock-keywords-2
|
|
362 ; (purecopy
|
|
363 ; (append fortran-font-lock-keywords-1
|
|
364 ; (list
|
|
365 ; ;; Variable declarations
|
|
366 ; '("^[ \t]*\\(\\(integer\\|logical\\|real\\|complex\\|double[ \t]*precision\\|character\\|parameter\\)[^ \t]*\\)"
|
|
367 ; 1 font-lock-keyword-face)
|
|
368 ; ;; Common blocks, external, etc
|
|
369 ; '("^[ \t]*\\(common\\|save\\|external\\|intrinsic\\|data\\)" 1 font-lock-keyword-face)
|
|
370 ; ;; Other keywords
|
|
371 ; '("^[ \t]*[0-9]*[ \t]*\\(if\\)[ \t]*("
|
|
372 ; 1 font-lock-keyword-face)
|
|
373
|
|
374 ; ;; Then
|
|
375 ; ;; '("^\\(\\([ \t]*[0-9]*[ \t]*\\)\\|\\( [^ ]\\)\\).*[ \t]*\\(then\\)[ \t]*"
|
|
376 ; ;; 4 font-lock-keyword-face)
|
|
377 ; '("\\(then\\)[ \t]*$" 1 font-lock-keyword-face)
|
|
378
|
|
379 ; ;; '("^[ \t]*[0-9]*[ \t]*\\(end[ \t]*if\\)[ \t]*$"
|
|
380 ; '("\\(end[ \t]*if\\)[ \t]*$"
|
|
381 ; 1 font-lock-keyword-face)
|
|
382 ; ;; '("\\(else[ \t]*\\(if\\)?\\)"
|
|
383 ; ;; the below works better <mdb@cdc.noaa.gov>
|
|
384 ; '("^[ \t]*[0-9]*[ \t]*\\(else[ \t]*\\(if\\)?\\)"
|
|
385 ; 1 font-lock-keyword-face)
|
|
386 ; '("^[ \t]*[0-9]*[ \t]*\\(do\\)[ \t]*[0-9]+"
|
|
387 ; 1 font-lock-keyword-face)
|
|
388 ; '("^[ \t]*[0-9]*[ \t]*\\(do\\)[ \t]*[a-z0-9_$]+[ \t]*="
|
|
389 ; 1 font-lock-keyword-face)
|
|
390 ; '("^[ \t]*[0-9]*[ \t]*\\(end[ \t]*do\\)"
|
|
391 ; 1 font-lock-keyword-face)
|
|
392 ; '("^[ \t]*[0-9]+[ \t]*\\(continue\\)" 1 font-lock-keyword-face)
|
|
393 ; '("^[ \t]*[0-9]*[ \t]*\\(call\\)" 1 font-lock-keyword-face)
|
|
394 ; '("^[ \t]*[0-9]*[ \t]*\\(go[ \t]*to\\)" 1 font-lock-keyword-face)
|
|
395
|
|
396 ; '("^[ \t]*[0-9]*[ \t]*\\(open\\|close\\|read\\|write\\|format\\)[ \t]*("
|
|
397 ; 1 font-lock-keyword-face)
|
|
398 ; '("^[ \t]*[0-9]*[ \t]*\\(print\\)[ \t]*[*'0-9]+" 1 font-lock-keyword-face)
|
|
399
|
|
400 ; '("^[ \t]*[0-9]*[ \t]*\\(end\\|return\\)[ \t]*$" 1 font-lock-keyword-face)
|
|
401
|
|
402 ; '("^[ \t]*[0-9]*[ \t]*\\(stop\\)[ \t]*['0-9]*" 1 font-lock-keyword-face)
|
|
403
|
|
404 ; ;; Boolean and relational operations, logical true and false
|
|
405 ; '("\\.\\(and\\|or\\|not\\|lt\\|le\\|eq\\|ge\\|gt\\|ne\\|true\\|false\\)\\."
|
|
406 ; . font-lock-keyword-face)
|
|
407 ; )))
|
|
408 ; "For consideration as a value of `fortran-font-lock-keywords'.
|
|
409 ;This highlights variable types, \"keywords,\" etc.")
|
|
410
|
|
411
|
|
412 (defvar fortran-mode-map ()
|
|
413 "Keymap used in Fortran mode.")
|
|
414 (if fortran-mode-map
|
|
415 ()
|
|
416 (setq fortran-mode-map (make-sparse-keymap))
|
|
417 (define-key fortran-mode-map ";" 'fortran-abbrev-start)
|
|
418 (define-key fortran-mode-map "\C-c;" 'fortran-comment-region)
|
|
419 (define-key fortran-mode-map "\e\C-a" 'beginning-of-fortran-subprogram)
|
|
420 (define-key fortran-mode-map "\e\C-e" 'end-of-fortran-subprogram)
|
|
421 (define-key fortran-mode-map "\e;" 'fortran-indent-comment)
|
|
422 (define-key fortran-mode-map "\e\C-h" 'mark-fortran-subprogram)
|
|
423 (define-key fortran-mode-map "\e\n" 'fortran-split-line)
|
|
424 (define-key fortran-mode-map "\n" 'fortran-indent-new-line)
|
|
425 (define-key fortran-mode-map "\e\C-q" 'fortran-indent-subprogram)
|
|
426 (define-key fortran-mode-map "\C-c\C-w" 'fortran-window-create-momentarily)
|
|
427 (define-key fortran-mode-map "\C-c\C-r" 'fortran-column-ruler)
|
|
428 (define-key fortran-mode-map "\C-c\C-p" 'fortran-previous-statement)
|
|
429 (define-key fortran-mode-map "\C-c\C-n" 'fortran-next-statement)
|
|
430 (define-key fortran-mode-map "\t" 'fortran-indent-line)
|
|
431 (define-key fortran-mode-map "0" 'fortran-electric-line-number)
|
|
432 (define-key fortran-mode-map "1" 'fortran-electric-line-number)
|
|
433 (define-key fortran-mode-map "2" 'fortran-electric-line-number)
|
|
434 (define-key fortran-mode-map "3" 'fortran-electric-line-number)
|
|
435 (define-key fortran-mode-map "4" 'fortran-electric-line-number)
|
|
436 (define-key fortran-mode-map "5" 'fortran-electric-line-number)
|
|
437 (define-key fortran-mode-map "6" 'fortran-electric-line-number)
|
|
438 (define-key fortran-mode-map "7" 'fortran-electric-line-number)
|
|
439 (define-key fortran-mode-map "8" 'fortran-electric-line-number)
|
|
440 (define-key fortran-mode-map "9" 'fortran-electric-line-number))
|
|
441
|
|
442 (defvar fortran-mode-abbrev-table nil)
|
|
443 (if fortran-mode-abbrev-table
|
|
444 ()
|
|
445 (let ((ac abbrevs-changed))
|
|
446 (define-abbrev-table 'fortran-mode-abbrev-table ())
|
|
447 (define-abbrev fortran-mode-abbrev-table ";au" "automatic" nil)
|
|
448 (define-abbrev fortran-mode-abbrev-table ";b" "byte" nil)
|
|
449 (define-abbrev fortran-mode-abbrev-table ";bd" "block data" nil)
|
|
450 (define-abbrev fortran-mode-abbrev-table ";ch" "character" nil)
|
|
451 (define-abbrev fortran-mode-abbrev-table ";cl" "close" nil)
|
|
452 (define-abbrev fortran-mode-abbrev-table ";c" "continue" nil)
|
|
453 (define-abbrev fortran-mode-abbrev-table ";cm" "common" nil)
|
|
454 (define-abbrev fortran-mode-abbrev-table ";cx" "complex" nil)
|
|
455 (define-abbrev fortran-mode-abbrev-table ";df" "define" nil)
|
|
456 (define-abbrev fortran-mode-abbrev-table ";di" "dimension" nil)
|
|
457 (define-abbrev fortran-mode-abbrev-table ";do" "double" nil)
|
|
458 (define-abbrev fortran-mode-abbrev-table ";dc" "double complex" nil)
|
|
459 (define-abbrev fortran-mode-abbrev-table ";dp" "double precision" nil)
|
|
460 (define-abbrev fortran-mode-abbrev-table ";dw" "do while" nil)
|
|
461 (define-abbrev fortran-mode-abbrev-table ";e" "else" nil)
|
|
462 (define-abbrev fortran-mode-abbrev-table ";ed" "enddo" nil)
|
|
463 (define-abbrev fortran-mode-abbrev-table ";el" "elseif" nil)
|
|
464 (define-abbrev fortran-mode-abbrev-table ";en" "endif" nil)
|
|
465 (define-abbrev fortran-mode-abbrev-table ";eq" "equivalence" nil)
|
|
466 (define-abbrev fortran-mode-abbrev-table ";ew" "endwhere" nil)
|
|
467 (define-abbrev fortran-mode-abbrev-table ";ex" "external" nil)
|
|
468 (define-abbrev fortran-mode-abbrev-table ";ey" "entry" nil)
|
|
469 (define-abbrev fortran-mode-abbrev-table ";f" "format" nil)
|
|
470 (define-abbrev fortran-mode-abbrev-table ";fa" ".false." nil)
|
|
471 (define-abbrev fortran-mode-abbrev-table ";fu" "function" nil)
|
|
472 (define-abbrev fortran-mode-abbrev-table ";g" "goto" nil)
|
|
473 (define-abbrev fortran-mode-abbrev-table ";im" "implicit" nil)
|
|
474 (define-abbrev fortran-mode-abbrev-table ";ib" "implicit byte" nil)
|
|
475 (define-abbrev fortran-mode-abbrev-table ";ic" "implicit complex" nil)
|
|
476 (define-abbrev fortran-mode-abbrev-table ";ich" "implicit character" nil)
|
|
477 (define-abbrev fortran-mode-abbrev-table ";ii" "implicit integer" nil)
|
|
478 (define-abbrev fortran-mode-abbrev-table ";il" "implicit logical" nil)
|
|
479 (define-abbrev fortran-mode-abbrev-table ";ir" "implicit real" nil)
|
|
480 (define-abbrev fortran-mode-abbrev-table ";inc" "include" nil)
|
|
481 (define-abbrev fortran-mode-abbrev-table ";in" "integer" nil)
|
|
482 (define-abbrev fortran-mode-abbrev-table ";intr" "intrinsic" nil)
|
|
483 (define-abbrev fortran-mode-abbrev-table ";l" "logical" nil)
|
|
484 (define-abbrev fortran-mode-abbrev-table ";n" "namelist" nil)
|
|
485 (define-abbrev fortran-mode-abbrev-table ";o" "open" nil) ; was ;op
|
|
486 (define-abbrev fortran-mode-abbrev-table ";pa" "parameter" nil)
|
|
487 (define-abbrev fortran-mode-abbrev-table ";pr" "program" nil)
|
|
488 (define-abbrev fortran-mode-abbrev-table ";ps" "pause" nil)
|
|
489 (define-abbrev fortran-mode-abbrev-table ";p" "print" nil)
|
|
490 (define-abbrev fortran-mode-abbrev-table ";rc" "record" nil)
|
|
491 (define-abbrev fortran-mode-abbrev-table ";re" "real" nil)
|
|
492 (define-abbrev fortran-mode-abbrev-table ";r" "read" nil)
|
|
493 (define-abbrev fortran-mode-abbrev-table ";rt" "return" nil)
|
|
494 (define-abbrev fortran-mode-abbrev-table ";rw" "rewind" nil)
|
|
495 (define-abbrev fortran-mode-abbrev-table ";s" "stop" nil)
|
|
496 (define-abbrev fortran-mode-abbrev-table ";sa" "save" nil)
|
|
497 (define-abbrev fortran-mode-abbrev-table ";st" "structure" nil)
|
|
498 (define-abbrev fortran-mode-abbrev-table ";sc" "static" nil)
|
|
499 (define-abbrev fortran-mode-abbrev-table ";su" "subroutine" nil)
|
|
500 (define-abbrev fortran-mode-abbrev-table ";tr" ".true." nil)
|
|
501 (define-abbrev fortran-mode-abbrev-table ";ty" "type" nil)
|
|
502 (define-abbrev fortran-mode-abbrev-table ";vo" "volatile" nil)
|
|
503 (define-abbrev fortran-mode-abbrev-table ";w" "write" nil)
|
|
504 (define-abbrev fortran-mode-abbrev-table ";wh" "where" nil)
|
|
505 (setq abbrevs-changed ac)))
|
|
506
|
|
507 ;;;###autoload
|
|
508 (defun fortran-mode ()
|
|
509 "Major mode for editing Fortran code.
|
|
510 \\[fortran-indent-line] indents the current Fortran line correctly.
|
|
511 DO statements must not share a common CONTINUE.
|
|
512
|
|
513 Type ;? or ;\\[help-command] to display a list of built-in\
|
|
514 abbrevs for Fortran keywords.
|
|
515
|
|
516 Key definitions:
|
|
517 \\{fortran-mode-map}
|
|
518
|
|
519 Variables controlling indentation style and extra features:
|
|
520
|
|
521 comment-start
|
|
522 Normally nil in Fortran mode. If you want to use comments
|
|
523 starting with `!', set this to the string \"!\".
|
|
524 fortran-do-indent
|
|
525 Extra indentation within do blocks. (default 3)
|
|
526 fortran-if-indent
|
|
527 Extra indentation within if blocks. (default 3)
|
|
528 fortran-structure-indent
|
|
529 Extra indentation within structure, union, map and interface blocks.
|
|
530 (default 3)
|
|
531 fortran-continuation-indent
|
|
532 Extra indentation applied to continuation statements. (default 5)
|
|
533 fortran-comment-line-extra-indent
|
|
534 Amount of extra indentation for text within full-line comments. (default 0)
|
|
535 fortran-comment-indent-style
|
|
536 nil means don't change indentation of text in full-line comments,
|
|
537 fixed means indent that text at `fortran-comment-line-extra-indent' beyond
|
|
538 the value of `fortran-minimum-statement-indent-fixed' (for fixed
|
|
539 format continuation style) or `fortran-minimum-statement-indent-tab'
|
|
540 (for TAB format continuation style).
|
|
541 relative means indent at `fortran-comment-line-extra-indent' beyond the
|
|
542 indentation for a line of code.
|
|
543 (default 'fixed)
|
|
544 fortran-comment-indent-char
|
|
545 Single-character string to be inserted instead of space for
|
|
546 full-line comment indentation. (default \" \")
|
|
547 fortran-minimum-statement-indent-fixed
|
|
548 Minimum indentation for Fortran statements in fixed format mode. (def.6)
|
|
549 fortran-minimum-statement-indent-tab
|
|
550 Minimum indentation for Fortran statements in TAB format mode. (default 9)
|
|
551 fortran-line-number-indent
|
|
552 Maximum indentation for line numbers. A line number will get
|
|
553 less than this much indentation if necessary to avoid reaching
|
|
554 column 5. (default 1)
|
|
555 fortran-check-all-num-for-matching-do
|
|
556 Non-nil causes all numbered lines to be treated as possible \"continue\"
|
|
557 statements. (default nil)
|
|
558 fortran-blink-matching-if
|
|
559 Non-nil causes \\[fortran-indent-line] on an ENDIF statement to blink on
|
|
560 matching IF. Also, from an ENDDO statement, blink on matching DO [WHILE]
|
|
561 statement. (default nil)
|
|
562 fortran-continuation-string
|
|
563 Single-character string to be inserted in column 5 of a continuation
|
|
564 line. (default \"$\")
|
|
565 fortran-comment-region
|
|
566 String inserted by \\[fortran-comment-region] at start of each line in
|
|
567 region. (default \"c$$$\")
|
|
568 fortran-electric-line-number
|
|
569 Non-nil causes line number digits to be moved to the correct column
|
|
570 as typed. (default t)
|
|
571 fortran-break-before-delimiters
|
|
572 Non-nil causes `fortran-fill' breaks lines before delimiters.
|
|
573 (default t)
|
|
574 fortran-startup-message
|
|
575 Set to nil to inhibit message first time Fortran mode is used.
|
|
576
|
|
577 Turning on Fortran mode calls the value of the variable `fortran-mode-hook'
|
|
578 with no args, if that value is non-nil."
|
|
579 (interactive)
|
|
580 (kill-all-local-variables)
|
|
581 (if fortran-startup-message
|
|
582 (message "Emacs Fortran mode %s. Bugs to %s"
|
|
583 fortran-mode-version bug-fortran-mode))
|
|
584 (setq fortran-startup-message nil)
|
|
585 (setq local-abbrev-table fortran-mode-abbrev-table)
|
|
586 (set-syntax-table fortran-mode-syntax-table)
|
2
|
587 ;; Font Lock mode support. (Removed for XEmacs)
|
|
588 ;; (make-local-variable 'font-lock-defaults)
|
|
589 ;; (setq font-lock-defaults '((fortran-font-lock-keywords
|
|
590 ;; fortran-font-lock-keywords-1
|
|
591 ;; fortran-font-lock-keywords-2
|
|
592 ;; fortran-font-lock-keywords-3)
|
|
593 ;; t t ((?/ . "$/"))))
|
0
|
594 (make-local-variable 'fortran-break-before-delimiters)
|
|
595 (setq fortran-break-before-delimiters t)
|
|
596 (make-local-variable 'indent-line-function)
|
|
597 (setq indent-line-function 'fortran-indent-line)
|
|
598 (make-local-variable 'comment-indent-function)
|
|
599 (setq comment-indent-function 'fortran-comment-hook)
|
|
600 (make-local-variable 'comment-line-start-skip)
|
|
601 (setq comment-line-start-skip
|
|
602 "^[Cc*]\\(\\([^ \t\n]\\)\\2\\2*\\)?[ \t]*\\|^#.*")
|
|
603 (make-local-variable 'comment-line-start)
|
|
604 (setq comment-line-start "c")
|
|
605 (make-local-variable 'comment-start-skip)
|
|
606 (setq comment-start-skip "![ \t]*")
|
|
607 (make-local-variable 'comment-start)
|
|
608 (setq comment-start nil)
|
|
609 (make-local-variable 'require-final-newline)
|
|
610 (setq require-final-newline t)
|
|
611 (make-local-variable 'abbrev-all-caps)
|
|
612 (setq abbrev-all-caps t)
|
|
613 (make-local-variable 'indent-tabs-mode)
|
|
614 (setq indent-tabs-mode nil)
|
|
615 ;;;(setq abbrev-mode t) ; ?? (abbrev-mode 1) instead??
|
|
616 (setq fill-column 72) ; Already local?
|
|
617 (use-local-map fortran-mode-map)
|
|
618 (setq mode-name "Fortran")
|
|
619 (setq major-mode 'fortran-mode)
|
|
620 ;;;(make-local-variable 'fortran-tab-mode)
|
|
621 (make-local-variable 'fortran-comment-line-extra-indent)
|
|
622 (make-local-variable 'fortran-minimum-statement-indent-fixed)
|
|
623 (make-local-variable 'fortran-minimum-statement-indent-tab)
|
|
624 (make-local-variable 'fortran-column-ruler-fixed)
|
|
625 (make-local-variable 'fortran-column-ruler-tab)
|
|
626 (make-local-variable 'fortran-tab-mode-string)
|
|
627 (setq fortran-tab-mode-string " TAB-format")
|
|
628 (setq indent-tabs-mode (fortran-analyze-file-format))
|
|
629 (run-hooks 'fortran-mode-hook))
|
|
630
|
|
631 (defun fortran-comment-hook ()
|
|
632 (save-excursion
|
|
633 (skip-chars-backward " \t")
|
|
634 (max (+ 1 (current-column))
|
|
635 comment-column)))
|
|
636
|
|
637 (defun fortran-indent-comment ()
|
|
638 "Align or create comment on current line.
|
|
639 Existing comments of all types are recognized and aligned.
|
|
640 If the line has no comment, a side-by-side comment is inserted and aligned
|
|
641 if the value of comment-start is not nil.
|
|
642 Otherwise, a separate-line comment is inserted, on this line
|
|
643 or on a new line inserted before this line if this line is not blank."
|
|
644 (interactive)
|
|
645 (beginning-of-line)
|
|
646 ;; Recognize existing comments of either kind.
|
|
647 (cond ((looking-at comment-line-start-skip)
|
|
648 (fortran-indent-line))
|
|
649 ((fortran-find-comment-start-skip) ; catches any inline comment and
|
|
650 ; leaves point after comment-start-skip
|
|
651 (if comment-start-skip
|
|
652 (progn (goto-char (match-beginning 0))
|
|
653 (if (not (= (current-column) (fortran-comment-hook)))
|
|
654 (progn (delete-horizontal-space)
|
|
655 (indent-to (fortran-comment-hook)))))
|
|
656 (end-of-line))) ; otherwise goto end of line or sth else?
|
|
657 ;; No existing comment.
|
|
658 ;; If side-by-side comments are defined, insert one,
|
|
659 ;; unless line is now blank.
|
|
660 ((and comment-start (not (looking-at "^[ \t]*$")))
|
|
661 (end-of-line)
|
|
662 (delete-horizontal-space)
|
|
663 (indent-to (fortran-comment-hook))
|
|
664 (insert comment-start))
|
|
665 ;; Else insert separate-line comment, making a new line if nec.
|
|
666 (t
|
|
667 (if (looking-at "^[ \t]*$")
|
|
668 (delete-horizontal-space)
|
|
669 (beginning-of-line)
|
|
670 (insert "\n")
|
|
671 (forward-char -1))
|
|
672 (insert comment-line-start)
|
|
673 (insert-char (if (stringp fortran-comment-indent-char)
|
|
674 (aref fortran-comment-indent-char 0)
|
|
675 fortran-comment-indent-char)
|
|
676 (- (calculate-fortran-indent) (current-column))))))
|
|
677
|
|
678 (defun fortran-comment-region (beg-region end-region arg)
|
|
679 "Comments every line in the region.
|
|
680 Puts fortran-comment-region at the beginning of every line in the region.
|
|
681 BEG-REGION and END-REGION are args which specify the region boundaries.
|
|
682 With non-nil ARG, uncomments the region."
|
|
683 (interactive "*r\nP")
|
|
684 (let ((end-region-mark (make-marker)) (save-point (point-marker)))
|
|
685 (set-marker end-region-mark end-region)
|
|
686 (goto-char beg-region)
|
|
687 (beginning-of-line)
|
|
688 (if (not arg) ;comment the region
|
|
689 (progn (insert fortran-comment-region)
|
|
690 (while (and (= (forward-line 1) 0)
|
|
691 (< (point) end-region-mark))
|
|
692 (insert fortran-comment-region)))
|
|
693 (let ((com (regexp-quote fortran-comment-region))) ;uncomment the region
|
|
694 (if (looking-at com)
|
|
695 (delete-region (point) (match-end 0)))
|
|
696 (while (and (= (forward-line 1) 0)
|
|
697 (< (point) end-region-mark))
|
|
698 (if (looking-at com)
|
|
699 (delete-region (point) (match-end 0))))))
|
|
700 (goto-char save-point)
|
|
701 (set-marker end-region-mark nil)
|
|
702 (set-marker save-point nil)))
|
|
703
|
|
704 (defun fortran-abbrev-start ()
|
|
705 "Typing ;\\[help-command] or ;? lists all the Fortran abbrevs.
|
|
706 Any other key combination is executed normally."
|
|
707 (interactive)
|
2
|
708 ;; XEmacs change
|
0
|
709 (let (e c)
|
|
710 (insert last-command-char)
|
|
711 (setq e (next-command-event)
|
|
712 c (event-to-character e))
|
|
713 ;; insert char if not equal to `?'
|
|
714 (if (or (= c ??) (eq c help-char))
|
|
715 (fortran-abbrev-help)
|
76
|
716 (setq unread-command-events (list e)))))
|
0
|
717
|
|
718 (defun fortran-abbrev-help ()
|
|
719 "List the currently defined abbrevs in Fortran mode."
|
|
720 (interactive)
|
|
721 (message "Listing abbrev table...")
|
|
722 (display-buffer (fortran-prepare-abbrev-list-buffer))
|
|
723 (message "Listing abbrev table...done"))
|
|
724
|
|
725 (defun fortran-prepare-abbrev-list-buffer ()
|
|
726 (save-excursion
|
|
727 (set-buffer (get-buffer-create "*Abbrevs*"))
|
|
728 (erase-buffer)
|
|
729 (insert-abbrev-table-description 'fortran-mode-abbrev-table t)
|
|
730 (goto-char (point-min))
|
|
731 (set-buffer-modified-p nil)
|
|
732 (edit-abbrevs-mode))
|
|
733 (get-buffer-create "*Abbrevs*"))
|
|
734
|
|
735 (defun fortran-column-ruler ()
|
|
736 "Inserts a column ruler momentarily above current line, till next keystroke.
|
|
737 The ruler is defined by the value of `fortran-column-ruler-fixed' when in fixed
|
|
738 format mode, and `fortran-column-ruler-tab' when in TAB format mode.
|
|
739 The key typed is executed unless it is SPC."
|
|
740 (interactive)
|
|
741 (momentary-string-display
|
|
742 (if indent-tabs-mode
|
|
743 fortran-column-ruler-tab
|
|
744 fortran-column-ruler-fixed)
|
|
745 (save-excursion
|
|
746 (beginning-of-line)
|
|
747 (if (eq (window-start (selected-window))
|
|
748 (window-point (selected-window)))
|
|
749 (progn (forward-line) (point))
|
|
750 (point)))
|
|
751 nil "Type SPC or any command to erase ruler."))
|
|
752
|
|
753 (defun fortran-window-create ()
|
|
754 "Makes the window 72 columns wide.
|
|
755 See also `fortran-window-create-momentarily'."
|
|
756 (interactive)
|
|
757 (condition-case error
|
|
758 (progn
|
|
759 (let ((window-min-width 2))
|
|
760 (if (< (window-width) (frame-width))
|
|
761 (enlarge-window-horizontally (- (frame-width)
|
|
762 (window-width) 1)))
|
|
763 (split-window-horizontally 73)
|
|
764 (other-window 1)
|
|
765 (switch-to-buffer " fortran-window-extra" t)
|
|
766 (select-window (previous-window))))
|
|
767 (error (message "No room for Fortran window.")
|
|
768 'error)))
|
|
769
|
|
770 (defun fortran-window-create-momentarily (&optional arg)
|
|
771 "Momentarily makes the window 72 columns wide.
|
|
772 Optional ARG non-nil and non-unity disables the momentary feature.
|
|
773 See also `fortran-window-create'."
|
|
774 (interactive "p")
|
|
775 (if (or (not arg)
|
|
776 (= arg 1))
|
|
777 (save-window-excursion
|
|
778 (if (not (equal (fortran-window-create) 'error))
|
|
779 (progn (message "Type SPC to continue editing.")
|
2
|
780 ;; XEmacs change
|
0
|
781 (let ((char (next-command-event)))
|
|
782 (or (equal (event-to-character char) ? )
|
76
|
783 (setq unread-command-events (list char)))))))
|
0
|
784 (fortran-window-create)))
|
|
785
|
|
786 (defun fortran-split-line ()
|
|
787 "Break line at point and insert continuation marker and alignment."
|
|
788 (interactive)
|
|
789 (delete-horizontal-space)
|
|
790 (if (save-excursion (beginning-of-line) (looking-at comment-line-start-skip))
|
|
791 (insert "\n" comment-line-start " ")
|
|
792 (if indent-tabs-mode
|
|
793 (progn
|
|
794 (insert "\n\t")
|
|
795 (insert-char (fortran-numerical-continuation-char) 1))
|
|
796 (insert "\n " fortran-continuation-string)));Space after \n important
|
|
797 (fortran-indent-line)) ;when the cont string is C, c or *.
|
|
798
|
|
799 (defun fortran-numerical-continuation-char ()
|
|
800 "Return a digit for tab-digit style of continuation lines.
|
|
801 If, previous line is a tab-digit continuation line, returns that digit
|
|
802 plus one. Otherwise return 1. Zero not allowed."
|
|
803 (save-excursion
|
|
804 (forward-line -1)
|
|
805 (if (looking-at "\t[1-9]")
|
|
806 (+ ?1 (% (- (char-after (+ (point) 1)) ?0) 9))
|
|
807 ?1)))
|
|
808
|
|
809 (defun delete-horizontal-regexp (chars)
|
|
810 "Delete all characters in CHARS around point.
|
|
811 CHARS is like the inside of a [...] in a regular expression
|
|
812 except that ] is never special and \ quotes ^, - or \."
|
|
813 (interactive "*s")
|
|
814 (skip-chars-backward chars)
|
|
815 (delete-region (point) (progn (skip-chars-forward chars) (point))))
|
|
816
|
|
817 (defun fortran-electric-line-number (arg)
|
|
818 "Self insert, but if part of a Fortran line number indent it automatically.
|
|
819 Auto-indent does not happen if a numeric arg is used."
|
|
820 (interactive "P")
|
|
821 (if (or arg (not fortran-electric-line-number))
|
|
822 (if arg
|
|
823 (self-insert-command (prefix-numeric-value arg))
|
|
824 (self-insert-command 1))
|
|
825 (if (or (and (= 5 (current-column))
|
|
826 (save-excursion
|
|
827 (beginning-of-line)
|
|
828 (looking-at " ")));In col 5 with only spaces to left.
|
|
829 (and (= (if indent-tabs-mode
|
|
830 fortran-minimum-statement-indent-tab
|
|
831 fortran-minimum-statement-indent-fixed) (current-column))
|
|
832 (save-excursion
|
|
833 (beginning-of-line)
|
|
834 (looking-at "\t"));In col 8 with a single tab to the left.
|
|
835 (not (or (eq last-command 'fortran-indent-line)
|
|
836 (eq last-command
|
|
837 'fortran-indent-new-line))))
|
|
838 (save-excursion
|
|
839 (re-search-backward "[^ \t0-9]"
|
|
840 (save-excursion
|
|
841 (beginning-of-line)
|
|
842 (point))
|
|
843 t)) ;not a line number
|
|
844 (looking-at "[0-9]") ;within a line number
|
|
845 )
|
|
846 (self-insert-command (prefix-numeric-value arg))
|
|
847 (skip-chars-backward " \t")
|
|
848 (insert last-command-char)
|
|
849 (fortran-indent-line))))
|
|
850
|
|
851 (defun beginning-of-fortran-subprogram ()
|
|
852 "Moves point to the beginning of the current Fortran subprogram."
|
|
853 (interactive)
|
|
854 (let ((case-fold-search t))
|
|
855 (beginning-of-line -1)
|
|
856 (re-search-backward "^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]" nil 'move)
|
|
857 (if (looking-at "^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]")
|
|
858 (forward-line 1))))
|
|
859
|
|
860 (defun end-of-fortran-subprogram ()
|
|
861 "Moves point to the end of the current Fortran subprogram."
|
|
862 (interactive)
|
|
863 (let ((case-fold-search t))
|
|
864 (beginning-of-line 2)
|
|
865 (re-search-forward "^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]" nil 'move)
|
|
866 (goto-char (match-beginning 0))
|
|
867 (forward-line 1)))
|
|
868
|
|
869 (defun mark-fortran-subprogram ()
|
|
870 "Put mark at end of Fortran subprogram, point at beginning.
|
|
871 The marks are pushed."
|
|
872 (interactive)
|
|
873 (end-of-fortran-subprogram)
|
|
874 (push-mark (point))
|
|
875 (beginning-of-fortran-subprogram))
|
|
876
|
|
877 (defun fortran-previous-statement ()
|
|
878 "Moves point to beginning of the previous Fortran statement.
|
|
879 Returns `first-statement' if that statement is the first
|
|
880 non-comment Fortran statement in the file, and nil otherwise."
|
|
881 (interactive)
|
|
882 (let (not-first-statement continue-test)
|
|
883 (beginning-of-line)
|
|
884 (setq continue-test
|
|
885 (and
|
|
886 (not (looking-at comment-line-start-skip))
|
|
887 (or (looking-at
|
|
888 (concat "[ \t]*" (regexp-quote fortran-continuation-string)))
|
|
889 (or (looking-at " [^ 0\n]")
|
|
890 (looking-at "\t[1-9]")))))
|
|
891 (while (and (setq not-first-statement (= (forward-line -1) 0))
|
|
892 (or (looking-at comment-line-start-skip)
|
|
893 (looking-at "[ \t]*$")
|
|
894 (looking-at " [^ 0\n]")
|
|
895 (looking-at "\t[1-9]")
|
|
896 (looking-at (concat "[ \t]*" comment-start-skip)))))
|
|
897 (cond ((and continue-test
|
|
898 (not not-first-statement))
|
|
899 (message "Incomplete continuation statement."))
|
|
900 (continue-test
|
|
901 (fortran-previous-statement))
|
|
902 ((not not-first-statement)
|
|
903 'first-statement))))
|
|
904
|
|
905 (defun fortran-next-statement ()
|
|
906 "Moves point to beginning of the next Fortran statement.
|
|
907 Returns `last-statement' if that statement is the last
|
|
908 non-comment Fortran statement in the file, and nil otherwise."
|
|
909 (interactive)
|
|
910 (let (not-last-statement)
|
|
911 (beginning-of-line)
|
|
912 (while (and (setq not-last-statement
|
|
913 (and (= (forward-line 1) 0)
|
|
914 (not (eobp))))
|
|
915 (or (looking-at comment-line-start-skip)
|
|
916 (looking-at "[ \t]*$")
|
|
917 (looking-at " [^ 0\n]")
|
|
918 (looking-at "\t[1-9]")
|
|
919 (looking-at (concat "[ \t]*" comment-start-skip)))))
|
|
920 (if (not not-last-statement)
|
|
921 'last-statement)))
|
|
922
|
|
923 (defun fortran-blink-matching-if ()
|
|
924 ;; From a Fortran ENDIF statement, blink the matching IF statement.
|
|
925 (let ((top-of-window (window-start)) matching-if
|
|
926 (endif-point (point)) message)
|
|
927 (if (save-excursion (beginning-of-line)
|
|
928 (skip-chars-forward " \t0-9")
|
|
929 (looking-at "end[ \t]*if\\b"))
|
|
930 (progn
|
|
931 (if (not (setq matching-if (fortran-beginning-if)))
|
|
932 (setq message "No matching if.")
|
|
933 (if (< matching-if top-of-window)
|
|
934 (save-excursion
|
|
935 (goto-char matching-if)
|
|
936 (beginning-of-line)
|
|
937 (setq message
|
|
938 (concat "Matches "
|
|
939 (buffer-substring
|
|
940 (point) (progn (end-of-line) (point))))))))
|
|
941 (if message
|
|
942 (message "%s" message)
|
|
943 (goto-char matching-if)
|
|
944 (sit-for 1)
|
|
945 (goto-char endif-point))))))
|
|
946
|
|
947 (defun fortran-blink-matching-do ()
|
|
948 ;; From a Fortran ENDDO statement, blink on the matching DO or DO WHILE
|
|
949 ;; statement. This is basically copied from fortran-blink-matching-if.
|
|
950 (let ((top-of-window (window-start)) matching-do
|
|
951 (enddo-point (point)) message)
|
|
952 (if (save-excursion (beginning-of-line)
|
|
953 (skip-chars-forward " \t0-9")
|
|
954 (looking-at "end[ \t]*do\\b"))
|
|
955 (progn
|
|
956 (if (not (setq matching-do (fortran-beginning-do)))
|
|
957 (setq message "No matching do.")
|
|
958 (if (< matching-do top-of-window)
|
|
959 (save-excursion
|
|
960 (goto-char matching-do)
|
|
961 (beginning-of-line)
|
|
962 (setq message
|
|
963 (concat "Matches "
|
|
964 (buffer-substring
|
|
965 (point) (progn (end-of-line) (point))))))))
|
|
966 (if message
|
|
967 (message "%s" message)
|
|
968 (goto-char matching-do)
|
|
969 (sit-for 1)
|
|
970 (goto-char enddo-point))))))
|
|
971
|
|
972 (defun fortran-mark-do ()
|
|
973 "Put mark at end of Fortran DO [WHILE]-ENDDO construct, point at beginning.
|
|
974 The marks are pushed."
|
|
975 (interactive)
|
|
976 (let (enddo-point do-point)
|
|
977 (if (setq enddo-point (fortran-end-do))
|
|
978 (if (not (setq do-point (fortran-beginning-do)))
|
|
979 (message "No matching do.")
|
|
980 ;; Set mark, move point.
|
|
981 (goto-char enddo-point)
|
|
982 (push-mark)
|
|
983 (goto-char do-point)))))
|
|
984
|
|
985 (defun fortran-end-do ()
|
|
986 ;; Search forward for first unmatched ENDDO. Return point or nil.
|
|
987 (if (save-excursion (beginning-of-line)
|
|
988 (skip-chars-forward " \t0-9")
|
|
989 (looking-at "end[ \t]*do\\b"))
|
|
990 ;; Sitting on one.
|
|
991 (match-beginning 0)
|
|
992 ;; Search for one.
|
|
993 (save-excursion
|
|
994 (let ((count 1))
|
|
995 (while (and (not (= count 0))
|
|
996 (not (eq (fortran-next-statement) 'last-statement))
|
|
997 ;; Keep local to subprogram
|
|
998 (not (looking-at "^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]")))
|
|
999
|
|
1000 (skip-chars-forward " \t0-9")
|
|
1001 (cond ((looking-at "end[ \t]*do\\b")
|
|
1002 (setq count (- count 1)))
|
|
1003 ((looking-at "do[ \t]+[^0-9]")
|
|
1004 (setq count (+ count 1)))))
|
|
1005 (and (= count 0)
|
|
1006 ;; All pairs accounted for.
|
|
1007 (point))))))
|
|
1008
|
|
1009 (defun fortran-beginning-do ()
|
|
1010 ;; Search backwards for first unmatched DO [WHILE]. Return point or nil.
|
|
1011 (if (save-excursion (beginning-of-line)
|
|
1012 (skip-chars-forward " \t0-9")
|
|
1013 (looking-at "do[ \t]+"))
|
|
1014 ;; Sitting on one.
|
|
1015 (match-beginning 0)
|
|
1016 ;; Search for one.
|
|
1017 (save-excursion
|
|
1018 (let ((count 1))
|
|
1019 (while (and (not (= count 0))
|
|
1020 (not (eq (fortran-previous-statement) 'first-statement))
|
|
1021 ;; Keep local to subprogram
|
|
1022 (not (looking-at "^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]")))
|
|
1023
|
|
1024 (skip-chars-forward " \t0-9")
|
|
1025 (cond ((looking-at "do[ \t]+[^0-9]")
|
|
1026 (setq count (- count 1)))
|
|
1027 ((looking-at "end[ \t]*do\\b")
|
|
1028 (setq count (+ count 1)))))
|
|
1029
|
|
1030 (and (= count 0)
|
|
1031 ;; All pairs accounted for.
|
|
1032 (point))))))
|
|
1033
|
|
1034 (defun fortran-mark-if ()
|
|
1035 "Put mark at end of Fortran IF-ENDIF construct, point at beginning.
|
|
1036 The marks are pushed."
|
|
1037 (interactive)
|
|
1038 (let (endif-point if-point)
|
|
1039 (if (setq endif-point (fortran-end-if))
|
|
1040 (if (not (setq if-point (fortran-beginning-if)))
|
|
1041 (message "No matching if.")
|
|
1042 ;; Set mark, move point.
|
|
1043 (goto-char endif-point)
|
|
1044 (push-mark)
|
|
1045 (goto-char if-point)))))
|
|
1046
|
|
1047 (defun fortran-end-if ()
|
|
1048 ;; Search forwards for first unmatched ENDIF. Return point or nil.
|
|
1049 (if (save-excursion (beginning-of-line)
|
|
1050 (skip-chars-forward " \t0-9")
|
|
1051 (looking-at "end[ \t]*if\\b"))
|
|
1052 ;; Sitting on one.
|
|
1053 (match-beginning 0)
|
|
1054 ;; Search for one. The point has been already been moved to first
|
|
1055 ;; letter on line but this should not cause troubles.
|
|
1056 (save-excursion
|
|
1057 (let ((count 1))
|
|
1058 (while (and (not (= count 0))
|
|
1059 (not (eq (fortran-next-statement) 'last-statement))
|
|
1060 ;; Keep local to subprogram.
|
|
1061 (not (looking-at
|
|
1062 "^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]")))
|
|
1063
|
|
1064 (skip-chars-forward " \t0-9")
|
|
1065 (cond ((looking-at "end[ \t]*if\\b")
|
|
1066 (setq count (- count 1)))
|
|
1067
|
|
1068 ((looking-at "if[ \t]*(")
|
|
1069 (save-excursion
|
|
1070 (if (or
|
|
1071 (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
|
|
1072 (let (then-test) ; Multi-line if-then.
|
|
1073 (while
|
|
1074 (and (= (forward-line 1) 0)
|
|
1075 ;; Search forward for then.
|
|
1076 (or (looking-at " [^ 0\n]")
|
|
1077 (looking-at "\t[1-9]"))
|
|
1078 (not
|
|
1079 (setq then-test
|
|
1080 (looking-at
|
|
1081 ".*then\\b[ \t]*[^ \t(=a-z0-9]")))))
|
|
1082 then-test))
|
|
1083 (setq count (+ count 1)))))))
|
|
1084
|
|
1085 (and (= count 0)
|
|
1086 ;; All pairs accounted for.
|
|
1087 (point))))))
|
|
1088
|
|
1089 (defun fortran-beginning-if ()
|
|
1090 ;; Search backwards for first unmatched IF-THEN. Return point or nil.
|
|
1091 (if (save-excursion
|
|
1092 ;; May be sitting on multi-line if-then statement, first move to
|
|
1093 ;; beginning of current statement. Note: `fortran-previous-statement'
|
|
1094 ;; moves to previous statement *unless* current statement is first
|
|
1095 ;; one. Only move forward if not first-statement.
|
|
1096 (if (not (eq (fortran-previous-statement) 'first-statement))
|
|
1097 (fortran-next-statement))
|
|
1098 (skip-chars-forward " \t0-9")
|
|
1099 (and
|
|
1100 (looking-at "if[ \t]*(")
|
|
1101 (save-match-data
|
|
1102 (or (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
|
|
1103 ;; Multi-line if-then.
|
|
1104 (let (then-test)
|
|
1105 (while
|
|
1106 (and (= (forward-line 1) 0)
|
|
1107 ;; Search forward for then.
|
|
1108 (or (looking-at " [^ 0\n]")
|
|
1109 (looking-at "\t[1-9]"))
|
|
1110 (not
|
|
1111 (setq then-test
|
|
1112 (looking-at
|
|
1113 ".*then\\b[ \t]*[^ \t(=a-z0-9]")))))
|
|
1114 then-test)))))
|
|
1115 ;; Sitting on one.
|
|
1116 (match-beginning 0)
|
|
1117 ;; Search for one.
|
|
1118 (save-excursion
|
|
1119 (let ((count 1))
|
|
1120 (while (and (not (= count 0))
|
|
1121 (not (eq (fortran-previous-statement) 'first-statement))
|
|
1122 ;; Keep local to subprogram.
|
|
1123 (not (looking-at
|
|
1124 "^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]")))
|
|
1125
|
|
1126 (skip-chars-forward " \t0-9")
|
|
1127 (cond ((looking-at "if[ \t]*(")
|
|
1128 (save-excursion
|
|
1129 (if (or
|
|
1130 (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
|
|
1131 (let (then-test) ; Multi-line if-then.
|
|
1132 (while
|
|
1133 (and (= (forward-line 1) 0)
|
|
1134 ;; Search forward for then.
|
|
1135 (or (looking-at " [^ 0\n]")
|
|
1136 (looking-at "\t[1-9]"))
|
|
1137 (not
|
|
1138 (setq then-test
|
|
1139 (looking-at
|
|
1140 ".*then\\b[ \t]*[^ \t(=a-z0-9]")))))
|
|
1141 then-test))
|
|
1142 (setq count (- count 1)))))
|
|
1143 ((looking-at "end[ \t]*if\\b")
|
|
1144 (setq count (+ count 1)))))
|
|
1145
|
|
1146 (and (= count 0)
|
|
1147 ;; All pairs accounted for.
|
|
1148 (point))))))
|
|
1149
|
|
1150 (defun fortran-indent-line ()
|
|
1151 "Indents current Fortran line based on its contents and on previous lines."
|
|
1152 (interactive)
|
|
1153 (let ((cfi (calculate-fortran-indent)))
|
|
1154 (save-excursion
|
|
1155 (beginning-of-line)
|
|
1156 (if (or (not (= cfi (fortran-current-line-indentation)))
|
|
1157 (and (re-search-forward "^[ \t]*[0-9]+" (+ (point) 4) t)
|
|
1158 (not (fortran-line-number-indented-correctly-p))))
|
|
1159 (fortran-indent-to-column cfi)
|
|
1160 (beginning-of-line)
|
|
1161 (if (and (not (looking-at comment-line-start-skip))
|
|
1162 (fortran-find-comment-start-skip))
|
|
1163 (fortran-indent-comment))))
|
|
1164 ;; Never leave point in left margin.
|
|
1165 (if (< (current-column) cfi)
|
|
1166 (move-to-column cfi))
|
|
1167 (if (and auto-fill-function
|
|
1168 (> (save-excursion (end-of-line) (current-column)) fill-column))
|
|
1169 (save-excursion
|
|
1170 (end-of-line)
|
|
1171 (fortran-fill)))
|
|
1172 (if fortran-blink-matching-if
|
|
1173 (progn
|
|
1174 (fortran-blink-matching-if)
|
|
1175 (fortran-blink-matching-do)))))
|
|
1176
|
|
1177 (defun fortran-indent-new-line ()
|
|
1178 "Reindent the current Fortran line, insert a newline and indent the newline.
|
|
1179 An abbrev before point is expanded if `abbrev-mode' is non-nil."
|
|
1180 (interactive)
|
|
1181 (if abbrev-mode (expand-abbrev))
|
|
1182 (save-excursion
|
|
1183 (beginning-of-line)
|
|
1184 (skip-chars-forward " \t")
|
|
1185 (if (or (looking-at "[0-9]") ;Reindent only where it is most
|
|
1186 (looking-at "end") ;likely to be necessary
|
|
1187 (looking-at "else")
|
|
1188 (looking-at (regexp-quote fortran-continuation-string)))
|
|
1189 (fortran-indent-line)))
|
|
1190 (newline)
|
|
1191 (fortran-indent-line))
|
|
1192
|
|
1193 (defun fortran-indent-subprogram ()
|
|
1194 "Properly indents the Fortran subprogram which contains point."
|
|
1195 (interactive)
|
|
1196 (save-excursion
|
|
1197 (mark-fortran-subprogram)
|
|
1198 (message "Indenting subprogram...")
|
|
1199 (indent-region (point) (mark t) nil)) ; XEmacs change
|
|
1200 (message "Indenting subprogram...done."))
|
|
1201
|
|
1202 (defun calculate-fortran-indent ()
|
|
1203 "Calculates the Fortran indent column based on previous lines."
|
|
1204 (let (icol first-statement (case-fold-search t)
|
|
1205 (fortran-minimum-statement-indent
|
|
1206 (if indent-tabs-mode
|
|
1207 fortran-minimum-statement-indent-tab
|
|
1208 fortran-minimum-statement-indent-fixed)))
|
|
1209 (save-excursion
|
|
1210 (setq first-statement (fortran-previous-statement))
|
|
1211 (if first-statement
|
|
1212 (setq icol fortran-minimum-statement-indent)
|
|
1213 (progn
|
|
1214 (if (= (point) (point-min))
|
|
1215 (setq icol fortran-minimum-statement-indent)
|
|
1216 (setq icol (fortran-current-line-indentation)))
|
|
1217 (skip-chars-forward " \t0-9")
|
|
1218 (cond ((looking-at "if[ \t]*(")
|
|
1219 (if (or (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t_$(=a-z0-9]")
|
|
1220 (let (then-test) ;multi-line if-then
|
|
1221 (while (and (= (forward-line 1) 0)
|
|
1222 ;;search forward for then
|
|
1223 (or (looking-at " [^ 0\n]")
|
|
1224 (looking-at "\t[1-9]"))
|
|
1225 (not (setq then-test (looking-at
|
|
1226 ".*then\\b[ \t]\
|
|
1227 *[^ \t_$(=a-z0-9]")))))
|
|
1228 then-test))
|
|
1229 (setq icol (+ icol fortran-if-indent))))
|
|
1230 ((looking-at "\\(else\\|elseif\\)\\b")
|
|
1231 (setq icol (+ icol fortran-if-indent)))
|
|
1232 ((looking-at "select[ \t]*case[ \t](.*)\\b")
|
|
1233 (setq icol (+ icol fortran-if-indent)))
|
|
1234 ((looking-at "case[ \t]*(.*)[ \t]*\n")
|
|
1235 (setq icol (+ icol fortran-if-indent)))
|
|
1236 ((looking-at "case[ \t]*default\\b")
|
|
1237 (setq icol (+ icol fortran-if-indent)))
|
|
1238 ((looking-at "\\(otherwise\\|else[ \t]*where\\)\\b")
|
|
1239 (setq icol (+ icol fortran-if-indent)))
|
|
1240 ((looking-at "where[ \t]*(.*)[ \t]*\n")
|
|
1241 (setq icol (+ icol fortran-if-indent)))
|
|
1242 ((looking-at "do\\b")
|
|
1243 (setq icol (+ icol fortran-do-indent)))
|
|
1244 ((looking-at
|
|
1245 "\\(structure\\|union\\|map\\|interface\\)\\b[ \t]*[^ \t=(a-z]")
|
|
1246 (setq icol (+ icol fortran-structure-indent)))
|
|
1247 ((looking-at "end\\b[ \t]*[^ \t=(a-z]")
|
|
1248 ;; Previous END resets indent to minimum
|
|
1249 (setq icol fortran-minimum-statement-indent))))))
|
|
1250 (save-excursion
|
|
1251 (beginning-of-line)
|
|
1252 (cond ((looking-at "[ \t]*$"))
|
|
1253 ((looking-at comment-line-start-skip)
|
|
1254 (cond ((eq fortran-comment-indent-style 'relative)
|
|
1255 (setq icol (+ icol fortran-comment-line-extra-indent)))
|
|
1256 ((eq fortran-comment-indent-style 'fixed)
|
|
1257 (setq icol (+ fortran-minimum-statement-indent
|
|
1258 fortran-comment-line-extra-indent))))
|
|
1259 (setq fortran-minimum-statement-indent 0))
|
|
1260 ((or (looking-at (concat "[ \t]*"
|
|
1261 (regexp-quote
|
|
1262 fortran-continuation-string)))
|
|
1263 (looking-at " [^ 0\n]")
|
|
1264 (looking-at "\t[1-9]"))
|
|
1265 (setq icol (+ icol fortran-continuation-indent)))
|
|
1266 ((looking-at "[ \t]*#") ; Check for cpp directive.
|
|
1267 (setq fortran-minimum-statement-indent 0 icol 0))
|
|
1268 (first-statement)
|
|
1269 ((and fortran-check-all-num-for-matching-do
|
|
1270 (looking-at "[ \t]*[0-9]+")
|
|
1271 (fortran-check-for-matching-do))
|
|
1272 (setq icol (- icol fortran-do-indent)))
|
|
1273 (t
|
|
1274 (skip-chars-forward " \t0-9")
|
|
1275 (cond ((looking-at "end[ \t]*if\\b")
|
|
1276 (setq icol (- icol fortran-if-indent)))
|
|
1277 ((looking-at "\\(else\\|elseif\\)\\b")
|
|
1278 (setq icol (- icol fortran-if-indent)))
|
|
1279 ((looking-at "case[ \t]*(.*)[ \t]*\n")
|
|
1280 (setq icol (- icol fortran-if-indent)))
|
|
1281 ((looking-at "case[ \t]*default\\b")
|
|
1282 (setq icol (- icol fortran-if-indent)))
|
|
1283 ((looking-at "\\(otherwise\\|else[ \t]*where\\)\\b")
|
|
1284 (setq icol (- icol fortran-if-indent)))
|
|
1285 ((looking-at "end[ \t]*where\\b")
|
|
1286 (setq icol (- icol fortran-if-indent)))
|
|
1287 ((and (looking-at "continue\\b")
|
|
1288 (fortran-check-for-matching-do))
|
|
1289 (setq icol (- icol fortran-do-indent)))
|
|
1290 ((looking-at "end[ \t]*do\\b")
|
|
1291 (setq icol (- icol fortran-do-indent)))
|
|
1292 ((looking-at
|
|
1293 "end[ \t]*\
|
|
1294 \\(structure\\|union\\|map\\|interface\\)\\b[ \t]*[^ \t=(a-z]")
|
|
1295 (setq icol (- icol fortran-structure-indent)))
|
|
1296 ((looking-at
|
|
1297 "end[ \t]*select\\b[ \t]*[^ \t=(a-z]")
|
|
1298 (setq icol (- icol fortran-if-indent)))
|
|
1299 ((and (looking-at "end\\b[ \t]*[^ \t=(a-z]")
|
|
1300 (not (= icol fortran-minimum-statement-indent)))
|
|
1301 (message "Warning: `end' not in column %d. Probably\
|
|
1302 an unclosed block." fortran-minimum-statement-indent))))))
|
|
1303 (max fortran-minimum-statement-indent icol)))
|
|
1304
|
|
1305 (defun fortran-current-line-indentation ()
|
|
1306 "Indentation of current line, ignoring Fortran line number or continuation.
|
|
1307 This is the column position of the first non-whitespace character
|
|
1308 aside from the line number and/or column 5/8 line-continuation character.
|
|
1309 For comment lines, returns indentation of the first
|
|
1310 non-indentation text within the comment."
|
|
1311 (save-excursion
|
|
1312 (beginning-of-line)
|
|
1313 (cond ((looking-at comment-line-start-skip)
|
|
1314 (goto-char (match-end 0))
|
|
1315 (skip-chars-forward
|
|
1316 (if (stringp fortran-comment-indent-char)
|
|
1317 fortran-comment-indent-char
|
|
1318 (char-to-string fortran-comment-indent-char))))
|
|
1319 ((or (looking-at " [^ 0\n]")
|
|
1320 (looking-at "\t[1-9]"))
|
|
1321 (goto-char (match-end 0)))
|
|
1322 (t
|
|
1323 ;; Move past line number.
|
|
1324 (skip-chars-forward "[ \t0-9]");From Uli
|
|
1325 ))
|
|
1326 ;; Move past whitespace.
|
|
1327 (skip-chars-forward " \t")
|
|
1328 (current-column)))
|
|
1329
|
|
1330 (defun fortran-indent-to-column (col)
|
|
1331 "Indents current line with spaces to column COL.
|
|
1332 notes: 1) A non-zero/non-blank character in column 5 indicates a continuation
|
|
1333 line, and this continuation character is retained on indentation;
|
|
1334 2) If `fortran-continuation-string' is the first non-whitespace
|
|
1335 character, this is a continuation line;
|
|
1336 3) A non-continuation line which has a number as the first
|
|
1337 non-whitespace character is a numbered line.
|
|
1338 4) A TAB followed by a digit indicates a continuation line."
|
|
1339 (save-excursion
|
|
1340 (beginning-of-line)
|
|
1341 (if (looking-at comment-line-start-skip)
|
|
1342 (if fortran-comment-indent-style
|
|
1343 (let ((char (if (stringp fortran-comment-indent-char)
|
|
1344 (aref fortran-comment-indent-char 0)
|
|
1345 fortran-comment-indent-char)))
|
|
1346 (goto-char (match-end 0))
|
|
1347 (delete-horizontal-regexp (concat " \t" (char-to-string char)))
|
|
1348 (insert-char char (- col (current-column)))))
|
|
1349 (if (looking-at "\t[1-9]")
|
|
1350 (if indent-tabs-mode
|
|
1351 (goto-char (match-end 0))
|
|
1352 (delete-char 2)
|
|
1353 (insert " ")
|
|
1354 (insert fortran-continuation-string))
|
|
1355 (if (looking-at " [^ 0\n]")
|
|
1356 (if indent-tabs-mode
|
|
1357 (progn (delete-char 6)
|
|
1358 (insert "\t")
|
|
1359 (insert-char (fortran-numerical-continuation-char) 1))
|
|
1360 (forward-char 6))
|
|
1361 (delete-horizontal-space)
|
|
1362 ;; Put line number in columns 0-4
|
|
1363 ;; or put continuation character in column 5.
|
|
1364 (cond ((eobp))
|
|
1365 ((looking-at (regexp-quote fortran-continuation-string))
|
|
1366 (if indent-tabs-mode
|
|
1367 (progn
|
|
1368 (indent-to
|
|
1369 (if indent-tabs-mode
|
|
1370 fortran-minimum-statement-indent-tab
|
|
1371 fortran-minimum-statement-indent-fixed))
|
|
1372 (delete-char 1)
|
|
1373 (insert-char (fortran-numerical-continuation-char) 1))
|
|
1374 (indent-to 5)
|
|
1375 (forward-char 1)))
|
|
1376 ((looking-at "[0-9]+")
|
|
1377 (let ((extra-space (- 5 (- (match-end 0) (point)))))
|
|
1378 (if (< extra-space 0)
|
|
1379 (message "Warning: line number exceeds 5-digit limit.")
|
|
1380 (indent-to (min fortran-line-number-indent extra-space))))
|
|
1381 (skip-chars-forward "0-9")))))
|
|
1382 ;; Point is now after any continuation character or line number.
|
|
1383 ;; Put body of statement where specified.
|
|
1384 (delete-horizontal-space)
|
|
1385 (indent-to col)
|
|
1386 ;; Indent any comment following code on the same line.
|
|
1387 (if (and comment-start-skip
|
|
1388 (fortran-find-comment-start-skip))
|
|
1389 (progn (goto-char (match-beginning 0))
|
|
1390 (if (not (= (current-column) (fortran-comment-hook)))
|
|
1391 (progn (delete-horizontal-space)
|
|
1392 (indent-to (fortran-comment-hook)))))))))
|
|
1393
|
|
1394 (defun fortran-line-number-indented-correctly-p ()
|
|
1395 "Return t if current line's line number is correctly indented.
|
|
1396 Do not call if there is no line number."
|
|
1397 (save-excursion
|
|
1398 (beginning-of-line)
|
|
1399 (skip-chars-forward " \t")
|
|
1400 (and (<= (current-column) fortran-line-number-indent)
|
|
1401 (or (= (current-column) fortran-line-number-indent)
|
|
1402 (progn (skip-chars-forward "0-9")
|
|
1403 (= (current-column) 5))))))
|
|
1404
|
|
1405 (defun fortran-check-for-matching-do ()
|
|
1406 "When called from a numbered statement, returns t if matching DO is found.
|
|
1407 Otherwise return a nil."
|
|
1408 (let (charnum
|
|
1409 (case-fold-search t))
|
|
1410 (save-excursion
|
|
1411 (beginning-of-line)
|
|
1412 (if (looking-at "[ \t]*[0-9]+")
|
|
1413 (progn
|
|
1414 (skip-chars-forward " \t")
|
|
1415 (skip-chars-forward "0") ;skip past leading zeros
|
|
1416 (setq charnum (buffer-substring (point)
|
|
1417 (progn (skip-chars-forward "0-9")
|
|
1418 (point))))
|
|
1419 (beginning-of-line)
|
|
1420 (and (re-search-backward
|
|
1421 (concat "\\(^[ \t0-9]*end\\b[ \t]*[^ \t=(a-z]\\)\\|"
|
|
1422 "\\(^[ \t0-9]*do[ \t]*0*" charnum "\\b\\)\\|"
|
|
1423 "\\(^[ \t]*0*" charnum "\\b\\)")
|
|
1424 nil t)
|
|
1425 (looking-at (concat "^[ \t0-9]*do[ \t]*0*" charnum))))))))
|
|
1426
|
|
1427 (defun fortran-find-comment-start-skip ()
|
|
1428 "Move to past `comment-start-skip' found on current line.
|
|
1429 Return t if `comment-start-skip' found, nil if not."
|
|
1430 ;;; In order to move point only if comment-start-skip is found,
|
|
1431 ;;; this one uses a lot of save-excursions. Note that re-search-forward
|
|
1432 ;;; moves point even if comment-start-skip is inside a string-constant.
|
|
1433 ;;; Some code expects certain values for match-beginning and end
|
|
1434 (interactive)
|
|
1435 (if (save-excursion
|
|
1436 (re-search-forward comment-start-skip
|
|
1437 (save-excursion (end-of-line) (point)) t))
|
|
1438 (let ((save-match-beginning (match-beginning 0))
|
|
1439 (save-match-end (match-end 0)))
|
|
1440 (if (fortran-is-in-string-p (match-beginning 0))
|
|
1441 (save-excursion
|
|
1442 (goto-char save-match-end)
|
|
1443 (fortran-find-comment-start-skip)) ; recurse for rest of line
|
|
1444 (goto-char save-match-beginning)
|
|
1445 (re-search-forward comment-start-skip
|
|
1446 (save-excursion (end-of-line) (point)) t)
|
|
1447 (goto-char (match-end 0))
|
|
1448 t))
|
|
1449 nil))
|
|
1450
|
|
1451 ;;;From: simon@gnu (Simon Marshall)
|
|
1452 ;;; Find the next ! not in a string.
|
|
1453 (defun fortran-match-!-comment (limit)
|
|
1454 (let (found)
|
|
1455 (while (and (setq found (search-forward "!" limit t))
|
|
1456 (fortran-is-in-string-p (point))))
|
|
1457 (if (not found)
|
|
1458 nil
|
|
1459 ;; Cheaper than `looking-at' "!.*".
|
|
1460 (store-match-data
|
|
1461 (list (1- (point)) (progn (end-of-line) (min (point) limit))))
|
|
1462 t)))
|
|
1463
|
|
1464 ;; The above function is about 10% faster than the below...
|
|
1465 ;;(defun fortran-match-!-comment (limit)
|
|
1466 ;; (let (found)
|
|
1467 ;; (while (and (setq found (re-search-forward "!.*" limit t))
|
|
1468 ;; (fortran-is-in-string-p (match-beginning 0))))
|
|
1469 ;; found))
|
|
1470
|
|
1471 ;;;From: ralf@up3aud1.gwdg.de (Ralf Fassel)
|
|
1472 ;;; Test if TAB format continuation lines work.
|
|
1473 (defun fortran-is-in-string-p (where)
|
|
1474 "Return non-nil if POS (a buffer position) is inside a Fortran string,
|
|
1475 nil else."
|
|
1476 (save-excursion
|
|
1477 (goto-char where)
|
|
1478 (cond
|
|
1479 ((bolp) nil) ; bol is never inside a string
|
|
1480 ((save-excursion ; comment lines too
|
|
1481 (beginning-of-line)(looking-at comment-line-start-skip)) nil)
|
|
1482 (t (let (;; ok, serious now. Init some local vars:
|
|
1483 (parse-state '(0 nil nil nil nil nil 0))
|
|
1484 (quoted-comment-start (if comment-start
|
|
1485 (regexp-quote comment-start)))
|
|
1486 (not-done t)
|
|
1487 parse-limit
|
|
1488 end-of-line
|
|
1489 )
|
|
1490 ;; move to start of current statement
|
|
1491 (fortran-next-statement)
|
|
1492 (fortran-previous-statement)
|
|
1493 ;; now parse up to WHERE
|
|
1494 (while not-done
|
|
1495 (if (or ;; skip to next line if:
|
|
1496 ;; - comment line?
|
|
1497 (looking-at comment-line-start-skip)
|
|
1498 ;; - at end of line?
|
|
1499 (eolp)
|
|
1500 ;; - not in a string and after comment-start?
|
|
1501 (and (not (nth 3 parse-state))
|
|
1502 comment-start
|
|
1503 (equal comment-start
|
|
1504 (char-to-string (preceding-char)))))
|
|
1505 ;; get around a bug in forward-line in versions <= 18.57
|
|
1506 (if (or (> (forward-line 1) 0) (eobp))
|
|
1507 (setq not-done nil))
|
|
1508 ;; else:
|
|
1509 ;; if we are at beginning of code line, skip any
|
|
1510 ;; whitespace, labels and tab continuation markers.
|
|
1511 (if (bolp) (skip-chars-forward " \t0-9"))
|
|
1512 ;; if we are in column <= 5 now, check for continuation char
|
|
1513 (cond ((= 5 (current-column)) (forward-char 1))
|
|
1514 ((and (< (current-column) 5)
|
|
1515 (equal fortran-continuation-string
|
|
1516 (char-to-string (following-char)))
|
|
1517 (forward-char 1))))
|
|
1518 ;; find out parse-limit from here
|
|
1519 (setq end-of-line (save-excursion (end-of-line)(point)))
|
|
1520 (setq parse-limit (min where end-of-line))
|
|
1521 ;; parse max up to comment-start, if non-nil and in current line
|
|
1522 (if comment-start
|
|
1523 (save-excursion
|
|
1524 (if (re-search-forward quoted-comment-start end-of-line t)
|
|
1525 (setq parse-limit (min (point) parse-limit)))))
|
|
1526 ;; now parse if still in limits
|
|
1527 (if (< (point) where)
|
|
1528 (setq parse-state (parse-partial-sexp
|
|
1529 (point) parse-limit nil nil parse-state))
|
|
1530 (setq not-done nil))
|
|
1531 ))
|
|
1532 ;; result is
|
|
1533 (nth 3 parse-state))))))
|
|
1534
|
|
1535 (defun fortran-auto-fill-mode (arg)
|
|
1536 "Toggle fortran-auto-fill mode.
|
|
1537 With ARG, turn `fortran-auto-fill' mode on iff ARG is positive.
|
|
1538 In `fortran-auto-fill' mode, inserting a space at a column beyond `fill-column'
|
|
1539 automatically breaks the line at a previous space."
|
|
1540 (interactive "P")
|
|
1541 (prog1 (setq auto-fill-function
|
|
1542 (if (if (null arg)
|
|
1543 (not auto-fill-function)
|
|
1544 (> (prefix-numeric-value arg) 0))
|
|
1545 'fortran-do-auto-fill
|
|
1546 nil))
|
2
|
1547 (redraw-modeline)))
|
0
|
1548
|
|
1549 (defun fortran-do-auto-fill ()
|
|
1550 (if (> (current-column) fill-column)
|
|
1551 (fortran-indent-line)))
|
|
1552
|
|
1553 (defun fortran-fill ()
|
|
1554 (interactive)
|
|
1555 (let* ((opoint (point))
|
|
1556 (bol (save-excursion (beginning-of-line) (point)))
|
|
1557 (eol (save-excursion (end-of-line) (point)))
|
|
1558 (bos (min eol (+ bol (fortran-current-line-indentation))))
|
|
1559 (quote
|
|
1560 (save-excursion
|
|
1561 (goto-char bol)
|
|
1562 (if (looking-at comment-line-start-skip)
|
|
1563 nil ; OK to break quotes on comment lines.
|
|
1564 (move-to-column fill-column)
|
|
1565 (cond ((fortran-is-in-string-p (point))
|
|
1566 (save-excursion (re-search-backward "[^']'[^']" bol t)
|
|
1567 (if fortran-break-before-delimiters
|
|
1568 (point)
|
|
1569 (1+ (point)))))
|
|
1570 (t nil)))))
|
|
1571 ;;
|
|
1572 ;; decide where to split the line. If a position for a quoted
|
|
1573 ;; string was found above then use that, else break the line
|
|
1574 ;; before the last delimiter.
|
|
1575 ;; Delimiters are whitespace, commas, and operators.
|
|
1576 ;; Will break before a pair of *'s.
|
|
1577 ;;
|
|
1578 (fill-point
|
|
1579 (or quote
|
|
1580 (save-excursion
|
|
1581 (move-to-column (1+ fill-column))
|
|
1582 (skip-chars-backward "^ \t\n,'+-/*=)"
|
|
1583 ;;; (if fortran-break-before-delimiters
|
|
1584 ;;; "^ \t\n,'+-/*=" "^ \t\n,'+-/*=)")
|
|
1585 )
|
|
1586 (if (<= (point) (1+ bos))
|
|
1587 (progn
|
|
1588 (move-to-column (1+ fill-column))
|
|
1589 ;;;what is this doing???
|
|
1590 (if (not (re-search-forward "[\t\n,'+-/*)=]" eol t))
|
|
1591 (goto-char bol))))
|
|
1592 (if (bolp)
|
|
1593 (re-search-forward "[ \t]" opoint t)
|
|
1594 (forward-char -1)
|
|
1595 (if (looking-at "'")
|
|
1596 (forward-char 1)
|
|
1597 (skip-chars-backward " \t\*")))
|
|
1598 (if fortran-break-before-delimiters
|
|
1599 (point)
|
|
1600 (1+ (point))))))
|
|
1601 )
|
|
1602 ;; if we are in an in-line comment, don't break unless the
|
|
1603 ;; line of code is longer than it should be. Otherwise
|
|
1604 ;; break the line at the column computed above.
|
|
1605 ;;
|
|
1606 ;; Need to use fortran-find-comment-start-skip to make sure that quoted !'s
|
|
1607 ;; don't prevent a break.
|
|
1608 (if (not (or (save-excursion
|
|
1609 (if (and (re-search-backward comment-start-skip bol t)
|
|
1610 (not (fortran-is-in-string-p (point))))
|
|
1611 (progn
|
|
1612 (skip-chars-backward " \t")
|
|
1613 (< (current-column) (1+ fill-column)))))
|
|
1614 (save-excursion
|
|
1615 (goto-char fill-point)
|
|
1616 (bolp))))
|
|
1617 (if (> (save-excursion
|
|
1618 (goto-char fill-point) (current-column))
|
|
1619 (1+ fill-column))
|
|
1620 (progn (goto-char fill-point)
|
|
1621 (fortran-break-line))
|
|
1622 (save-excursion
|
|
1623 (if (> (save-excursion
|
|
1624 (goto-char fill-point)
|
|
1625 (current-column))
|
|
1626 (+ (calculate-fortran-indent) fortran-continuation-indent))
|
|
1627 (progn
|
|
1628 (goto-char fill-point)
|
|
1629 (fortran-break-line))))))
|
|
1630 ))
|
|
1631 (defun fortran-break-line ()
|
|
1632 (let ((opoint (point))
|
|
1633 (bol (save-excursion (beginning-of-line) (point)))
|
|
1634 (eol (save-excursion (end-of-line) (point)))
|
|
1635 (comment-string nil))
|
|
1636
|
|
1637 (save-excursion
|
|
1638 (if (and comment-start-skip (fortran-find-comment-start-skip))
|
|
1639 (progn
|
|
1640 (re-search-backward comment-start-skip bol t)
|
|
1641 (setq comment-string (buffer-substring (point) eol))
|
|
1642 (delete-region (point) eol))))
|
|
1643 ;;; Forward line 1 really needs to go to next non white line
|
|
1644 (if (save-excursion (forward-line 1)
|
|
1645 (or (looking-at " [^ 0\n]")
|
|
1646 (looking-at "\t[1-9]")))
|
|
1647 (progn
|
|
1648 (end-of-line)
|
|
1649 (delete-region (point) (match-end 0))
|
|
1650 (delete-horizontal-space)
|
|
1651 (fortran-fill))
|
|
1652 (fortran-split-line))
|
|
1653 (if comment-string
|
|
1654 (save-excursion
|
|
1655 (goto-char bol)
|
|
1656 (end-of-line)
|
|
1657 (delete-horizontal-space)
|
|
1658 (indent-to (fortran-comment-hook))
|
|
1659 (insert comment-string)))))
|
|
1660
|
|
1661 (defun fortran-analyze-file-format ()
|
|
1662 "Returns nil if fixed format is used, t if TAB formatting is used.
|
|
1663 Use `fortran-tab-mode-default' if no non-comment statements are found in the
|
|
1664 file before the end or the first `fortran-analyze-depth' lines."
|
|
1665 (let ((i 0))
|
|
1666 (save-excursion
|
|
1667 (goto-char (point-min))
|
|
1668 (setq i 0)
|
|
1669 (while (not (or
|
|
1670 (eobp)
|
|
1671 (looking-at "\t")
|
|
1672 (looking-at " ")
|
|
1673 (> i fortran-analyze-depth)))
|
|
1674 (forward-line)
|
|
1675 (setq i (1+ i)))
|
|
1676 (cond
|
|
1677 ((looking-at "\t") t)
|
|
1678 ((looking-at " ") nil)
|
|
1679 (fortran-tab-mode-default t)
|
|
1680 (t nil)))))
|
|
1681
|
|
1682 (or (assq 'fortran-tab-mode-string minor-mode-alist)
|
|
1683 (setq minor-mode-alist (cons
|
|
1684 '(fortran-tab-mode-string
|
|
1685 (indent-tabs-mode fortran-tab-mode-string))
|
|
1686 minor-mode-alist)))
|
|
1687
|
|
1688 (provide 'fortran)
|
|
1689
|
|
1690 ;;; fortran.el ends here
|