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