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