Mercurial > emacs
annotate lisp/progmodes/f90.el @ 10698:9dc3f4fc6b7f
Talk about auto save.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 08 Feb 1995 06:29:29 +0000 |
parents | ce2d2fe2fa79 |
children | bb8df7aad5ef |
rev | line source |
---|---|
10613 | 1 ;; f90.el --- Fortran-90 mode (free format) for GNU Emacs. |
10612 | 2 ;; Copyright (C) 1995 Free Software Foundation, Inc. |
3 | |
4 ;; Author: Torbj\"orn Einarsson <tfkte@fy.chalmers.se> | |
5 ;; Created: Jan 21, 1995 | |
6 ;; Keywords: fortran, f90, languages | |
7 | |
8 ;; This program is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
10 ;; the Free Software Foundation; either version 2 of the License, or | |
11 ;; (at your option) any later version. | |
12 | |
13 ;; This program is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with this program; if not, write to the Free Software | |
20 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | |
22 ;;; Commentary: | |
23 ;; Smart mode for editing F90 programs in FREE FORMAT. | |
24 ;; Knows about continuation lines, named structured statements, and other | |
25 ;; new features in F90 including HPF (High Performance Fortran) structures. | |
26 ;; The basic feature is to provide an accurate indentation of F90 programs. | |
27 ;; In addition, there are many more features like automatic matching of all | |
28 ;; end statements, an auto-fill function to break long lines, a join-lines | |
29 ;; function which joins continued lines etc etc. | |
30 ;; To facilitate typing, a fairly complete list of abbreviations is provided. | |
31 ;; For example, `i is short-hand for integer (if abbrev-mode is on). | |
32 | |
33 ;; There are two separate features for highlighting the code. | |
34 ;; 1) Upcasing or capitalizing of all keywords. | |
35 ;; 2) Different colors/fonts for different structures. (X-windows) | |
36 ;; (using either font-lock-mode or hilit19) | |
37 ;; Automatic upcase of downcase of keywords is controlled by the parameter | |
38 ;; f90-auto-keyword-case. | |
39 ;; To use hilit19 it must be loaded before this file. Then the parameter | |
40 ;; f90-auto-hilit19 determines if each line should be updated automatically. | |
41 | |
42 ;; The indentations of lines starting with ! is determined by the first of the | |
43 ;; following matches: | |
44 ;; start-string indent variable holding start-string | |
45 ;; !!! 0 | |
46 ;; !hpf$ 0 f90-directive-comment (default nil) | |
47 ;; !!$ 0 f90-comment-region (default !!$) | |
48 ;; ! as code f90-indented-comment (a regexp, default !) | |
49 ;; default comment-column | |
50 ;; Ex: Here is the result of three different settings of f90-indented-comment | |
51 ;; f90-indented-comment !-indentation !!-indentation | |
52 ;; ! as code as code | |
53 ;; !! comment-column as code | |
54 ;; ![^!] as code comment-column | |
55 ;; Trailing comments are indented to comment-column with indent-for-comment M-; | |
56 ;; f90-comment-region (C-c;) toggles insertion of f90-comment-region in region. | |
57 | |
58 ;; One common convention for free vs. fixed format is that free-format files | |
59 ;; have the ending .f90 while the fixed format files have the ending .f. | |
60 ;; To make f90-mode work, put this file in, for example, your directory | |
61 ;; ~/lisp, and be sure that you have the following in your .emacs-file | |
62 ;; (setq load-path (append load-path '("~/lisp"))) | |
63 ;; (autoload 'f90-mode "f90" | |
64 ;; "Major mode for editing Fortran 90 code in free format." t) | |
65 ;; (setq auto-mode-alist (append auto-mode-alist | |
66 ;; (list '("\\.f90$" . f90-mode)))) | |
67 ;; Once you have entered f90-mode, you may get more info by using | |
68 ;; the command describe-mode (C-h m). For online help describing various | |
69 ;; functions use C-h f <Name of function you want described> | |
70 | |
71 ;; To customize the f90-mode for your taste, use, for example: | |
72 ;; (you don't have to specify values for all the parameters below) | |
73 ;;(setq f90-mode-hook | |
74 ;; '(lambda () (setq f90-do-indent 3 | |
75 ;; f90-if-indent 3 | |
76 ;; f90-type-indent 3 | |
77 ;; f90-program-indent 2 | |
78 ;; f90-continuation-indent 5 | |
79 ;; f90-comment-region "!!$" | |
80 ;; f90-directive-comment nil | |
81 ;; f90-indented-comment "!" | |
82 ;; f90-break-delimiters "[-+\\*/,><=% \t]" | |
83 ;; f90-break-before-delimiters t | |
84 ;; f90-beginning-ampersand t | |
85 ;; f90-smart-end 'blink | |
86 ;; f90-auto-keyword-case nil | |
87 ;; f90-auto-hilit19 t | |
88 ;; f90-leave-line-no nil | |
89 ;; f90-startup-message t) | |
90 ;; ;;The rest is not default. | |
91 ;; (abbrev-mode 1) ; turn on abbreviation mode | |
92 ;; (f90-auto-fill-mode 1) ; turn on auto-filling | |
93 ;; (if f90-auto-keyword-case ; change case of all keywords on startup | |
94 ;; (f90-change-keywords f90-auto-keyword-case)) | |
95 ;; )) | |
96 ;; in your .emacs file (the shown values are the defaults). You can also | |
97 ;; change the values of the lists f90-keywords etc. | |
98 ;; The auto-fill and abbreviation minor modes are accessible from the menu, | |
99 ;; or by using M-x f90-auto-fill-mode and M-x abbrev-mode, respectively. | |
100 | |
101 ;; Remarks | |
102 ;; 1) Line numbers are by default left-justified. If f90-leave-line-no is | |
103 ;; non-nil, the line numbers are never touched. | |
104 ;; 2) Multi-; statements like > do i=1,20 ; j=j+i ; end do < are not handled | |
105 ;; correctly, but I imagine them to be rare. | |
106 ;; 3) You can use either hilit19 or font-lock-mode for your highlighting | |
107 ;; a) To use hilit19, be sure that hilit19 is loaded before this file | |
108 ;; b) To use font-lock-mode, nothing special is needed. | |
109 ;; 4) For FIXED FORMAT code, use the ordinary fortran mode. | |
110 ;; 5) This mode does not work under emacs-18.x. | |
111 | |
112 ;; List of user commands | |
113 ;; f90-previous-statement f90-next-statement | |
114 ;; f90-beginning-of-subprogram f90-end-of-subprogram f90-mark-subprogram | |
115 ;; f90-comment-region | |
116 ;; f90-indent-line f90-indent-new-line | |
117 ;; f90-indent-region (can be called by calling indent-region) | |
118 ;; f90-indent-subprogram | |
119 ;; f90-break-line f90-join-lines | |
120 ;; f90-auto-fill-mode | |
121 ;; f90-fill-region | |
122 ;; f90-insert-end | |
123 ;; f90-upcase-keywords f90-upcase-region-keywords | |
124 ;; f90-downcase-keywords f90-downcase-region-keywords | |
125 ;; f90-capitalize-keywords f90-capitalize-region-keywords | |
126 | |
127 ;; Thanks to all the people who have tested the mode. Special thanks to Jens | |
128 ;; Bloch Helmers for encouraging me to write this code, for creative | |
129 ;; suggestions as well as for the lists of hpf-commands. | |
130 ;; Also thanks to the authors of the fortran and pascal modes, on which some | |
131 ;; of this code is built. | |
132 | |
133 ;;; Code: | |
134 (defconst bug-f90-mode "tfkte@fy.chalmers.se" | |
135 "Address of mailing list for F90 mode bugs.") | |
136 | |
137 ;; User options | |
138 (defvar f90-do-indent 3 | |
139 "*Extra indentation applied to DO blocks.") | |
140 | |
141 (defvar f90-if-indent 3 | |
142 "*Extra indentation applied to IF, SELECT CASE, WHERE and FORALL blocks.") | |
143 | |
144 (defvar f90-type-indent 3 | |
145 "*Extra indentation applied to TYPE, INTERFACE and BLOCK DATA blocks.") | |
146 | |
147 (defvar f90-program-indent 2 | |
148 "*Extra indentation applied to PROGRAM/MODULE/SUBROUTINE/FUNCTION blocks.") | |
149 | |
150 (defvar f90-continuation-indent 5 | |
151 "*Extra indentation applied to F90 continuation lines.") | |
152 | |
153 (defvar f90-comment-region "!!$" | |
154 "*String inserted by \\[f90-comment-region]\ | |
155 at start of each line in region.") | |
156 | |
157 (defvar f90-indented-comment "!" | |
158 "*Comments to be indented like code.") | |
159 | |
160 (defvar f90-directive-comment nil | |
161 "*String of comment-like directive like \"!HPF$\", not to be indented.") | |
162 | |
163 (defvar f90-beginning-ampersand t | |
164 "*t makes automatic insertion of \& at beginning of continuation line.") | |
165 | |
166 (defvar f90-smart-end 'blink | |
167 "*From an END statement, check and fill the end using matching block start. | |
168 Allowed values are 'blink, 'no-blink, and nil, which determine | |
169 whether to blink the matching beginning.") | |
170 | |
171 (defvar f90-break-delimiters "[-+\\*/><=,% \t]" | |
172 "*Regexp holding list of delimiters at which lines may be broken.") | |
173 | |
174 (defvar f90-break-before-delimiters t | |
175 "*Non-nil causes `f90-do-auto-fill' to break lines before delimiters.") | |
176 | |
177 (defvar f90-auto-keyword-case nil | |
178 "*Automatic case conversion of keywords. | |
179 The options are 'downcase-word, 'upcase-word, 'capitalize-word and nil") | |
180 | |
181 (defvar f90-auto-hilit19 t | |
182 "*Automatic highlight of line at every indent or newline (for hilit19).") | |
183 | |
184 (defvar f90-leave-line-no nil | |
185 "*If nil, left-justify linenumbers.") | |
186 | |
187 (defvar f90-startup-message t | |
188 "*Non-nil displays a startup message when F90 mode is first called.") | |
189 | |
190 (defvar f90-keywords | |
191 '("allocate" "allocatable" "assign" "assignment" "backspace" "block" | |
192 "call" "case" "character" "close" "common" "complex" "contains" | |
193 "continue" "cycle" "data" "deallocate" "dimension" "do" "double" "else" | |
194 "elseif" "elsewhere" "end" "enddo" "endfile" "endif" "entry" "equivalence" | |
195 "exit" "external" "forall" "format" "function" "goto" "if" "implicit" | |
196 "include" "inquire" "integer" "intent" "interface" "intrinsic" "logical" | |
197 "module" "namelist" "none" "nullify" "open" "optional" "parameter" | |
198 "pause" "pointer" "precision" "print" "private" "procedure" "program" | |
199 "public" "read" "real" "recursive" "return" "rewind" "save" "select" | |
200 "sequence" "stop" "subroutine" "target" "then" "type" "use" "where" | |
201 "while" "write") | |
202 "*List of f90-keywords.") | |
203 | |
204 (defvar f90-intrinsic-procedures | |
205 '("abs" "achar" "acos" "adjustl" "adjustr" "aimag" "aint" "all" "allocated" | |
206 "anint" "any" "asin" "associated" "atan" "atan2" "bit_size" "btest" | |
207 "ceiling" "char" "cmplx" "conjg" "cos" "cosh" "count" "cshift" | |
208 "date_and_time" "dble" "digits" "dim" "dot_product" "dprod" "eoshift" | |
209 "epsilon" "exp" "exponent" "floor" "fraction" "huge" "iachar" "iand" | |
210 "ibclr" "ibits" "ibset" "ichar" "ieor" "index" "int" "ior" "ishft" | |
211 "ishftc" "kind" "lbound" "len" "len_trim" "lge" "lgt" "lle" "llt" "log" | |
212 "logical" "log10" "matmul" "max" "maxexponent" "maxloc" "maxval" "merge" | |
213 "min" "minexponent" "minloc" "minval" "mod" "modulo" "mvbits" "nearest" | |
214 "nint" "not" "pack" "precision" "present" "product" "radix" "random_number" | |
215 "random_seed" "range" "real" "repeat" "reshape" "rrspacing" "scale" | |
216 "scan" "selected_int_kind" "selected_real_kind" "set_exponent" "shape" | |
217 "sign" "sin" "sinh" "size" "spacing" "spread" "sqrt" "sum" | |
218 "system_clock" "tan" "tanh" "tiny" "transfer" "transpose" "trim" | |
219 "ubound" "unpack" "verify") | |
220 "*List of F90 intrinsic procedures.") | |
221 | |
222 (defvar f90-hpf-procedures | |
223 '("all_prefix" "all_scatter" "all_suffix" "any_prefix" "any_scatter" | |
224 "any_suffix" "copy_prefix" "copy_scatter" "copy_suffix" "count_prefix" | |
225 "count_scatter" "count_suffix" "grade_down" "grade_up" "hpf_alignment" | |
226 "hpf_template" "hpf_distribution" "iall" "iall_prefix" "iall_scatter" | |
227 "iall_suffix" "iany" "iany_prefix" "iany_scatter" "iany_suffix" "iparity" | |
228 "iparity_prefix" "iparity_scatter" "iparity_suffix" "leadz" "maxval_prefix" | |
229 "maxval_scatter" "maxval_suffix" "minval_prefix" "minval_scatter" | |
230 "minval_suffix" "parity" "parity_prefix" "parity_scatter" "parity_suffix" | |
231 "popcnt" "poppar" "product_prefix" "product_scatter" "product_suffix" | |
232 "sum_prefix" "sum_scatter" "sum_suffix" "ilen" "number_of_processors" | |
233 "processors_shape") | |
234 "*List of hpf intrinsic procedures.") | |
235 | |
236 (defvar f90-hpf-directives | |
237 '("align" "distribute" "dynamic" "inherit" "template" "processors" | |
238 "realign" "redistribute" "independent") | |
239 "*List of hpf directives.") | |
240 | |
241 (defvar f90-hpf-keywords | |
242 '("pure" "extrinsic" "new" "with" "onto" "block" "cyclic") | |
243 "*List of hpf keywords.") | |
244 | |
245 ;; Highlighting patterns | |
246 | |
247 (defconst f90-font-lock-keywords-1 | |
248 (purecopy | |
249 (list | |
250 ;; Subroutine and function declarations | |
251 '("^[ \t]*\\(program\\|module\\)[ \t]+\\sw+" 1 font-lock-keyword-face) | |
252 '("^[ \t]*\\(program\\|module\\)[ \t]+\\(\\sw+\\)" 2 | |
253 font-lock-function-name-face) | |
254 '("\\(^.*\\(function\\|subroutine\\)\\)[ \t]+\\sw+" 1 | |
255 font-lock-keyword-face) | |
256 '("^.*\\(function\\|subroutine\\)[ \t]+\\(\\sw+\\)" 2 | |
257 font-lock-function-name-face) | |
258 '("^[ \t]*end[ \t]*\\(program\\|module\\|function\\|subroutine\\|type\\)" | |
259 . font-lock-keyword-face) | |
260 (list (concat "^[ \t]*end[ \t]*\\(program\\|module\\|function\\|" | |
261 "subroutine\\|type\\)[ \t]+\\(\\sw+\\)") 2 | |
262 'font-lock-function-name-face) | |
263 '("^[ \t]*\\(type\\)[ \t]+\\sw+" 1 font-lock-keyword-face) | |
264 '("^[ \t]*type[ \t]+\\(\\sw+\\)" 1 font-lock-function-name-face) | |
265 '("^[ \t]*\\(end[ \t]*\\)?interface\\>" . font-lock-keyword-face) | |
266 '("^[ \t]*contains\\>" . font-lock-keyword-face))) | |
267 "For consideration as a value of `f90-font-lock-keywords-1'. | |
268 This does fairly subdued highlighting of comments and function names.") | |
269 | |
270 (defconst f90-font-lock-keywords-2 | |
271 (purecopy | |
272 (append f90-font-lock-keywords-1 | |
273 (list | |
274 ;; Variable declarations | |
275 '("\\(\\(real\\|integer\\|character\\|complex\\|logical\\|type\\).*\\)::" | |
276 1 font-lock-type-face) | |
277 '("implicit[ \t]*none" . font-lock-keyword-face) | |
278 '("^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(do\\([ \t]*while\\)?\\)\\>" | |
279 2 font-lock-keyword-face) | |
280 '("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*\\(do\\([ \t]*while\\)?\\)\\>" 1 | |
281 font-lock-function-name-face) | |
282 '("^[ \t]*\\(end[ \t]*do\\)\\>" 1 font-lock-keyword-face) | |
283 '("^[ \t]*end[ \t]*do[ \t]+\\(\\sw+\\)" 1 font-lock-function-name-face) | |
284 '("^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(if\\)\\>" 2 | |
285 font-lock-keyword-face) | |
286 '("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*if\\>" 1 font-lock-function-name-face) | |
287 '("^[ \t]*\\(end[ \t]*if\\)\\>" 1 font-lock-keyword-face) | |
288 '("^[ \t]*end[ \t]*if[ \t]+\\(\\sw+\\)" 1 font-lock-function-name-face) | |
289 '("^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(select[ \t]*case\\)\\>" 2 | |
290 font-lock-keyword-face) | |
291 '("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*\\(select[ \t]*case\\)\\>" 1 | |
292 font-lock-function-name-face) | |
293 '("^[ \t]*end[ \t]*select\\>" . font-lock-keyword-face) | |
294 '("^[ \t]*end[ \t]*select\\>[ \t]+\\(\\sw+\\)" 1 | |
295 font-lock-function-name-face) | |
296 '("\\(where\\|forall\\)[ \t]*(" 1 font-lock-keyword-face) | |
297 '("\\<\\(elsewhere\\|else\\|else[ \t]*if\\)\\>" . font-lock-keyword-face) | |
298 '("\\<end[ \t]*\\(where\\|forall\\)\\>" . font-lock-keyword-face) | |
299 '("\\<then\\>" . font-lock-keyword-face) | |
300 '("\\<\\(exit\\|cycle\\)\\>" . font-lock-keyword-face) | |
301 '("\\<\\(exit\\|cycle\\)[ \t]*\\(\\sw+\\)\\>" 2 | |
302 font-lock-function-name-face) | |
303 '("\\<\\(stop\\|return\\)\\>" . font-lock-keyword-face) | |
304 '("^[ \t]*\\(case\\)[ \t]*\\((\\|default\\)" 1 font-lock-keyword-face) | |
305 (concat "\\<\\("(mapconcat 'identity f90-keywords "\\|") "\\)\\>") | |
306 (concat "\\<\\("(mapconcat 'identity f90-intrinsic-procedures "\\|") | |
307 "\\)\\>") | |
308 (concat "\\<\\("(mapconcat 'identity f90-hpf-procedures "\\|") | |
309 "\\)\\>") | |
310 (concat "\\<\\("(mapconcat 'identity f90-hpf-directives "\\|") | |
311 "\\)\\>") | |
312 (concat "\\<\\("(mapconcat 'identity f90-hpf-keywords "\\|") | |
313 "\\)\\>")))) | |
314 "For consideration as a value of `f90-font-lock-keywords'. | |
315 This highlights variable types, \"keywords,\" etc.") | |
316 | |
317 (defvar f90-font-lock-keywords f90-font-lock-keywords-2 | |
318 "*Additional expressions to highlight in F90 mode.") | |
319 | |
320 ;; hilit19 customization and expressions | |
321 (defvar f90-face-string 'named-param "*Face for strings.") | |
322 (defvar f90-face-comment 'comment "*Face for comments.") | |
323 (defvar f90-face-decl 'include "*Face for declarations.") | |
324 (defvar f90-face-prog 'defun "*Face for program blocks.") | |
325 (defvar f90-face-label 'Tomato-bold "*Face for labels.") | |
326 (defvar f90-face-type 'defun "*Face for type blocks.") | |
327 (defvar f90-face-interface 'defun "*Face for interface blocks.") | |
328 (defvar f90-face-contains 'defun "*Face for contains statement.") | |
329 (defvar f90-face-do 'SteelBlue-bold "*Face for do-structure.") | |
330 (defvar f90-face-if 'define "*Face for if-structure.") | |
331 (defvar f90-face-select 'define "*Face for select-case structure.") | |
332 (defvar f90-face-stop 'defun "*Face for stop and return.") | |
333 (defvar f90-face-exit 'SteelBlue-bold "*Face for exit and cycle.") | |
334 (defvar f90-face-keyword 'struct "*Face for keywords.") | |
335 (defvar f90-face-intrinsics 'struct "*Face for intrinsic procedures.") | |
336 ;; Highlighting for HPF (High-Peformance Fortran) | |
337 (defvar f90-face-hpf-procedures 'struct "*Face for hpf procedures.") | |
338 (defvar f90-face-hpf-directives 'struct "*Face for hpf directives.") | |
339 (defvar f90-face-hpf-keywords 'struct "*Face for hpf keywords.") | |
340 | |
341 (if (fboundp 'hilit-set-mode-patterns) | |
342 (hilit-set-mode-patterns | |
343 'f90-mode | |
344 (list | |
345 ;; Allow for strings delimited by ' and by " and for multirow strings. | |
346 ;; A multi-row string includes &\n& (+ possible whitespace and comments) | |
347 (list (concat | |
348 "\\(\"[^\"\n]*\\(&[ \t]*\\(![^\n]*\\)?\n[ \t]*&[^\"\n]*\\)*\"" | |
349 "\\|'[^'\n]*\\(&[ \t]*\\(![^\n]*\\)?\n[ \t]*&[^'\n]*\\)*'\\)") | |
350 nil f90-face-string) | |
351 (list "!" "$" f90-face-comment) | |
352 (list "\\(\\(real\\|integer\\|character\\|complex\\|logical\ | |
353 \\|type\\).*\\)::" 1 f90-face-decl) | |
354 (list "implicit[ \t]*none" nil f90-face-decl) | |
355 (list "^[ \t]*\\(program\\|module\\)[ \t]+\\sw+" 1 f90-face-prog) | |
356 (list "^[ \t]*\\(program\\|module\\)[ \t]+\\(\\sw+\\)" 2 f90-face-label) | |
357 (list "\\(^.*\\(function\\|subroutine\\)\\)[ \t]+\\sw+" 1 | |
358 f90-face-prog) | |
359 (list "^.*\\(function\\|subroutine\\)[ \t]+\\(\\sw+\\)" 2 | |
360 f90-face-label) | |
361 (list "^[ \t]*end[ \t]*\\(program\\|module\\|function\ | |
362 \\|subroutine\\|type\\)" nil f90-face-prog) | |
363 (list (concat "^[ \t]*end[ \t]*\\(program\\|module\\|function\\|" | |
364 "subroutine\\|type\\)[ \t]+\\(\\sw+\\)") 2 f90-face-label) | |
365 (list "^[ \t]*\\(type\\)[ \t]+\\sw+" 1 f90-face-type) | |
366 (list "^[ \t]*type[ \t]+\\(\\sw+\\)" 1 f90-face-label) | |
367 (list "^[ \t]*\\(end[ \t]*\\)?interface\\>" nil f90-face-interface) | |
368 (list "^[ \t]*contains\\>" nil f90-face-contains) | |
369 (list "^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(do\\([ \t]*while\\)?\\)\\>" | |
370 2 f90-face-do) | |
371 (list "^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*\\(do\\([ \t]*while\\)?\\)\\>" 1 | |
372 f90-face-label) | |
373 (list "^[ \t]*\\(end[ \t]*do\\)\\>" 1 f90-face-do) | |
374 (list "^[ \t]*end[ \t]*do[ \t]+\\(\\sw+\\)" 1 f90-face-label) | |
375 (list "^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(if\\)\\>" 2 f90-face-if) | |
376 (list "^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*if\\>" 1 f90-face-label) | |
377 (list "^[ \t]*\\(end[ \t]*if\\)\\>" 1 f90-face-if) | |
378 (list "^[ \t]*end[ \t]*if[ \t]+\\(\\sw+\\)" 1 f90-face-label) | |
379 (list "^[ \t]*\\(\\sw+[ \t]*:[ \t]*\\)?\\(select[ \t]*case\\)\\>" 2 | |
380 f90-face-select) | |
381 (list "^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*\\(select[ \t]*case\\)\\>" 1 | |
382 f90-face-label) | |
383 (list "^[ \t]*end[ \t]*select\\>" nil f90-face-select) | |
384 (list "^[ \t]*end[ \t]*select\\>[ \t]+\\(\\sw+\\)" 1 f90-face-label) | |
385 (list "\\(where\\|forall\\)[ \t]*(" 1 f90-face-if) | |
386 (list "\\<\\(elsewhere\\|else\\|else[ \t]*if\\)\\>" nil f90-face-if) | |
387 (list "\\<end[ \t]*\\(where\\|forall\\)\\>" nil f90-face-if) | |
388 (list "\\<then\\>" nil f90-face-if) | |
389 (list "\\<\\(exit\\|cycle\\)\\>" nil f90-face-exit) | |
390 (list "\\<\\(exit\\|cycle\\)[ \t]*\\sw+\\>" nil f90-face-label) | |
391 (list "\\<\\(stop\\|return\\)\\>" nil f90-face-stop) | |
392 (list "^[ \t]*\\(case\\)[ \t]*\\((\\|default\\)" 1 f90-face-select) | |
393 (list (concat "\\<\\("(mapconcat 'identity f90-keywords "\\|") | |
394 "\\)\\>") nil f90-face-keyword) | |
395 (list (concat "\\<\\("(mapconcat 'identity f90-intrinsic-procedures "\\|") | |
396 "\\)\\>") nil f90-face-intrinsics) | |
397 (list (concat "\\<\\("(mapconcat 'identity f90-hpf-procedures "\\|") | |
398 "\\)\\>") nil f90-face-hpf-procedures) | |
399 (list (concat "\\<\\("(mapconcat 'identity f90-hpf-directives "\\|") | |
400 "\\)\\>") nil f90-face-hpf-directives) | |
401 (list (concat "\\<\\("(mapconcat 'identity f90-hpf-keywords "\\|") | |
402 "\\)\\>") nil f90-face-hpf-keywords)) | |
403 nil 'case-insensitive)) | |
404 | |
405 ;; syntax table | |
406 (defvar f90-mode-syntax-table nil | |
407 "Syntax table in use in F90 mode buffers.") | |
408 | |
409 (if f90-mode-syntax-table | |
410 () | |
411 (setq f90-mode-syntax-table (make-syntax-table)) | |
412 (modify-syntax-entry ?\! "<" f90-mode-syntax-table) ; beg. comment | |
413 (modify-syntax-entry ?\n ">" f90-mode-syntax-table) ; end comment | |
414 (modify-syntax-entry ?_ "w" f90-mode-syntax-table) ; underscore in names | |
415 (modify-syntax-entry ?\' "\"" f90-mode-syntax-table) ; string quote | |
416 (modify-syntax-entry ?\" "\"" f90-mode-syntax-table) ; string quote | |
417 (modify-syntax-entry ?\` "w" f90-mode-syntax-table) ; for abbrevs | |
418 (modify-syntax-entry ?\r " " f90-mode-syntax-table) ; return is whitespace | |
419 (modify-syntax-entry ?+ "." f90-mode-syntax-table) | |
420 (modify-syntax-entry ?- "." f90-mode-syntax-table) | |
421 (modify-syntax-entry ?= "." f90-mode-syntax-table) | |
422 (modify-syntax-entry ?* "." f90-mode-syntax-table) | |
423 (modify-syntax-entry ?/ "." f90-mode-syntax-table) | |
424 (modify-syntax-entry ?\\ "/" f90-mode-syntax-table)) ; escape chars | |
425 | |
426 ;; keys | |
427 (defvar f90-mode-map () | |
428 "Keymap used in F90 mode.") | |
429 (if f90-mode-map | |
430 () | |
431 (setq f90-mode-map (make-sparse-keymap)) | |
432 (define-key f90-mode-map "`" 'f90-abbrev-start) | |
433 (define-key f90-mode-map "\C-c;" 'f90-comment-region) | |
434 (define-key f90-mode-map "\C-\M-a" 'f90-beginning-of-subprogram) | |
435 (define-key f90-mode-map "\C-\M-e" 'f90-end-of-subprogram) | |
436 (define-key f90-mode-map "\C-\M-h" 'f90-mark-subprogram) | |
437 (define-key f90-mode-map "\C-\M-q" 'f90-indent-subprogram) | |
438 (define-key f90-mode-map "\C-j" 'f90-indent-new-line) ; LFD equals C-j | |
439 (define-key f90-mode-map "\r" 'newline) | |
440 (define-key f90-mode-map "\C-c\r" 'f90-break-line) | |
441 ;; (define-key f90-mode-map [M-return] 'f90-break-line) | |
442 (define-key f90-mode-map "\C-c\C-d" 'f90-join-lines) | |
443 (define-key f90-mode-map "\C-c\C-f" 'f90-fill-region) | |
444 (define-key f90-mode-map "\C-c\C-p" 'f90-previous-statement) | |
445 (define-key f90-mode-map "\C-c\C-n" 'f90-next-statement) | |
446 (define-key f90-mode-map "\C-c\C-w" 'f90-insert-end) | |
447 (define-key f90-mode-map "\t" 'f90-indent-line)) | |
448 ;; menus | |
449 (if (string-match "Lucid" emacs-version) | |
450 ;; XEmacs | |
451 (progn | |
452 (add-menu nil "F90" | |
453 '( | |
454 ["Indent subprogram" f90-indent-subprogram t] | |
455 ["Mark subprogram" f90-mark-subprogram t] | |
456 ["Beginning of subprogram" f90-beginning-of-subprogram t] | |
457 ["End of subprogram" f90-end-of-subprogram t] | |
458 "-----" | |
459 ["(Un)Comment region" f90-comment-region t] | |
460 ["Indent region" indent-region t] | |
461 ["Fill region" f90-fill-region t] | |
462 "-----" | |
463 ["Break line at point" f90-break-line t] | |
464 ["Join with next line" f90-join-lines t] | |
465 ["Insert newline." newline t] | |
466 ["Insert end." f90-insert-end t] | |
467 "-----" | |
468 ["UPCASE keywords (buffer)" f90-upcase-keywords t] | |
469 ["UPCASE keywords (region)" f90-upcase-region-keywords | |
470 t] | |
471 ["Capitalize keywords (buffer)" f90-capitalize-keywords t] | |
472 ["Capitalize keywords (region)" | |
473 f90-capitalize-region-keywords t] | |
474 ["downcase keywords (buffer)" f90-downcase-keywords t] | |
475 ["downcase keywords (region)" | |
476 f90-downcase-region-keywords t] | |
477 "-----" | |
478 ["Toggle abbrev-mode" abbrev-mode t] | |
479 ["Toggle auto-fill" f90-auto-fill-mode t]))) | |
10613 | 480 ;; Emacs |
10612 | 481 (define-key f90-mode-map [menu-bar] (make-sparse-keymap)) |
482 (define-key f90-mode-map [menu-bar f90] | |
483 (cons "F90" (make-sparse-keymap "f90"))) | |
484 (define-key f90-mode-map [menu-bar f90 abbrev-mode] | |
485 '("Toggle abbrev-mode" . abbrev-mode)) | |
486 (define-key f90-mode-map [menu-bar f90 f90-auto-fill-mode] | |
487 '("Toggle auto-fill" . f90-auto-fill-mode)) | |
488 (define-key f90-mode-map [menu-bar f90 f90-downcase-region-keywords] | |
489 '("downcase keywords (region)" . f90-downcase-region-keywords)) | |
490 (define-key f90-mode-map [menu-bar f90 f90-downcase-keywords] | |
491 '("downcase keywords (buffer)" . f90-downcase-keywords)) | |
492 (define-key f90-mode-map [menu-bar f90 f90-capitalize-keywords] | |
493 '("Capitalize keywords (region)" . f90-capitalize-region-keywords)) | |
494 (define-key f90-mode-map [menu-bar f90 f90-capitalize-region-keywords] | |
495 '("Capitalize keywords (buffer)" . f90-capitalize-keywords)) | |
496 (define-key f90-mode-map [menu-bar f90 f90-upcase-region-keywords] | |
497 '("UPCASE keywords (region)" . f90-upcase-region-keywords)) | |
498 (define-key f90-mode-map [menu-bar f90 f90-upcase-keywords] | |
499 '("UPCASE keywords (buffer)" . f90-upcase-keywords)) | |
500 (define-key f90-mode-map [menu-bar f90 f90-insert-end] | |
501 '("Insert end." . f90-insert-end)) | |
502 (define-key f90-mode-map [menu-bar f90 f90-join-lines] | |
503 '("Join with next line." . f90-join-lines)) | |
504 (define-key f90-mode-map [menu-bar f90 f90-break-line] | |
505 '("Break line at point" . f90-break-line)) | |
506 (define-key f90-mode-map [menu-bar f90 f90-fill-region] | |
507 '("Fill Region" . f90-fill-region)) | |
508 (define-key f90-mode-map [menu-bar f90 indent-region] | |
509 '("Indent Region" . indent-region)) | |
510 (define-key f90-mode-map [menu-bar f90 f90-comment-region] | |
511 '("(Un)Comment Region" . f90-comment-region)) | |
512 (define-key f90-mode-map [menu-bar f90 f90-end-of-subprogram] | |
513 '("End of Subprogram" . f90-end-of-subprogram)) | |
514 (define-key f90-mode-map [menu-bar f90 f90-beginning-of-subprogram] | |
515 '("Beginning of Subprogram" . f90-beginning-of-subprogram)) | |
516 (define-key f90-mode-map [menu-bar f90 f90-mark-subprogram] | |
517 '("Mark Subprogram" . f90-mark-subprogram)) | |
518 (define-key f90-mode-map [menu-bar f90 f90-indent-subprogram] | |
519 '("Indent Subprogram" . f90-indent-subprogram))) | |
520 | |
521 (defconst f90-symbol-re "[a-z_][a-z_0-9]*") | |
522 (defconst f90-blocks-re | |
523 "\\(block[ \t]*data\\|do\\|if\\|interface\\|function\\|module\\|\ | |
524 program\\|select\\|subroutine\\|type\\|where\\|forall\\)\\>") | |
525 (defconst f90-program-block-re | |
526 "\\(program\\|module\\|subroutine\\|function\\)") | |
527 (defconst f90-else-like-re | |
528 "\\(else\\|else[ \t]*if\\|elsewhere\\|case[ \t]*(\\|case[ \t]*default\\)") | |
529 (defconst f90-end-if-re | |
530 "end[ \t]*\\(if\\|select\\|where\\|forall\\)\\>") | |
531 (defconst f90-end-type-re | |
532 "end[ \t]*\\(type\\|interface\\|block[ \t]*data\\)\\>") | |
533 (defconst f90-no-break-re "\\(\\*\\*\\|//\\|=>\\)") | |
534 ;; A temporary position to make region operators faster | |
535 (defvar f90-cache-position nil) | |
536 (make-variable-buffer-local 'f90-cache-position) | |
537 | |
538 ;; abbrevs have generally two letters, except standard types `c, `i, `r, `t | |
539 (defvar f90-mode-abbrev-table nil) | |
540 (if f90-mode-abbrev-table | |
541 () | |
542 (let ((ac abbrevs-changed)) | |
543 (define-abbrev-table 'f90-mode-abbrev-table ()) | |
544 (define-abbrev f90-mode-abbrev-table "`al" "allocate" nil) | |
545 (define-abbrev f90-mode-abbrev-table "`ab" "allocateable" nil) | |
546 (define-abbrev f90-mode-abbrev-table "`as" "assignment" nil) | |
547 (define-abbrev f90-mode-abbrev-table "`ba" "backspace" nil) | |
548 (define-abbrev f90-mode-abbrev-table "`bd" "block data" nil) | |
549 (define-abbrev f90-mode-abbrev-table "`c" "character" nil) | |
550 (define-abbrev f90-mode-abbrev-table "`cl" "close" nil) | |
551 (define-abbrev f90-mode-abbrev-table "`cm" "common" nil) | |
552 (define-abbrev f90-mode-abbrev-table "`cx" "complex" nil) | |
553 (define-abbrev f90-mode-abbrev-table "`cn" "contains" nil) | |
554 (define-abbrev f90-mode-abbrev-table "`cy" "cycle" nil) | |
555 (define-abbrev f90-mode-abbrev-table "`de" "deallocate" nil) | |
556 (define-abbrev f90-mode-abbrev-table "`df" "define" nil) | |
557 (define-abbrev f90-mode-abbrev-table "`di" "dimension" nil) | |
558 (define-abbrev f90-mode-abbrev-table "`dw" "do while" nil) | |
559 (define-abbrev f90-mode-abbrev-table "`el" "else" nil) | |
560 (define-abbrev f90-mode-abbrev-table "`eli" "else if" nil) | |
561 (define-abbrev f90-mode-abbrev-table "`elw" "elsewhere" nil) | |
562 (define-abbrev f90-mode-abbrev-table "`eq" "equivalence" nil) | |
563 (define-abbrev f90-mode-abbrev-table "`ex" "external" nil) | |
564 (define-abbrev f90-mode-abbrev-table "`ey" "entry" nil) | |
565 (define-abbrev f90-mode-abbrev-table "`fl" "forall" nil) | |
566 (define-abbrev f90-mode-abbrev-table "`fo" "format" nil) | |
567 (define-abbrev f90-mode-abbrev-table "`fu" "function" nil) | |
568 (define-abbrev f90-mode-abbrev-table "`fa" ".false." nil) | |
569 (define-abbrev f90-mode-abbrev-table "`im" "implicit none" nil) | |
570 (define-abbrev f90-mode-abbrev-table "`in " "include" nil) | |
571 (define-abbrev f90-mode-abbrev-table "`i" "integer" nil) | |
572 (define-abbrev f90-mode-abbrev-table "`it" "intent" nil) | |
573 (define-abbrev f90-mode-abbrev-table "`if" "interface" nil) | |
574 (define-abbrev f90-mode-abbrev-table "`lo" "logical" nil) | |
575 (define-abbrev f90-mode-abbrev-table "`mo" "module" nil) | |
576 (define-abbrev f90-mode-abbrev-table "`na" "namelist" nil) | |
577 (define-abbrev f90-mode-abbrev-table "`nu" "nullify" nil) | |
578 (define-abbrev f90-mode-abbrev-table "`op" "optional" nil) | |
579 (define-abbrev f90-mode-abbrev-table "`pa" "parameter" nil) | |
580 (define-abbrev f90-mode-abbrev-table "`po" "pointer" nil) | |
581 (define-abbrev f90-mode-abbrev-table "`pr" "print" nil) | |
582 (define-abbrev f90-mode-abbrev-table "`pi" "private" nil) | |
583 (define-abbrev f90-mode-abbrev-table "`pm" "program" nil) | |
584 (define-abbrev f90-mode-abbrev-table "`pu" "public" nil) | |
585 (define-abbrev f90-mode-abbrev-table "`r" "real" nil) | |
586 (define-abbrev f90-mode-abbrev-table "`rc" "recursive" nil) | |
587 (define-abbrev f90-mode-abbrev-table "`rt" "return" nil) | |
588 (define-abbrev f90-mode-abbrev-table "`rw" "rewind" nil) | |
589 (define-abbrev f90-mode-abbrev-table "`se" "select" nil) | |
590 (define-abbrev f90-mode-abbrev-table "`sq" "sequence" nil) | |
591 (define-abbrev f90-mode-abbrev-table "`su" "subroutine" nil) | |
592 (define-abbrev f90-mode-abbrev-table "`ta" "target" nil) | |
593 (define-abbrev f90-mode-abbrev-table "`tr" ".true." nil) | |
594 (define-abbrev f90-mode-abbrev-table "`t" "type" nil) | |
595 (define-abbrev f90-mode-abbrev-table "`wh" "where" nil) | |
596 (define-abbrev f90-mode-abbrev-table "`wr" "write" nil) | |
597 (setq abbrevs-changed ac))) | |
598 | |
599 ;;;###autoload | |
600 (defun f90-mode () | |
601 "Major mode for editing Fortran 90 code in free format. | |
602 | |
603 \\[f90-indent-new-line] corrects current indentation and creates new\ | |
604 indented line. | |
605 \\[f90-indent-line] indents the current line correctly. | |
606 \\[f90-indent-subprogram] indents the current subprogram. | |
607 | |
608 Type `? or `\\[help-command] to display a list of built-in\ | |
609 abbrevs for F90 keywords. | |
610 | |
611 Key definitions: | |
612 \\{f90-mode-map} | |
613 | |
614 Variables controlling indentation style and extra features: | |
615 | |
616 f90-do-indent | |
617 Extra indentation within do blocks. (default 3) | |
618 f90-if-indent | |
619 Extra indentation within if/select case/where/forall blocks. (default 3) | |
620 f90-type-indent | |
621 Extra indentation within type/interface/block-data blocks. (default 3) | |
622 f90-program-indent | |
623 Extra indentation within program/module/subroutine/function blocks. | |
624 (default 2) | |
625 f90-continuation-indent | |
626 Extra indentation applied to continuation lines. (default 5) | |
627 f90-comment-region | |
628 String inserted by \\[f90-comment-region] at start of each line in | |
629 region. (default \"!!!$\") | |
630 f90-indented-comment | |
631 String holding the type of comment to be intended like code. | |
632 This is a regular expression. (default \"!\") | |
633 f90-directive-comment | |
634 String of comment-like directive like \"!HPF$\", not to be indented. | |
635 (default nil) | |
636 f90-break-delimiters | |
637 Regexp holding list of delimiters at which lines may be broken. | |
638 (default \"[-+*/><=,% \\t]\") | |
639 f90-break-before-delimiters | |
640 Non-nil causes `f90-do-auto-fill' to break lines before delimiters. | |
641 (default t) | |
642 f90-beginning-ampersand | |
643 Automatic insertion of \& at beginning of continuation lines. (default t) | |
644 f90-smart-end | |
645 From an END statement, check and fill the end using matching block start. | |
646 Allowed values are 'blink, 'no-blink, and nil, which determine | |
647 whether to blink the matching beginning.) (default 'blink) | |
648 f90-auto-keyword-case | |
649 Automatic change of case of keywords. (default nil) | |
650 The possibilities are 'downcase-word, 'upcase-word, 'capitalize-word. | |
651 f90-auto-hilit19 (default nil) | |
652 Automatic highlighting (if hilit19 is used) at every indent or newline. | |
653 f90-leave-line-no | |
654 Do not left-justify line numbers. (default nil) | |
655 f90-startup-message | |
656 Set to nil to inhibit message first time F90 mode is used. (default t) | |
657 f90-keywords | |
658 List of keywords used for highlighting/upcase-keywords etc. | |
659 | |
660 Turning on F90 mode calls the value of the variable `f90-mode-hook' | |
661 with no args, if that value is non-nil." | |
662 (interactive) | |
663 (kill-all-local-variables) | |
664 (setq major-mode 'f90-mode) | |
665 (setq mode-name "F90") | |
666 (setq local-abbrev-table f90-mode-abbrev-table) | |
667 (set-syntax-table f90-mode-syntax-table) | |
668 (use-local-map f90-mode-map) | |
669 (make-local-variable 'indent-line-function) | |
670 (setq indent-line-function 'f90-indent-line) | |
671 (make-local-variable 'indent-region-function) | |
672 (setq indent-region-function 'f90-indent-region) | |
673 (make-local-variable 'require-final-newline) | |
674 (setq require-final-newline t) | |
675 (make-local-variable 'comment-start) | |
676 (setq comment-start "!") | |
677 (make-local-variable 'comment-start-skip) | |
678 (setq comment-start-skip "!+ *") | |
679 (make-local-variable 'comment-indent-function) | |
680 (setq comment-indent-function 'f90-comment-indent) | |
681 (make-local-variable 'abbrev-all-caps) | |
682 (setq abbrev-all-caps t) | |
683 ;; Setting up things for font-lock | |
684 (if (string-match "Lucid" emacs-version) | |
685 (put 'f90-mode 'font-lock-keywords-case-fold-search t) | |
10613 | 686 ;; (make-local-variable 'font-lock-keywords) ; for version <= 19.28 |
10612 | 687 ;; (setq font-lock-keywords f90-font-lock-keywords) |
10613 | 688 (make-local-variable 'font-lock-defaults) ; for version > 19.28 |
10612 | 689 (setq font-lock-defaults '(f90-font-lock-keywords t)) |
690 ) | |
691 (make-local-variable 'font-lock-keywords-case-fold-search) | |
692 (setq font-lock-keywords-case-fold-search t) | |
693 (run-hooks 'f90-mode-hook) | |
694 (if f90-startup-message | |
10644
ce2d2fe2fa79
(f90-mode-version): Variable deleted.
Richard M. Stallman <rms@gnu.org>
parents:
10613
diff
changeset
|
695 (message "Emacs F90 mode; please report bugs to %s" bug-f90-mode)) |
10612 | 696 (setq f90-startup-message nil)) |
697 | |
698 ;; inline-functions | |
699 (defsubst f90-get-beg-of-line () | |
700 (save-excursion (beginning-of-line) (point))) | |
701 | |
702 (defsubst f90-get-end-of-line () | |
703 (save-excursion (end-of-line) (point))) | |
704 | |
705 (defsubst f90-in-string () | |
706 (let ((beg-pnt | |
707 (if (and f90-cache-position (> (point) f90-cache-position)) | |
708 f90-cache-position | |
709 (point-min)))) | |
710 (nth 3 (parse-partial-sexp beg-pnt (point))))) | |
711 | |
712 (defsubst f90-in-comment () | |
713 (let ((beg-pnt | |
714 (if (and f90-cache-position (> (point) f90-cache-position)) | |
715 f90-cache-position | |
716 (point-min)))) | |
717 (nth 4 (parse-partial-sexp beg-pnt (point))))) | |
718 | |
719 (defsubst f90-line-continued () | |
720 (save-excursion | |
721 (let ((bol (f90-get-beg-of-line))) | |
722 (end-of-line) | |
723 (while (f90-in-comment) | |
724 (search-backward "!" bol) | |
725 (skip-chars-backward "!")) | |
726 (skip-chars-backward " \t") | |
727 (= (preceding-char) ?&)))) | |
728 | |
729 (defsubst f90-current-indentation () | |
730 "Return indentation of current line. | |
731 Line-numbers are considered whitespace characters." | |
732 (save-excursion | |
733 (beginning-of-line) (skip-chars-forward " \t0-9") | |
734 (current-column))) | |
735 | |
736 (defsubst f90-indent-to (col &optional no-line-number) | |
737 "Indent current line to column COL. | |
738 If no-line-number nil, jump over a possible line-number." | |
739 (beginning-of-line) | |
740 (if (not no-line-number) | |
741 (skip-chars-forward " \t0-9")) | |
742 (delete-horizontal-space) | |
743 (if (zerop (current-column)) | |
744 (indent-to col) | |
745 (indent-to col 1))) | |
746 | |
747 (defsubst f90-match-piece (arg) | |
748 (if (match-beginning arg) | |
749 (buffer-substring (match-beginning arg) (match-end arg)))) | |
750 | |
751 (defsubst f90-get-present-comment-type () | |
752 (save-excursion | |
753 (let ((type nil) (eol (f90-get-end-of-line))) | |
754 (if (f90-in-comment) | |
755 (progn | |
756 (beginning-of-line) | |
757 (re-search-forward "[!]+" eol) | |
758 (while (f90-in-string) | |
759 (re-search-forward "[!]+" eol)) | |
760 (setq type (buffer-substring (match-beginning 0) (match-end 0))))) | |
761 type))) | |
762 | |
763 (defsubst f90-equal-symbols (a b) | |
764 "Compare strings neglecting case and allowing for nil value." | |
765 (let ((a-local (if a (downcase a) nil)) | |
766 (b-local (if b (downcase b) nil))) | |
767 (equal a-local b-local))) | |
768 | |
769 ;; There seems to be a bug in XEmacs matching of regular expressions. | |
770 ;; One cannot extract the label directly for do,if, and select case. | |
771 ;; Therefore, the following functions are longer than necessary. | |
772 | |
773 (defsubst f90-looking-at-do () | |
774 "Return (\"do\" name) if a do statement starts after point. | |
775 Name is nil if the statement has no label." | |
776 (let (struct (label nil)) | |
777 (if (looking-at (concat "\\(\\(" f90-symbol-re "\\)[ \t]*\:\\)?" | |
778 "[ \t]*\\(do\\)\\b")) | |
779 (progn | |
780 (setq struct (f90-match-piece 3)) | |
781 (if (looking-at (concat "\\(" f90-symbol-re "\\)[ \t]*\:")) | |
782 (setq label (f90-match-piece 1))) | |
783 (list struct label))))) | |
784 | |
785 (defsubst f90-looking-at-if-then () | |
786 "Return (\"if\" name) if an if () then statement starts after point. | |
787 Name is nil if the statement has no label." | |
788 (save-excursion | |
789 (let (struct (label nil)) | |
790 (if (looking-at (concat "\\(\\(" f90-symbol-re "\\)[ \t]*\:\\)?" | |
791 "[ \t]*\\(if\\)\\b")) | |
792 (progn | |
793 (setq struct (f90-match-piece 3)) | |
794 (if (looking-at (concat "\\(" f90-symbol-re "\\)[ \t]*\:")) | |
795 (setq label (f90-match-piece 1))) | |
796 (goto-char (scan-lists (point) 1 0)) | |
797 (skip-chars-forward " \t") | |
798 (if (or (looking-at "then\\b") | |
799 (if (f90-line-continued) | |
800 (progn | |
801 (f90-next-statement) | |
802 (skip-chars-forward " \t0-9&") | |
803 (looking-at "then\\b")))) | |
804 (list struct label))))))) | |
805 | |
806 (defsubst f90-looking-at-select-case () | |
807 "Return (\"select\" name) if a select-case statement starts after point. | |
808 Name is nil if the statement has no label." | |
809 (let (struct (label nil)) | |
810 (if (looking-at (concat "\\(\\(" f90-symbol-re "\\)[ \t]*\:\\)?" | |
811 "[ \t]*\\(select\\)[ \t]*case[ \t]*(")) | |
812 (progn | |
813 (setq struct (f90-match-piece 3)) | |
814 (if (looking-at (concat "\\(" f90-symbol-re "\\)[ \t]*\:")) | |
815 (setq label (f90-match-piece 1))) | |
816 (list struct label))))) | |
817 | |
818 (defsubst f90-looking-at-where-or-forall () | |
819 "Return (kind nil) if where/forall...end starts after point." | |
820 (save-excursion | |
821 (let (command) | |
822 (if (looking-at "\\(where\\|forall\\)[ \t]*(") | |
823 (progn | |
824 (setq command (list (f90-match-piece 1) nil)) | |
825 (goto-char (scan-lists (point) 1 0)) | |
826 (skip-chars-forward " \t") | |
827 (if (looking-at "\\(!\\|$\\)") | |
828 command)))))) | |
829 | |
830 (defsubst f90-looking-at-type-like () | |
831 "Return (kind name) at the start of a type/interface/block-data block. | |
832 Name is non-nil only for type." | |
833 (cond | |
834 ((looking-at (concat "\\(type\\)[ \t]+\\(" f90-symbol-re "\\)\\>")) | |
835 (list (f90-match-piece 1) (f90-match-piece 2))) | |
836 ((looking-at "\\(interface\\)\\>") | |
837 (list (f90-match-piece 1) nil)) | |
838 ((looking-at "\\(block[ \t]*data\\)\\>") | |
839 (list (f90-match-piece 1) nil)))) | |
840 | |
841 (defsubst f90-looking-at-program-block-start () | |
842 "Return (kind name) if a program block with name name starts after point." | |
843 (cond | |
844 ((looking-at (concat "\\(program\\)[ \t]+\\(" f90-symbol-re "\\)\\b")) | |
845 (list (f90-match-piece 1) (f90-match-piece 2))) | |
846 ((and (not (looking-at "module[ \t]*procedure\\>")) | |
847 (looking-at (concat "\\(module\\)[ \t]+\\(" | |
848 f90-symbol-re "\\)\\b"))) | |
849 (list (f90-match-piece 1) (f90-match-piece 2))) | |
850 ((looking-at (concat "\\(recursive[ \t]*\\)?\\(subroutine\\)[ \t]+\\(" | |
851 f90-symbol-re "\\)")) | |
852 (list (f90-match-piece 2) (f90-match-piece 3))) | |
853 ((looking-at (concat "[a-z0-9()_ \t]*\\(function\\)[ \t]+\\(" | |
854 f90-symbol-re "\\)[ \t]*(")) | |
855 (list (f90-match-piece 1) (f90-match-piece 2))))) | |
856 | |
857 (defsubst f90-looking-at-program-block-end () | |
858 "Return list of type and name of end of block." | |
859 (if (looking-at (concat "end[ \t]*" f90-blocks-re "?\\([ \t]+\\(" | |
860 f90-symbol-re "\\)\\)?\\>")) | |
861 (list (f90-match-piece 1) (f90-match-piece 3)))) | |
862 | |
863 (defsubst f90-comment-indent () | |
864 (cond ((looking-at "!!!") 0) | |
865 ((and f90-directive-comment | |
866 (looking-at (regexp-quote f90-directive-comment))) 0) | |
867 ((looking-at (regexp-quote f90-comment-region)) 0) | |
868 ((looking-at f90-indented-comment) | |
869 (f90-calculate-indent)) | |
870 (t (skip-chars-backward " \t") | |
871 (max (if (bolp) 0 (1+ (current-column))) comment-column)))) | |
872 | |
873 (defsubst f90-present-statement-cont () | |
874 "Return continuation properties of present statement." | |
875 (let (pcont cont) | |
876 (save-excursion | |
877 (setq pcont (if (f90-previous-statement) (f90-line-continued) nil))) | |
878 (setq cont (f90-line-continued)) | |
879 (cond ((and (not pcont) (not cont)) 'single) | |
880 ((and (not pcont) cont) 'begin) | |
881 ((and pcont (not cont)) 'end) | |
882 ((and pcont cont) 'middle) | |
883 (t (error))))) | |
884 | |
885 (defsubst f90-indent-line-no () | |
886 (if f90-leave-line-no | |
887 () | |
888 (if (and (not (zerop (skip-chars-forward " \t"))) | |
889 (looking-at "[0-9]")) | |
890 (delete-horizontal-space))) | |
891 (skip-chars-forward " \t0-9")) | |
892 | |
893 (defsubst f90-no-block-limit () | |
894 (let ((eol (f90-get-end-of-line))) | |
895 (save-excursion | |
896 (not (or (looking-at "end") | |
897 (looking-at "\\(do\\|if\\|else\\|select[ \t]*case\\|\ | |
898 case\\|where\\|forall\\)\\>") | |
899 (looking-at "\\(program\\|module\\|interface\\|\ | |
900 block[ \t]*data\\)\\>") | |
901 (looking-at "\\(contains\\|continue\\|\\sw+[ \t]*:\\)") | |
902 (looking-at "type[ \t]+\\sw+") | |
903 (re-search-forward "\\(function\\|subroutine\\)" eol t)))))) | |
904 | |
905 (defsubst f90-update-line () | |
906 (let (bol eol) | |
907 (if (or f90-auto-keyword-case f90-auto-hilit19) | |
908 (progn (setq bol (f90-get-beg-of-line) | |
909 eol (f90-get-end-of-line)) | |
910 (if f90-auto-keyword-case | |
911 (f90-change-keywords f90-auto-keyword-case bol eol)) | |
912 (if (and f90-auto-hilit19 (fboundp 'hilit-rehighlight-region)) | |
913 (hilit-rehighlight-region bol eol t)))))) | |
914 | |
915 (defun f90-get-correct-indent () | |
916 "Get correct indent for a line starting with line number. | |
917 Does not check type and subprogram indentation." | |
918 (let ((epnt (f90-get-end-of-line)) icol cont) | |
919 (save-excursion | |
920 (while (and (f90-previous-statement) | |
921 (or (progn | |
922 (setq cont (f90-present-statement-cont)) | |
923 (or (eq cont 'end) (eq cont 'middle))) | |
924 (looking-at "[ \t]*[0-9]")))) | |
925 (setq icol (current-indentation)) | |
926 (beginning-of-line) | |
927 (if (re-search-forward "\\(if\\|do\\|select\\|where\\|forall\\)" | |
928 (f90-get-end-of-line) t) | |
929 (progn | |
930 (beginning-of-line) (skip-chars-forward " \t") | |
931 (cond ((f90-looking-at-do) | |
932 (setq icol (+ icol f90-do-indent))) | |
933 ((or (f90-looking-at-if-then) | |
934 (f90-looking-at-where-or-forall) | |
935 (f90-looking-at-select-case)) | |
936 (setq icol (+ icol f90-if-indent)))) | |
937 (end-of-line))) | |
938 (while (re-search-forward | |
939 "\\(if\\|do\\|select\\|where\\|forall\\|continue\\)" epnt t) | |
940 (beginning-of-line) (skip-chars-forward " \t0-9") | |
941 (cond ((f90-looking-at-do) | |
942 (setq icol (+ icol f90-do-indent))) | |
943 ((or (f90-looking-at-if-then) | |
944 (f90-looking-at-where-or-forall) | |
945 (f90-looking-at-select-case)) | |
946 (setq icol (+ icol f90-if-indent))) | |
947 ((looking-at f90-end-if-re) | |
948 (setq icol (- icol f90-if-indent))) | |
949 ((looking-at "\\(end[ \t]*do\\|continue\\)\\>") | |
950 (setq icol (- icol f90-do-indent)))) | |
951 (end-of-line)) | |
952 icol))) | |
953 | |
954 | |
955 (defun f90-calculate-indent () | |
956 "Calculate the indent column based on previous statements." | |
957 (interactive) | |
958 (let (icol cont (case-fold-search t) (pnt (point))) | |
959 (save-excursion | |
960 (if (not (f90-previous-statement)) | |
961 (setq icol 0) | |
962 (setq cont (f90-present-statement-cont)) | |
963 (if (eq cont 'end) | |
964 (while (not (eq 'begin (f90-present-statement-cont))) | |
965 (f90-previous-statement))) | |
966 (cond ((eq cont 'begin) | |
967 (setq icol (+ (f90-current-indentation) | |
968 f90-continuation-indent))) | |
969 ((eq cont 'middle) (setq icol(current-indentation))) | |
970 (t (setq icol (f90-current-indentation)) | |
971 (skip-chars-forward " \t") | |
972 (if (looking-at "[0-9]") | |
973 (setq icol (f90-get-correct-indent)) | |
974 (cond ((or (f90-looking-at-if-then) | |
975 (f90-looking-at-where-or-forall) | |
976 (f90-looking-at-select-case) | |
977 (looking-at f90-else-like-re)) | |
978 (setq icol (+ icol f90-if-indent))) | |
979 ((f90-looking-at-do) | |
980 (setq icol (+ icol f90-do-indent))) | |
981 ((f90-looking-at-type-like) | |
982 (setq icol (+ icol f90-type-indent))) | |
983 ((or (f90-looking-at-program-block-start) | |
984 (looking-at "contains[ \t]*\\($\\|!\\)")) | |
985 (setq icol (+ icol f90-program-indent))))) | |
986 (goto-char pnt) | |
987 (beginning-of-line) | |
988 (cond ((looking-at "[ \t]*$")) | |
989 ((looking-at "[ \t]*#") ; Check for cpp directive. | |
990 (setq icol 0)) | |
991 (t | |
992 (skip-chars-forward " \t0-9") | |
993 (cond ((or (looking-at f90-else-like-re) | |
994 (looking-at f90-end-if-re)) | |
995 (setq icol (- icol f90-if-indent))) | |
996 ((looking-at "\\(end[ \t]*do\\|continue\\)\\>") | |
997 (setq icol (- icol f90-do-indent))) | |
998 ((looking-at f90-end-type-re) | |
999 (setq icol (- icol f90-type-indent))) | |
1000 ((or (looking-at "contains[ \t]*\\(!\\|$\\)") | |
1001 (f90-looking-at-program-block-end)) | |
1002 (setq icol (- icol f90-program-indent)))))) | |
1003 )))) | |
1004 icol)) | |
1005 | |
1006 ;; Statement = statement line, a line which is neither blank, nor a comment. | |
1007 (defun f90-previous-statement () | |
1008 "Move point to beginning of the previous F90 statement. | |
1009 Return nil if no previous statement is found." | |
1010 (interactive) | |
1011 (let (not-first-statement) | |
1012 (beginning-of-line) | |
1013 (while (and (setq not-first-statement (zerop (forward-line -1))) | |
1014 (looking-at "[ \t0-9]*\\(!\\|$\\)"))) | |
1015 not-first-statement)) | |
1016 | |
1017 (defun f90-next-statement () | |
1018 "Move point to beginning of the next F90 statement. | |
1019 Return nil if no later statement is found." | |
1020 (interactive) | |
1021 (let (not-last-statement) | |
1022 (beginning-of-line) | |
1023 (while (and (setq not-last-statement | |
1024 (and (zerop (forward-line 1)) | |
1025 (not (eobp)))) | |
1026 (looking-at "[ \t0-9]*\\(!\\|$\\)"))) | |
1027 not-last-statement)) | |
1028 | |
1029 (defun f90-beginning-of-subprogram () | |
1030 "Move point to the beginning of subprogram. | |
1031 Return (type name) or nil if not found." | |
1032 (interactive) | |
1033 (let ((count 1) (case-fold-search t) matching-beg) | |
1034 (beginning-of-line) (skip-chars-forward " \t0-9") | |
1035 (if (setq matching-beg (f90-looking-at-program-block-start)) | |
1036 (setq count (- count 1))) | |
1037 (while (and (not (zerop count)) | |
1038 (re-search-backward f90-program-block-re nil 'move)) | |
1039 (beginning-of-line) (skip-chars-forward " \t0-9") | |
1040 (cond | |
1041 ((setq matching-beg (f90-looking-at-program-block-start)) | |
1042 (setq count (- count 1))) | |
1043 ((f90-looking-at-program-block-end) | |
1044 (setq count (+ count 1))))) | |
1045 (beginning-of-line) | |
1046 (if (zerop count) | |
1047 matching-beg | |
1048 (message "No beginning-found.") | |
1049 nil))) | |
1050 | |
1051 (defun f90-end-of-subprogram () | |
1052 "Move point to the end of subprogram. | |
1053 Return (type name) or nil if not found." | |
1054 (interactive) | |
1055 (let ((count 1) (case-fold-search t) matching-end) | |
1056 (beginning-of-line) (skip-chars-forward " \t0-9") | |
1057 (if (setq matching-end (f90-looking-at-program-block-end)) | |
1058 (setq count (1- count))) | |
1059 (end-of-line) | |
1060 (while (and (not (zerop count)) | |
1061 (re-search-forward f90-program-block-re nil 'move)) | |
1062 (beginning-of-line) (skip-chars-forward " \t0-9") | |
1063 (cond ((f90-looking-at-program-block-start) | |
1064 (setq count (+ count 1))) | |
1065 ((setq matching-end (f90-looking-at-program-block-end)) | |
1066 (setq count (1- count )))) | |
1067 (end-of-line)) | |
1068 (forward-line 1) | |
1069 (if (zerop count) | |
1070 matching-end | |
1071 (message "No end found.") | |
1072 nil))) | |
1073 | |
1074 (defun f90-mark-subprogram () | |
1075 "Put mark at end of F90 subprogram, point at beginning. | |
1076 Marks are pushed and highlight (grey shadow) is turned on." | |
1077 (interactive) | |
1078 (let ((pos (point)) program) | |
1079 (f90-end-of-subprogram) | |
1080 (push-mark (point) t) | |
1081 (goto-char pos) | |
1082 (setq program (f90-beginning-of-subprogram)) | |
1083 ;; The keywords in the preceding lists assume case-insensitivity. | |
1084 (if (string-match "Lucid" emacs-version) | |
1085 (zmacs-activate-region) | |
1086 (setq mark-active t) | |
1087 (setq deactivate-mark nil)) | |
1088 program)) | |
1089 | |
1090 (defun f90-comment-region (beg-region end-region) | |
1091 "Comment/uncomment every line in the region. | |
1092 Insert f90-comment-region at the beginning of every line in the region | |
1093 or, if already present, remove it." | |
1094 (interactive "*r") | |
1095 (let ((end (make-marker))) | |
1096 (set-marker end end-region) | |
1097 (goto-char beg-region) | |
1098 (beginning-of-line) | |
1099 (if (looking-at (regexp-quote f90-comment-region)) | |
1100 (delete-region (point) (match-end 0)) | |
1101 (insert f90-comment-region)) | |
1102 (while (and (zerop (forward-line 1)) | |
1103 (< (point) (marker-position end))) | |
1104 (if (looking-at (regexp-quote f90-comment-region)) | |
1105 (delete-region (point) (match-end 0)) | |
1106 (insert f90-comment-region))) | |
1107 (set-marker end nil))) | |
1108 | |
1109 (defun f90-indent-line (&optional no-update) | |
1110 "Indent current line as F90 code." | |
1111 (interactive) | |
1112 (let (indent (no-line-number nil) (pos (make-marker)) (case-fold-search t)) | |
1113 (set-marker pos (point)) | |
1114 (beginning-of-line) ; Digits after & \n are not line-no | |
1115 (if (save-excursion (and (f90-previous-statement) (f90-line-continued))) | |
1116 (progn (setq no-line-number t) (skip-chars-forward " \t")) | |
1117 (f90-indent-line-no)) | |
1118 (if (looking-at "!") | |
1119 (setq indent (f90-comment-indent)) | |
1120 (if (and (looking-at "end") f90-smart-end) (f90-match-end)) | |
1121 (setq indent (f90-calculate-indent))) | |
1122 (if (zerop (- indent (current-column))) | |
1123 nil | |
1124 (f90-indent-to indent no-line-number)) | |
1125 ;; If initial point was within line's indentation, | |
1126 ;; position after the indentation. Else stay at same point in text. | |
1127 (if (< (point) (marker-position pos)) | |
1128 (goto-char (marker-position pos))) | |
1129 (if (not no-update) (f90-update-line)) | |
1130 (if (and auto-fill-function | |
1131 (> (save-excursion (end-of-line) (current-column)) fill-column)) | |
1132 (save-excursion (f90-do-auto-fill))) | |
1133 (set-marker pos nil))) | |
1134 | |
1135 (defun f90-indent-new-line () | |
1136 "Reindent the current F90 line, insert a newline and indent the newline. | |
1137 An abbrev before point is expanded if `abbrev-mode' is non-nil. | |
1138 If run in the middle of a line, the line is not broken." | |
1139 (interactive) | |
1140 (let (string cont (case-fold-search t)) | |
1141 (if abbrev-mode (expand-abbrev)) | |
1142 (beginning-of-line) ; Reindent where likely to be needed. | |
1143 (f90-indent-line-no) | |
1144 (if (or (looking-at "\\(end\\|else\\|!\\)")) | |
1145 (f90-indent-line 'no-update)) | |
1146 (end-of-line) | |
1147 (delete-horizontal-space) ;Destroy trailing whitespace | |
1148 (setq string (f90-in-string)) | |
1149 (setq cont (f90-line-continued)) | |
1150 (if (and string (not cont)) (insert "&")) | |
1151 (f90-update-line) | |
1152 (newline) | |
1153 (if (or string (and cont f90-beginning-ampersand)) (insert "&")) | |
1154 (f90-indent-line 'no-update))) | |
1155 | |
1156 | |
1157 (defun f90-indent-region (beg-region end-region) | |
1158 "Indent every line in region by forward parsing." | |
1159 (interactive "*r") | |
1160 (let ((end-region-mark (make-marker)) (save-point (point-marker)) | |
1161 (block-list nil) ind-lev ind-curr ind-b cont | |
1162 struct beg-struct end-struct) | |
1163 (set-marker end-region-mark end-region) | |
1164 (goto-char beg-region) | |
1165 ;; first find a line which is not a continuation line or comment | |
1166 (beginning-of-line) | |
1167 (while (and (looking-at "[ \t]*[0-9]*\\(!\\|[ \t]*$\\)") | |
1168 (progn (f90-indent-line 'no-update) | |
1169 (zerop (forward-line 1))) | |
1170 (< (point) end-region-mark))) | |
1171 (setq cont (f90-present-statement-cont)) | |
1172 (while (and (or (eq cont 'middle) (eq cont 'end)) | |
1173 (f90-previous-statement)) | |
1174 (setq cont (f90-present-statement-cont))) | |
1175 ;; process present line for beginning of block | |
1176 (setq f90-cache-position (point)) | |
1177 (f90-indent-line 'no-update) | |
1178 (setq ind-lev (f90-current-indentation)) | |
1179 (setq ind-curr ind-lev) | |
1180 (beginning-of-line) (skip-chars-forward " \t0-9") | |
1181 (setq struct nil) | |
1182 (setq ind-b (cond ((setq struct (f90-looking-at-do)) f90-do-indent) | |
1183 ((or (setq struct (f90-looking-at-if-then)) | |
1184 (setq struct (f90-looking-at-select-case)) | |
1185 (setq struct (f90-looking-at-where-or-forall)) | |
1186 (looking-at f90-else-like-re)) | |
1187 f90-if-indent) | |
1188 ((setq struct (f90-looking-at-type-like)) | |
1189 f90-type-indent) | |
1190 ((or(setq struct (f90-looking-at-program-block-start)) | |
1191 (looking-at "contains[ \t]*\\($\\|!\\)")) | |
1192 f90-program-indent))) | |
1193 (if ind-b (setq ind-lev (+ ind-lev ind-b))) | |
1194 (if struct (setq block-list (cons struct block-list))) | |
1195 (while (and (f90-line-continued) (zerop (forward-line 1)) | |
1196 (< (point) end-region-mark)) | |
1197 (if (not (zerop (- (current-indentation) | |
1198 (+ ind-curr f90-continuation-indent)))) | |
1199 (f90-indent-to (+ ind-curr f90-continuation-indent) 'no-line-no))) | |
1200 ;; process all following lines | |
1201 (while (and (zerop (forward-line 1)) (< (point) end-region-mark)) | |
1202 (beginning-of-line) | |
1203 (f90-indent-line-no) | |
1204 (setq f90-cache-position (point)) | |
1205 (cond ((looking-at "[ \t]*$") (setq ind-curr 0)) | |
1206 ((looking-at "[ \t]*#") (setq ind-curr 0)) | |
1207 ((looking-at "!") (setq ind-curr (f90-comment-indent))) | |
1208 ((f90-no-block-limit) (setq ind-curr ind-lev)) | |
1209 ((looking-at f90-else-like-re) (setq ind-curr | |
1210 (- ind-lev f90-if-indent))) | |
1211 ((looking-at "contains[ \t]*\\($\\|!\\)") | |
1212 (setq ind-curr (- ind-lev f90-program-indent))) | |
1213 ((setq ind-b | |
1214 (cond ((setq struct (f90-looking-at-do)) f90-do-indent) | |
1215 ((or (setq struct (f90-looking-at-if-then)) | |
1216 (setq struct (f90-looking-at-select-case)) | |
1217 (setq struct (f90-looking-at-where-or-forall))) | |
1218 f90-if-indent) | |
1219 ((setq struct (f90-looking-at-type-like)) | |
1220 f90-type-indent) | |
1221 ((setq struct (f90-looking-at-program-block-start)) | |
1222 f90-program-indent))) | |
1223 (setq ind-curr ind-lev) | |
1224 (if ind-b (setq ind-lev (+ ind-lev ind-b))) | |
1225 (setq block-list (cons struct block-list))) | |
1226 ((setq end-struct (f90-looking-at-program-block-end)) | |
1227 (setq beg-struct (car block-list) | |
1228 block-list (cdr block-list)) | |
1229 (if f90-smart-end | |
1230 (save-excursion | |
1231 (f90-block-match (car beg-struct)(car (cdr beg-struct)) | |
1232 (car end-struct)(car (cdr end-struct))))) | |
1233 (setq ind-b | |
1234 (cond ((looking-at f90-end-if-re) f90-if-indent) | |
1235 ((looking-at "end[ \t]*do\\>") f90-do-indent) | |
1236 ((looking-at f90-end-type-re) f90-type-indent) | |
1237 ((f90-looking-at-program-block-end) | |
1238 f90-program-indent))) | |
1239 (if ind-b (setq ind-lev (- ind-lev ind-b))) | |
1240 (setq ind-curr ind-lev)) | |
1241 ((looking-at "continue\\>") | |
1242 (setq ind-lev (- ind-lev f90-do-indent)) | |
1243 (setq ind-curr ind-lev) | |
1244 (setq block-list (cdr block-list))) | |
1245 (t (setq ind-curr ind-lev))) | |
1246 ;; do the indentation if necessary | |
1247 (if (not (zerop (- ind-curr (current-column)))) | |
1248 (f90-indent-to ind-curr)) | |
1249 (while (and (f90-line-continued) (zerop (forward-line 1)) | |
1250 (< (point) end-region-mark)) | |
1251 (if (not (zerop (- (current-indentation) | |
1252 (+ ind-curr f90-continuation-indent)))) | |
1253 (f90-indent-to (+ ind-curr f90-continuation-indent) 'no-line-no)))) | |
1254 ;; restore point etc | |
1255 (setq f90-cache-position nil) | |
1256 (goto-char save-point) | |
1257 (set-marker end-region-mark nil) | |
1258 (set-marker save-point nil) | |
1259 (if (string-match "Lucid" emacs-version) | |
1260 (zmacs-deactivate-region) | |
1261 (deactivate-mark)))) | |
1262 | |
1263 (defun f90-indent-subprogram () | |
1264 "Properly indent the subprogram which contains point." | |
1265 (interactive) | |
1266 (save-excursion | |
1267 (let (program) | |
1268 (setq program (f90-mark-subprogram)) | |
1269 (if program | |
1270 (progn | |
1271 (message (concat "Indenting " (car program) " " | |
1272 (car (cdr program))".")) | |
1273 (f90-indent-region (point) (mark)) | |
1274 (message (concat "Indenting " (car program) " " | |
1275 (car (cdr program)) "...done."))) | |
1276 (message "Indenting the whole file.") | |
1277 (f90-indent-region (point) (mark)) | |
1278 (message (concat "Indenting the whole file...done.")))))) | |
1279 | |
1280 ;; autofill and break-line | |
1281 (defun f90-break-line (&optional no-update) | |
1282 "Break line at point, insert continuation marker(s) and indent." | |
1283 (interactive) | |
1284 (let (ctype) | |
1285 (cond ((f90-in-string) | |
1286 (insert "&") (newline) (insert "&")) | |
1287 ((f90-in-comment) | |
1288 (delete-horizontal-space) | |
1289 (setq ctype (f90-get-present-comment-type)) | |
1290 (newline) (insert (concat ctype " "))) | |
1291 (t (delete-horizontal-space) | |
1292 (insert "&") | |
1293 (if (not no-update) (f90-update-line)) | |
1294 (newline) | |
1295 (if f90-beginning-ampersand (insert "& "))))) | |
1296 (if (not no-update) (f90-indent-line))) | |
1297 | |
1298 (defun f90-find-breakpoint () | |
1299 "From fill-column, search backward for break-delimiter." | |
1300 (let ((bol (f90-get-beg-of-line))) | |
1301 (re-search-backward f90-break-delimiters bol) | |
1302 (if f90-break-before-delimiters | |
1303 (progn (backward-char) | |
1304 (if (not (looking-at f90-no-break-re)) | |
1305 (forward-char))) | |
1306 (if (looking-at f90-no-break-re) | |
1307 (forward-char 2) | |
1308 (forward-char))))) | |
1309 | |
1310 (defun f90-auto-fill-mode (arg) | |
1311 "Toggle f90-auto-fill mode. | |
1312 With ARG, turn `f90-auto-fill' mode on iff ARG is positive. | |
1313 In `f90-auto-fill' mode, inserting a space at a column beyond `fill-column' | |
1314 automatically breaks the line at a previous space." | |
1315 (interactive "P") | |
1316 (prog1 (setq auto-fill-function | |
1317 (if (if (null arg) | |
1318 (not auto-fill-function) | |
1319 (> (prefix-numeric-value arg) 0)) | |
1320 'f90-do-auto-fill)) | |
1321 ;; update mode-line | |
1322 (set-buffer-modified-p (buffer-modified-p)))) | |
1323 | |
1324 (defun f90-do-auto-fill () | |
1325 "Break line if non-white characters beyond fill-column." | |
1326 (interactive) | |
1327 ;; Break the line before or after the last delimiter (non-word char). | |
1328 ;; Will not break **, //, or => (specified by f90-no-break-re). | |
1329 (move-to-column fill-column) | |
1330 (if (and (looking-at "[ \t]*$") (not (f90-in-string))) | |
1331 (delete-horizontal-space) | |
1332 (f90-find-breakpoint) | |
1333 (f90-break-line) | |
1334 (end-of-line))) | |
1335 | |
1336 (defun f90-join-lines () | |
1337 "Join present line with next line, if this line ends with \&." | |
1338 (interactive) | |
1339 (let (pos (oldpos (point))) | |
1340 (end-of-line) | |
1341 (skip-chars-backward " \t") | |
1342 (cond ((= (preceding-char) ?&) | |
1343 (delete-char -1) | |
1344 (setq pos (point)) | |
1345 (forward-line 1) | |
1346 (skip-chars-forward " \t") | |
1347 (if (looking-at "\&") (delete-char 1)) | |
1348 (delete-region pos (point)) | |
1349 (if (not (f90-in-string)) | |
1350 (progn (delete-horizontal-space) (insert " "))) | |
1351 (if (and auto-fill-function | |
1352 (> (save-excursion (end-of-line) | |
1353 (current-column)) | |
1354 fill-column)) | |
1355 (f90-do-auto-fill)) | |
1356 (goto-char oldpos) | |
1357 t)))) | |
1358 | |
1359 (defun f90-fill-region (beg-region end-region) | |
1360 "Fill every line in region by forward parsing. Join lines if possible." | |
1361 (interactive "*r") | |
1362 (let ((end-region-mark (make-marker)) | |
1363 (f90-smart-end nil) (f90-auto-keyword-case nil) | |
1364 (f90-auto-hilit19 nil) indent (go-on t) | |
1365 (af-function auto-fill-function) (auto-fill-function nil)) | |
1366 (set-marker end-region-mark end-region) | |
1367 (goto-char beg-region) | |
1368 (while go-on | |
1369 ;; join as much as possible | |
1370 (while (f90-join-lines)); | |
1371 (setq indent (+ (f90-current-indentation) f90-continuation-indent)) | |
1372 ;; chop the line if necessary | |
1373 (while (> (save-excursion (end-of-line) (current-column)) | |
1374 fill-column) | |
1375 (move-to-column fill-column) | |
1376 (if (and (looking-at "[ \t]*$") (not (f90-in-string))) | |
1377 (delete-horizontal-space) | |
1378 (f90-find-breakpoint) | |
1379 (f90-break-line 'no-update) | |
1380 (f90-indent-to indent 'no-line-no))) | |
1381 (setq go-on (and (< (point) (marker-position end-region-mark)) | |
1382 (zerop (forward-line 1)))) | |
1383 (setq f90-cache-position (point))) | |
1384 (setq auto-fill-function af-function) | |
1385 (setq f90-cache-position nil) | |
1386 (if (string-match "Lucid" emacs-version) | |
1387 (zmacs-deactivate-region) | |
1388 (deactivate-mark)))) | |
1389 | |
1390 (defun f90-block-match (beg-block beg-name end-block end-name) | |
1391 "Match end-struct with beg-struct and complete end-block if possible. | |
1392 Leave point at the end of line." | |
1393 (search-forward "end" (f90-get-end-of-line)) | |
1394 (catch 'no-match | |
1395 (if (not (f90-equal-symbols beg-block end-block)) | |
1396 (if end-block | |
1397 (progn | |
1398 (message "END %s does not match %s." end-block beg-block) | |
1399 (end-of-line) | |
1400 (throw 'no-match nil)) | |
1401 (message "Inserting %s." beg-block) | |
1402 (insert (concat " " beg-block))) | |
1403 (search-forward end-block)) | |
1404 (if (not (f90-equal-symbols beg-name end-name)) | |
1405 (cond ((and beg-name (not end-name)) | |
1406 (message "Inserting %s." beg-name) | |
1407 (insert (concat " " beg-name))) | |
1408 ((and beg-name end-name) | |
1409 (message "Replacing %s with %s." end-name beg-name) | |
1410 (search-forward end-name) | |
1411 (replace-match beg-name)) | |
1412 ((and (not beg-name) end-name) | |
1413 (message "Deleting %s." end-name) | |
1414 (search-forward end-name) | |
1415 (replace-match ""))) | |
1416 (if end-name (search-forward end-name))) | |
1417 (if (not (looking-at "!")) (delete-horizontal-space)))) | |
1418 | |
1419 (defun f90-match-end () | |
1420 "From an end foo statement, find the corresponding foo including name." | |
1421 (interactive) | |
1422 (let ((count 1) (top-of-window (window-start)) (matching-beg nil) | |
1423 (end-point (point)) (case-fold-search t) | |
1424 beg-name end-name beg-block end-block end-struct) | |
1425 (if (save-excursion (beginning-of-line) (skip-chars-forward " \t0-9") | |
1426 (setq end-struct (f90-looking-at-program-block-end))) | |
1427 (progn | |
1428 (setq end-block (car end-struct)) | |
1429 (setq end-name (car (cdr end-struct))) | |
1430 (save-excursion | |
1431 (beginning-of-line) | |
1432 (while (and (not (zerop count)) | |
1433 (re-search-backward | |
1434 (concat "\\(" f90-blocks-re "\\|continue\\)") nil t)) | |
1435 (beginning-of-line) (skip-chars-forward " \t0-9") | |
1436 (cond ((setq matching-beg | |
1437 (cond | |
1438 ((f90-looking-at-do)) | |
1439 ((f90-looking-at-if-then)) | |
1440 ((f90-looking-at-where-or-forall)) | |
1441 ((f90-looking-at-select-case)) | |
1442 ((f90-looking-at-type-like)) | |
1443 ((f90-looking-at-program-block-start)))) | |
1444 (setq count (- count 1))) | |
1445 ((looking-at (concat "end[ \t]*" f90-blocks-re "\\b")) | |
1446 (setq count (+ count 1))) | |
1447 ((looking-at "continue\\>") (setq count (+ count 1))))) | |
1448 (if (not (zerop count)) | |
1449 (message "No matching beginning.") | |
1450 (f90-update-line) | |
1451 (if (eq f90-smart-end 'blink) | |
1452 (if (< (point) top-of-window) | |
1453 (message (concat | |
1454 "Matches " (what-line) ": " | |
1455 (buffer-substring | |
1456 (progn (beginning-of-line) (point)) | |
1457 (progn (end-of-line) (point))))) | |
1458 (sit-for 1))) | |
1459 (setq beg-block (car matching-beg)) | |
1460 (setq beg-name (car (cdr matching-beg))) | |
1461 (goto-char end-point) | |
1462 (beginning-of-line) | |
1463 (f90-block-match beg-block beg-name end-block end-name))))))) | |
1464 | |
1465 (defun f90-insert-end () | |
1466 "Inserts an complete end statement matching beginning of present block." | |
1467 (interactive) | |
1468 (let ((f90-smart-end (if f90-smart-end f90-smart-end 'blink))) | |
1469 (insert "end") | |
1470 (f90-indent-new-line))) | |
1471 | |
1472 ;; abbrevs and keywords | |
1473 | |
1474 (defun f90-abbrev-start () | |
1475 "Typing `\\[help-command] or `? lists all the F90 abbrevs. | |
1476 Any other key combination is executed normally." | |
1477 (interactive) | |
1478 (let (c) | |
1479 (insert last-command-char) | |
1480 (if (or (eq (setq c (if (string-match "Lucid" emacs-version) | |
1481 (event-to-character (next-command-event)) | |
1482 (read-event))) | |
1483 ??) ;insert char if not equal to `?' | |
1484 (eq c help-char)) | |
1485 (f90-abbrev-help) | |
1486 (if (string-match "Lucid" emacs-version) | |
1487 (setq unread-command-event c) | |
1488 (setq unread-command-events (list c)))))) | |
1489 | |
1490 (defun f90-abbrev-help () | |
1491 "List the currently defined abbrevs in F90 mode." | |
1492 (interactive) | |
1493 (message "Listing abbrev table...") | |
1494 (display-buffer (f90-prepare-abbrev-list-buffer)) | |
1495 (message "Listing abbrev table...done")) | |
1496 | |
1497 (defun f90-prepare-abbrev-list-buffer () | |
1498 (save-excursion | |
1499 (set-buffer (get-buffer-create "*Abbrevs*")) | |
1500 (erase-buffer) | |
1501 (insert-abbrev-table-description 'f90-mode-abbrev-table t) | |
1502 (goto-char (point-min)) | |
1503 (set-buffer-modified-p nil) | |
1504 (edit-abbrevs-mode)) | |
1505 (get-buffer-create "*Abbrevs*")) | |
1506 | |
1507 (defun f90-upcase-keywords () | |
1508 "Upcase all F90 keywords in the buffer." | |
1509 (interactive) | |
1510 (f90-change-keywords 'upcase-word)) | |
1511 | |
1512 (defun f90-capitalize-keywords () | |
1513 "Capitalize all F90 keywords in the buffer." | |
1514 (interactive) | |
1515 (f90-change-keywords 'capitalize-word)) | |
1516 | |
1517 (defun f90-downcase-keywords () | |
1518 "Downcase all F90 keywords in the buffer." | |
1519 (interactive) | |
1520 (f90-change-keywords 'downcase-word)) | |
1521 | |
1522 (defun f90-upcase-region-keywords (beg end) | |
1523 "Upcase all F90 keywords in the region." | |
1524 (interactive "*r") | |
1525 (f90-change-keywords 'upcase-word beg end)) | |
1526 | |
1527 (defun f90-capitalize-region-keywords (beg end) | |
1528 "Capitalize all F90 keywords in the region." | |
1529 (interactive "*r") | |
1530 (f90-change-keywords 'capitalize-word beg end)) | |
1531 | |
1532 (defun f90-downcase-region-keywords (beg end) | |
1533 "Downcase all F90 keywords in the region." | |
1534 (interactive "*r") | |
1535 (f90-change-keywords 'downcase-word beg end)) | |
1536 | |
1537 ;; Change the keywords according to argument. | |
1538 (defun f90-change-keywords (change-word &optional beg end) | |
1539 (save-excursion | |
1540 (setq beg (if beg beg (point-min))) | |
1541 (setq end (if end end (point-max))) | |
1542 (let ((keyword-re | |
1543 (concat "\\<\\(" | |
1544 (mapconcat 'identity f90-keywords "\\|") "\\|" | |
1545 (mapconcat 'identity f90-intrinsic-procedures"\\|") "\\|" | |
1546 (mapconcat 'identity f90-hpf-procedures "\\|") "\\|" | |
1547 (mapconcat 'identity f90-hpf-directives "\\|") "\\|" | |
1548 (mapconcat 'identity f90-hpf-keywords "\\|") | |
1549 "\\)\\>")) (ref-point (point-min)) state) | |
1550 (goto-char beg) | |
1551 (while (re-search-forward keyword-re end t) | |
1552 (if (progn | |
1553 (setq state (parse-partial-sexp ref-point (point))) | |
1554 (and (not (nth 3 state)) (not (nth 4 state)))) | |
1555 (progn | |
1556 (setq ref-point (point)) | |
1557 (funcall change-word -1))))))) | |
1558 | |
1559 (provide 'f90) | |
10613 | 1560 |
10612 | 1561 ;;; f90.el ends here |