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