1 ;;; f90.el --- Fortran-90 mode (free format)
3 ;; Copyright (C) 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Torbj\"orn Einarsson <Torbjorn.Einarsson@era.ericsson.se>
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
8 ;; Keywords: fortran, f90, languages
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; Major mode for editing F90 programs in FREE FORMAT.
30 ;; The minor language revision F95 is also supported (with font-locking).
32 ;; Knows about continuation lines, named structured statements, and other
33 ;; features in F90 including HPF (High Performance Fortran) structures.
34 ;; The basic feature provides accurate indentation of F90 programs.
35 ;; In addition, there are many more features like automatic matching of all
36 ;; end statements, an auto-fill function to break long lines, a join-lines
37 ;; function which joins continued lines, etc.
39 ;; To facilitate typing, a fairly complete list of abbreviations is provided.
40 ;; All abbreviations begin with the backquote character "`"
41 ;; (this requires modification of the syntax-table).
42 ;; For example, `i expands to integer (if abbrev-mode is on).
44 ;; There are two separate features for altering the appearance of code:
45 ;; 1) Upcasing or capitalizing of all keywords.
46 ;; 2) Colors/fonts using font-lock-mode.
47 ;; Automatic upcase or downcase of keywords is controlled by the variable
48 ;; f90-auto-keyword-case.
50 ;; The indentations of lines starting with ! is determined by the first of the
51 ;; following matches (values in the left column are the defaults):
53 ;; start-string/regexp indent variable holding start-string/regexp
55 ;; !hpf\\$ (re) 0 f90-directive-comment-re
56 ;; !!$ 0 f90-comment-region
57 ;; ! (re) as code f90-indented-comment-re
58 ;; default comment-column
60 ;; Ex: Here is the result of 3 different settings of f90-indented-comment-re
61 ;; f90-indented-comment-re !-indentation !!-indentation
63 ;; !! comment-column as code
64 ;; ![^!] as code comment-column
65 ;; Trailing comments are indented to comment-column with indent-for-comment.
66 ;; The function f90-comment-region toggles insertion of
67 ;; the variable f90-comment-region in every line of the region.
69 ;; One common convention for free vs. fixed format is that free format files
70 ;; have the ending .f90 or .f95 while fixed format files have the ending .f.
71 ;; Emacs automatically loads Fortran files in the appropriate mode based
72 ;; on extension. You can modify this by adjusting the variable auto-mode-alist.
74 ;; (add-to-list 'auto-mode-alist '("\\.f\\'" . f90-mode))
76 ;; Once you have entered f90-mode, you may get more info by using
77 ;; the command describe-mode (C-h m). For online help use
78 ;; C-h f <Name of function you want described>, or
79 ;; C-h v <Name of variable you want described>.
81 ;; To customize f90-mode for your taste, use, for example:
82 ;; (you don't have to specify values for all the parameters below)
84 ;;(add-hook 'f90-mode-hook
85 ;; ;; These are the default values.
86 ;; '(lambda () (setq f90-do-indent 3
89 ;; f90-program-indent 2
90 ;; f90-continuation-indent 5
91 ;; f90-comment-region "!!$"
92 ;; f90-directive-comment-re "!hpf\\$"
93 ;; f90-indented-comment-re "!"
94 ;; f90-break-delimiters "[-+\\*/><=,% \t]"
95 ;; f90-break-before-delimiters t
96 ;; f90-beginning-ampersand t
97 ;; f90-smart-end 'blink
98 ;; f90-auto-keyword-case nil
99 ;; f90-leave-line-no nil
100 ;; indent-tabs-mode nil
101 ;; f90-font-lock-keywords f90-font-lock-keywords-2
103 ;; ;; These are not default.
104 ;; (abbrev-mode 1) ; turn on abbreviation mode
105 ;; (f90-add-imenu-menu) ; extra menu with functions etc.
106 ;; (if f90-auto-keyword-case ; change case of all keywords on startup
107 ;; (f90-change-keywords f90-auto-keyword-case))
110 ;; in your .emacs file. You can also customize the lists
111 ;; f90-font-lock-keywords, etc.
113 ;; The auto-fill and abbreviation minor modes are accessible from the F90 menu,
114 ;; or by using M-x auto-fill-mode and M-x abbrev-mode, respectively.
117 ;; 1) Line numbers are by default left-justified. If f90-leave-line-no is
118 ;; non-nil, the line numbers are never touched.
119 ;; 2) Multi-; statements like "do i=1,20 ; j=j+i ; end do" are not handled
120 ;; correctly, but I imagine them to be rare.
121 ;; 3) Regexps for hilit19 are no longer supported.
122 ;; 4) For FIXED FORMAT code, use fortran mode.
123 ;; 5) This mode does not work under emacs-18.x.
124 ;; 6) Preprocessor directives, i.e., lines starting with # are left-justified
125 ;; and are untouched by all case-changing commands. There is, at present, no
126 ;; mechanism for treating multi-line directives (continued by \ ).
127 ;; 7) f77 do-loops do 10 i=.. ; ; 10 continue are not correctly indented.
128 ;; You are urged to use f90-do loops (with labels if you wish).
129 ;; 8) The highlighting mode under XEmacs is not as complete as under Emacs.
131 ;; List of user commands
132 ;; f90-previous-statement f90-next-statement
133 ;; f90-beginning-of-subprogram f90-end-of-subprogram f90-mark-subprogram
134 ;; f90-comment-region
135 ;; f90-indent-line f90-indent-new-line
136 ;; f90-indent-region (can be called by calling indent-region)
137 ;; f90-indent-subprogram
138 ;; f90-break-line f90-join-lines
141 ;; f90-upcase-keywords f90-upcase-region-keywords
142 ;; f90-downcase-keywords f90-downcase-region-keywords
143 ;; f90-capitalize-keywords f90-capitalize-region-keywords
144 ;; f90-add-imenu-menu
145 ;; f90-font-lock-1, f90-font-lock-2, f90-font-lock-3, f90-font-lock-4
147 ;; Original author's thanks
148 ;; Thanks to all the people who have tested the mode. Special thanks to Jens
149 ;; Bloch Helmers for encouraging me to write this code, for creative
150 ;; suggestions as well as for the lists of hpf-commands.
151 ;; Also thanks to the authors of the fortran and pascal modes, on which some
152 ;; of this code is built.
157 ;; Support for align.
158 ;; OpenMP, preprocessor highlighting.
160 (defvar comment-auto-fill-only-comments
)
161 (defvar font-lock-keywords
)
166 "Major mode for editing free format Fortran 90,95 code."
167 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
170 (defgroup f90-indent nil
171 "Indentation in free format Fortran."
176 (defcustom f90-do-indent
3
177 "*Extra indentation applied to DO blocks."
180 (put 'f90-do-indent
'safe-local-variable
'integerp
)
182 (defcustom f90-if-indent
3
183 "*Extra indentation applied to IF, SELECT CASE, WHERE and FORALL blocks."
186 (put 'f90-if-indent
'safe-local-variable
'integerp
)
188 (defcustom f90-type-indent
3
189 "*Extra indentation applied to TYPE, INTERFACE and BLOCK DATA blocks."
192 (put 'f90-type-indent
'safe-local-variable
'integerp
)
194 (defcustom f90-program-indent
2
195 "*Extra indentation applied to PROGRAM, MODULE, SUBROUTINE, FUNCTION blocks."
198 (put 'f90-program-indent
'safe-local-variable
'integerp
)
200 (defcustom f90-continuation-indent
5
201 "*Extra indentation applied to continuation lines."
204 (put 'f90-continuation-indent
'safe-local-variable
'integerp
)
206 (defcustom f90-comment-region
"!!$"
207 "*String inserted by \\[f90-comment-region] at start of each line in region."
210 (put 'f90-comment-region
'safe-local-variable
'stringp
)
212 (defcustom f90-indented-comment-re
"!"
213 "*Regexp matching comments to indent as code."
216 (put 'f90-indented-comment-re
'safe-local-variable
'stringp
)
218 (defcustom f90-directive-comment-re
"!hpf\\$"
219 "*Regexp of comment-like directive like \"!HPF\\\\$\", not to be indented."
222 (put 'f90-directive-comment-re
'safe-local-variable
'stringp
)
224 (defcustom f90-beginning-ampersand t
225 "*Non-nil gives automatic insertion of \& at start of continuation line."
228 (put 'f90-beginning-ampersand
'safe-local-variable
'booleanp
)
230 (defcustom f90-smart-end
'blink
231 "*Qualification of END statements according to the matching block start.
232 For example, the END that closes an IF block is changed to END
233 IF. If the block has a label, this is added as well. Allowed
234 values are 'blink, 'no-blink, and nil. If nil, nothing is done.
235 The other two settings have the same effect, but 'blink
236 additionally blinks the cursor to the start of the block."
237 :type
'(choice (const blink
) (const no-blink
) (const nil
))
239 (put 'f90-smart-end
'safe-local-variable
240 (lambda (value) (memq value
'(blink no-blink nil
))))
242 (defcustom f90-break-delimiters
"[-+\\*/><=,% \t]"
243 "*Regexp matching delimiter characters at which lines may be broken.
244 There are certain tokens comprised entirely of characters
245 matching this regexp that should not be split, and these are
246 specified by the constant `f90-no-break-re'."
249 (put 'f90-break-delimiters
'safe-local-variable
'stringp
)
251 (defcustom f90-break-before-delimiters t
252 "*Non-nil causes `f90-do-auto-fill' to break lines before delimiters."
255 (put 'f90-break-before-delimiters
'safe-local-variable
'booleanp
)
257 (defcustom f90-auto-keyword-case nil
258 "*Automatic case conversion of keywords.
259 The options are 'downcase-word, 'upcase-word, 'capitalize-word and nil."
260 :type
'(choice (const downcase-word
) (const upcase-word
)
261 (const capitalize-word
) (const nil
))
263 (put 'f90-auto-keyword-case
'safe-local-variable
264 (lambda (value) (memq value
'(downcase-word
265 capitalize-word upcase-word nil
))))
267 (defcustom f90-leave-line-no nil
268 "*If non-nil, line numbers are not left justified."
271 (put 'f90-leave-line-no
'safe-local-variable
'booleanp
)
273 (defcustom f90-mode-hook nil
274 "Hook run when entering F90 mode."
276 :options
'(f90-add-imenu-menu)
278 (put 'f90-mode-hook
'safe-local-variable
279 (lambda (value) (member value
'((f90-add-imenu-menu) nil
))))
281 ;; User options end here.
283 (defconst f90-keywords-re
284 (regexp-opt '("allocatable" "allocate" "assign" "assignment" "backspace"
285 "block" "call" "case" "character" "close" "common" "complex"
286 "contains" "continue" "cycle" "data" "deallocate"
287 "dimension" "do" "double" "else" "elseif" "elsewhere" "end"
288 "enddo" "endfile" "endif" "entry" "equivalence" "exit"
289 "external" "forall" "format" "function" "goto" "if"
290 "implicit" "include" "inquire" "integer" "intent"
291 "interface" "intrinsic" "logical" "module" "namelist" "none"
292 "nullify" "only" "open" "operator" "optional" "parameter"
293 "pause" "pointer" "precision" "print" "private" "procedure"
294 "program" "public" "read" "real" "recursive" "result" "return"
295 "rewind" "save" "select" "sequence" "stop" "subroutine"
296 "target" "then" "type" "use" "where" "while" "write"
298 "elemental" "pure") 'words
)
299 "Regexp used by the function `f90-change-keywords'.")
301 (defconst f90-keywords-level-3-re
303 '("allocatable" "allocate" "assign" "assignment" "backspace"
304 "close" "deallocate" "dimension" "endfile" "entry" "equivalence"
305 "external" "inquire" "intent" "intrinsic" "nullify" "only" "open"
306 "operator" "optional" "parameter" "pause" "pointer" "print" "private"
307 "public" "read" "recursive" "result" "rewind" "save" "select"
308 "sequence" "target" "write"
310 "elemental" "pure") 'words
)
311 "Keyword-regexp for font-lock level >= 3.")
313 (defconst f90-procedures-re
316 '("abs" "achar" "acos" "adjustl" "adjustr" "aimag" "aint"
317 "all" "allocated" "anint" "any" "asin" "associated"
318 "atan" "atan2" "bit_size" "btest" "ceiling" "char" "cmplx"
319 "conjg" "cos" "cosh" "count" "cshift" "date_and_time" "dble"
320 "digits" "dim" "dot_product" "dprod" "eoshift" "epsilon"
321 "exp" "exponent" "floor" "fraction" "huge" "iachar" "iand"
322 "ibclr" "ibits" "ibset" "ichar" "ieor" "index" "int" "ior"
323 "ishft" "ishftc" "kind" "lbound" "len" "len_trim" "lge" "lgt"
324 "lle" "llt" "log" "log10" "logical" "matmul" "max"
325 "maxexponent" "maxloc" "maxval" "merge" "min" "minexponent"
326 "minloc" "minval" "mod" "modulo" "mvbits" "nearest" "nint"
327 "not" "pack" "precision" "present" "product" "radix"
328 ;; Real is taken out here to avoid highlighting declarations.
329 "random_number" "random_seed" "range" ;; "real"
330 "repeat" "reshape" "rrspacing" "scale" "scan"
331 "selected_int_kind" "selected_real_kind" "set_exponent"
332 "shape" "sign" "sin" "sinh" "size" "spacing" "spread" "sqrt"
333 "sum" "system_clock" "tan" "tanh" "tiny" "transfer"
334 "transpose" "trim" "ubound" "unpack" "verify"
335 ;; F95 intrinsic functions.
336 "null" "cpu_time") t
)
337 ;; A left parenthesis to avoid highlighting non-procedures.
339 "Regexp whose first part matches F90 intrinsic procedures.")
341 (defconst f90-operators-re
343 (regexp-opt '("and" "eq" "eqv" "false" "ge" "gt" "le" "lt" "ne"
344 "neqv" "not" "or" "true") t
)
346 "Regexp matching intrinsic operators.")
348 (defconst f90-hpf-keywords-re
350 ;; Intrinsic procedures.
351 '("all_prefix" "all_scatter" "all_suffix" "any_prefix"
352 "any_scatter" "any_suffix" "copy_prefix" "copy_scatter"
353 "copy_suffix" "count_prefix" "count_scatter" "count_suffix"
354 "grade_down" "grade_up"
355 "hpf_alignment" "hpf_distribution" "hpf_template" "iall" "iall_prefix"
356 "iall_scatter" "iall_suffix" "iany" "iany_prefix" "iany_scatter"
357 "iany_suffix" "ilen" "iparity" "iparity_prefix"
358 "iparity_scatter" "iparity_suffix" "leadz" "maxval_prefix"
359 "maxval_scatter" "maxval_suffix" "minval_prefix" "minval_scatter"
360 "minval_suffix" "number_of_processors" "parity"
361 "parity_prefix" "parity_scatter" "parity_suffix" "popcnt" "poppar"
362 "processors_shape" "product_prefix" "product_scatter"
363 "product_suffix" "sum_prefix" "sum_scatter" "sum_suffix"
365 "align" "distribute" "dynamic" "independent" "inherit" "processors"
366 "realign" "redistribute" "template"
368 "block" "cyclic" "extrinsic" "new" "onto" "pure" "with") 'words
)
369 "Regexp for all HPF keywords, procedures and directives.")
371 ;; Highlighting patterns.
373 (defvar f90-font-lock-keywords-1
375 ;; Special highlighting of "module procedure".
376 '("\\<\\(module[ \t]*procedure\\)\\>" (1 font-lock-keyword-face
))
377 ;; Highlight definition of derived type.
378 '("\\<\\(\\(?:end[ \t]*\\)?type\\)\\>\\([^()\n]*::\\)?[ \t]*\\(\\sw+\\)"
379 (1 font-lock-keyword-face
) (3 font-lock-function-name-face
))
380 ;; Other functions and declarations.
381 '("\\<\\(\\(?:end[ \t]*\\)?\\(program\\|module\\|function\\|\
382 subroutine\\)\\|use\\|call\\)\\>[ \t]*\\(\\sw+\\)?"
383 (1 font-lock-keyword-face
) (3 font-lock-function-name-face nil t
))
384 "\\<\\(\\(end[ \t]*\\)?\\(interface\\|block[ \t]*data\\)\\|contains\\)\\>")
385 "This does fairly subdued highlighting of comments and function calls.")
387 (defvar f90-font-lock-keywords-2
389 f90-font-lock-keywords-1
391 ;; Variable declarations (avoid the real function call).
392 '("^[ \t0-9]*\\(real\\|integer\\|c\\(haracter\\|omplex\\)\\|\
393 logical\\|double[ \t]*precision\\|type[ \t]*(\\sw+)\\)\
394 \\(.*::\\|[ \t]*(.*)\\)?\\([^&!\n]*\\)"
395 (1 font-lock-type-face t
) (4 font-lock-variable-name-face t
))
396 ;; do, if, select, where, and forall constructs.
397 '("\\<\\(end[ \t]*\\(do\\|if\\|select\\|forall\\|where\\)\\)\\>\
398 \\([ \t]+\\(\\sw+\\)\\)?"
399 (1 font-lock-keyword-face
) (3 font-lock-constant-face nil t
))
400 '("^[ \t0-9]*\\(\\(\\sw+\\)[ \t]*:[ \t]*\\)?\\(\\(if\\|\
401 do\\([ \t]*while\\)?\\|select[ \t]*case\\|where\\|forall\\)\\)\\>"
402 (2 font-lock-constant-face nil t
) (3 font-lock-keyword-face
))
403 ;; Implicit declaration.
404 '("\\<\\(implicit\\)[ \t]*\\(real\\|integer\\|c\\(haracter\\|omplex\\)\
405 \\|logical\\|double[ \t]*precision\\|type[ \t]*(\\sw+)\\|none\\)[ \t]*"
406 (1 font-lock-keyword-face
) (2 font-lock-type-face
))
407 '("\\<\\(namelist\\|common\\)[ \t]*\/\\(\\sw+\\)?\/"
408 (1 font-lock-keyword-face
) (2 font-lock-constant-face nil t
))
409 "\\<else\\([ \t]*if\\|where\\)?\\>"
410 '("\\(&\\)[ \t]*\\(!\\|$\\)" (1 font-lock-keyword-face
))
411 "\\<\\(then\\|continue\\|format\\|include\\|stop\\|return\\)\\>"
412 '("\\<\\(exit\\|cycle\\)[ \t]*\\(\\sw+\\)?\\>"
413 (1 font-lock-keyword-face
) (2 font-lock-constant-face nil t
))
414 '("\\<\\(case\\)[ \t]*\\(default\\|(\\)" .
1)
415 '("\\<\\(do\\|go[ \t]*to\\)\\>[ \t]*\\([0-9]+\\)"
416 (1 font-lock-keyword-face
) (2 font-lock-constant-face
))
417 ;; Line numbers (lines whose first character after number is letter).
418 '("^[ \t]*\\([0-9]+\\)[ \t]*[a-z]+" (1 font-lock-constant-face t
))))
419 "Highlights declarations, do-loops and other constructs.")
421 (defvar f90-font-lock-keywords-3
422 (append f90-font-lock-keywords-2
424 f90-keywords-level-3-re
426 (list f90-procedures-re
'(1 font-lock-keyword-face keep
))
427 "\\<real\\>" ; avoid overwriting real defs
429 "Highlights all F90 keywords and intrinsic procedures.")
431 (defvar f90-font-lock-keywords-4
432 (append f90-font-lock-keywords-3
433 (list f90-hpf-keywords-re
))
434 "Highlights all F90 and HPF keywords.")
436 (defvar f90-font-lock-keywords
437 f90-font-lock-keywords-2
438 "*Default expressions to highlight in F90 mode.
439 Can be overridden by the value of `font-lock-maximum-decoration'.")
442 (defvar f90-mode-syntax-table
443 (let ((table (make-syntax-table)))
444 (modify-syntax-entry ?\
! "<" table
) ; begin comment
445 (modify-syntax-entry ?
\n ">" table
) ; end comment
446 (modify-syntax-entry ?_
"w" table
) ; underscore in names
447 (modify-syntax-entry ?
\' "\"" table
) ; string quote
448 (modify-syntax-entry ?
\" "\"" table
) ; string quote
449 (modify-syntax-entry ?\
` "w" table
) ; for abbrevs
450 (modify-syntax-entry ?
\r " " table
) ; return is whitespace
451 (modify-syntax-entry ?
+ "." table
) ; punctuation
452 (modify-syntax-entry ?-
"." table
)
453 (modify-syntax-entry ?
= "." table
)
454 (modify-syntax-entry ?
* "." table
)
455 (modify-syntax-entry ?
/ "." table
)
456 ;; I think that the f95 standard leaves the behaviour of \
457 ;; unspecified, but that f2k will require it to be non-special.
458 ;; Use `f90-backslash-not-special' to change.
459 (modify-syntax-entry ?
\\ "\\" table
) ; escape chars
461 "Syntax table used in F90 mode.")
464 (let ((map (make-sparse-keymap)))
465 (define-key map
"`" 'f90-abbrev-start
)
466 (define-key map
"\C-c;" 'f90-comment-region
)
467 (define-key map
"\C-\M-a" 'f90-beginning-of-subprogram
)
468 (define-key map
"\C-\M-e" 'f90-end-of-subprogram
)
469 (define-key map
"\C-\M-h" 'f90-mark-subprogram
)
470 (define-key map
"\C-\M-n" 'f90-end-of-block
)
471 (define-key map
"\C-\M-p" 'f90-beginning-of-block
)
472 (define-key map
"\C-\M-q" 'f90-indent-subprogram
)
473 (define-key map
"\C-j" 'f90-indent-new-line
) ; LFD equals C-j
474 (define-key map
"\r" 'newline
)
475 (define-key map
"\C-c\r" 'f90-break-line
)
476 ;;; (define-key map [M-return] 'f90-break-line)
477 (define-key map
"\C-c\C-a" 'f90-previous-block
)
478 (define-key map
"\C-c\C-e" 'f90-next-block
)
479 (define-key map
"\C-c\C-d" 'f90-join-lines
)
480 (define-key map
"\C-c\C-f" 'f90-fill-region
)
481 (define-key map
"\C-c\C-p" 'f90-previous-statement
)
482 (define-key map
"\C-c\C-n" 'f90-next-statement
)
483 (define-key map
"\C-c\C-w" 'f90-insert-end
)
484 (define-key map
"\t" 'f90-indent-line
)
485 (define-key map
"," 'f90-electric-insert
)
486 (define-key map
"+" 'f90-electric-insert
)
487 (define-key map
"-" 'f90-electric-insert
)
488 (define-key map
"*" 'f90-electric-insert
)
489 (define-key map
"/" 'f90-electric-insert
)
491 (easy-menu-define f90-menu map
"Menu for F90 mode."
494 ,(custom-menu-create 'f90
)
496 ["Save" Custom-save t
]
497 ["Reset to Current" Custom-reset-current t
]
498 ["Reset to Saved" Custom-reset-saved t
]
499 ["Reset to Standard Settings" Custom-reset-standard t
]
502 ["Indent Subprogram" f90-indent-subprogram t
]
503 ["Mark Subprogram" f90-mark-subprogram t
]
504 ["Beginning of Subprogram" f90-beginning-of-subprogram t
]
505 ["End of Subprogram" f90-end-of-subprogram t
]
507 ["(Un)Comment Region" f90-comment-region mark-active
]
508 ["Indent Region" f90-indent-region mark-active
]
509 ["Fill Region" f90-fill-region mark-active
]
511 ["Break Line at Point" f90-break-line t
]
512 ["Join with Previous Line" f90-join-lines t
]
513 ["Insert Block End" f90-insert-end t
]
516 ["Toggle font-lock-mode" font-lock-mode
:selected font-lock-mode
519 ["Light highlighting (level 1)" f90-font-lock-1 t
]
520 ["Moderate highlighting (level 2)" f90-font-lock-2 t
]
521 ["Heavy highlighting (level 3)" f90-font-lock-3 t
]
522 ["Maximum highlighting (level 4)" f90-font-lock-4 t
]
524 ("Change Keyword Case"
525 ["Upcase Keywords (buffer)" f90-upcase-keywords t
]
526 ["Capitalize Keywords (buffer)" f90-capitalize-keywords t
]
527 ["Downcase Keywords (buffer)" f90-downcase-keywords t
]
529 ["Upcase Keywords (region)" f90-upcase-region-keywords
531 ["Capitalize Keywords (region)" f90-capitalize-region-keywords
533 ["Downcase Keywords (region)" f90-downcase-region-keywords
537 ["Toggle auto-fill" auto-fill-mode
:selected auto-fill-function
539 ["Toggle abbrev-mode" abbrev-mode
:selected abbrev-mode
541 ["Add imenu Menu" f90-add-imenu-menu
542 :active
(not (lookup-key (current-local-map) [menu-bar index
]))
543 :included
(fboundp 'imenu-add-to-menubar
)]))
545 "Keymap used in F90 mode.")
548 (defun f90-font-lock-1 ()
549 "Set `font-lock-keywords' to `f90-font-lock-keywords-1'."
552 (setq font-lock-keywords f90-font-lock-keywords-1
)
553 (font-lock-fontify-buffer))
555 (defun f90-font-lock-2 ()
556 "Set `font-lock-keywords' to `f90-font-lock-keywords-2'."
559 (setq font-lock-keywords f90-font-lock-keywords-2
)
560 (font-lock-fontify-buffer))
562 (defun f90-font-lock-3 ()
563 "Set `font-lock-keywords' to `f90-font-lock-keywords-3'."
566 (setq font-lock-keywords f90-font-lock-keywords-3
)
567 (font-lock-fontify-buffer))
569 (defun f90-font-lock-4 ()
570 "Set `font-lock-keywords' to `f90-font-lock-keywords-4'."
573 (setq font-lock-keywords f90-font-lock-keywords-4
)
574 (font-lock-fontify-buffer))
577 ;; Regexps for finding program structures.
578 (defconst f90-blocks-re
579 (concat "\\(block[ \t]*data\\|"
580 (regexp-opt '("do" "if" "interface" "function" "module" "program"
581 "select" "subroutine" "type" "where" "forall"))
583 "Regexp potentially indicating a \"block\" of F90 code.")
585 (defconst f90-program-block-re
586 (regexp-opt '("program" "module" "subroutine" "function") 'paren
)
587 "Regexp used to locate the start/end of a \"subprogram\".")
589 (defconst f90-else-like-re
590 "\\(else\\([ \t]*if\\|where\\)?\\|case[ \t]*\\(default\\|(\\)\\)"
591 "Regexp matching an ELSE IF, ELSEWHERE, CASE statement.")
593 (defconst f90-end-if-re
595 (regexp-opt '("if" "select" "where" "forall") 'paren
)
597 "Regexp matching the end of an IF, SELECT, WHERE, FORALL block.")
599 (defconst f90-end-type-re
600 "end[ \t]*\\(type\\|interface\\|block[ \t]*data\\)\\>"
601 "Regexp matching the end of a TYPE, INTERFACE, BLOCK DATA section.")
603 (defconst f90-type-def-re
604 "\\<\\(type\\)\\>\\(?:[^()\n]*::\\)?[ \t]*\\(\\sw+\\)"
605 "Regexp matching the definition of a derived type.")
607 (defconst f90-no-break-re
608 (regexp-opt '("**" "//" "=>" ">=" "<=" "==" "/=") 'paren
)
609 "Regexp specifying where not to break lines when filling.
610 This regexp matches certain tokens comprised entirely of
611 characters matching the regexp `f90-break-delimiters' that should
612 not be split by filling. Each element is assumed to be two
615 (defvar f90-cache-position nil
616 "Temporary position used to speed up region operations.")
617 (make-variable-buffer-local 'f90-cache-position
)
621 (defconst f90-end-block-re
622 (concat "^[ \t0-9]*\\<end[ \t]*"
623 (regexp-opt '("do" "if" "forall" "function" "interface"
624 "module" "program" "select" "subroutine"
627 "Regexp matching the end of an F90 \"block\", from the line start.
628 Used in the F90 entry in `hs-special-modes-alist'.")
630 ;; Ignore the fact that FUNCTION, SUBROUTINE, WHERE, FORALL have a
631 ;; following "(". DO, CASE, IF can have labels.
632 (defconst f90-start-block-re
634 "^[ \t0-9]*" ; statement number
636 "\\(\\sw+[ \t]*:[ \t]*\\)?" ; structure label
637 "\\(do\\|select[ \t]*case\\|"
638 ;; See comments in fortran-start-block-re for the problems of IF.
640 ".*\n\\([^if]*\\([^i].\\|.[^f]\\|.\\>\\)\\)\\)\\<then\\|"
641 ;; Distinguish WHERE block from isolated WHERE.
642 "\\(where\\|forall\\)[ \t]*(.*)[ \t]*\\(!\\|$\\)\\)\\)"
644 "program\\|interface\\|module\\|type\\|function\\|subroutine"
647 "Regexp matching the start of an F90 \"block\", from the line start.
648 A simple regexp cannot do this in fully correct fashion, so this
649 tries to strike a compromise between complexity and flexibility.
650 Used in the F90 entry in `hs-special-modes-alist'.")
652 ;; hs-special-modes-alist is autoloaded.
653 (add-to-list 'hs-special-modes-alist
654 `(f90-mode ,f90-start-block-re
,f90-end-block-re
655 "!" f90-end-of-block nil
))
659 (defvar f90-imenu-generic-expression
660 (let ((good-char "[^!\"\&\n \t]") (not-e "[^e!\n\"\& \t]")
661 (not-n "[^n!\n\"\& \t]") (not-d "[^d!\n\"\& \t]"))
663 '(nil "^[ \t0-9]*program[ \t]+\\(\\sw+\\)" 1)
664 '("Modules" "^[ \t0-9]*module[ \t]+\\(\\sw+\\)[ \t]*\\(!\\|$\\)" 1)
665 '("Types" "^[ \t0-9]*type[ \t]+\\(\\sw+\\)" 1)
671 ;; At least three non-space characters before function/subroutine.
672 ;; Check that the last three non-space characters do not spell E N D.
674 not-e good-char good-char
"\\|"
675 good-char not-n good-char
"\\|"
676 good-char good-char not-d
"\\)"
678 ;; Less than three non-space characters before function/subroutine.
679 good-char
"?" good-char
"?"
681 "[ \t]*\\(function\\|subroutine\\)[ \t]+\\(\\sw+\\)")
683 "Value for `imenu-generic-expression' in F90 mode.")
685 (defun f90-add-imenu-menu ()
686 "Add an imenu menu to the menubar."
688 (if (lookup-key (current-local-map) [menu-bar index
])
689 (message "%s" "F90-imenu already exists.")
690 (imenu-add-to-menubar "F90-imenu")
691 (redraw-frame (selected-frame))))
694 ;; Abbrevs have generally two letters, except standard types `c, `i, `r, `t.
695 (defvar f90-mode-abbrev-table
697 (define-abbrev-table 'f90-mode-abbrev-table nil
)
698 f90-mode-abbrev-table
)
699 "Abbrev table for F90 mode.")
701 (let (abbrevs-changed)
702 ;; Use the 6th arg (SYSTEM-FLAG) of define-abbrev if possible.
703 ;; A little baroque to quieten the byte-compiler.
705 (function (lambda (element)
707 (apply 'define-abbrev f90-mode-abbrev-table
708 (append element
'(nil 0 t
)))
709 (wrong-number-of-arguments
710 (apply 'define-abbrev f90-mode-abbrev-table
711 (append element
'(nil 0)))))))
712 '(("`al" "allocate" )
713 ("`ab" "allocatable" )
714 ("`as" "assignment" )
716 ("`bd" "block data" )
723 ("`de" "deallocate" )
726 ("`dp" "double precision")
730 ("`elw" "elsewhere" )
731 ("`eq" "equivalence" )
738 ("`im" "implicit none")
760 ("`su" "subroutine" )
770 "Major mode for editing Fortran 90,95 code in free format.
771 For fixed format code, use `fortran-mode'.
773 \\[f90-indent-line] indents the current line.
774 \\[f90-indent-new-line] indents current line and creates a new\
776 \\[f90-indent-subprogram] indents the current subprogram.
778 Type `? or `\\[help-command] to display a list of built-in\
779 abbrevs for F90 keywords.
784 Variables controlling indentation style and extra features:
787 Extra indentation within do blocks (default 3).
789 Extra indentation within if/select case/where/forall blocks (default 3).
791 Extra indentation within type/interface/block-data blocks (default 3).
793 Extra indentation within program/module/subroutine/function blocks
795 `f90-continuation-indent'
796 Extra indentation applied to continuation lines (default 5).
798 String inserted by function \\[f90-comment-region] at start of each
799 line in region (default \"!!!$\").
800 `f90-indented-comment-re'
801 Regexp determining the type of comment to be intended like code
803 `f90-directive-comment-re'
804 Regexp of comment-like directive like \"!HPF\\\\$\", not to be indented
805 (default \"!hpf\\\\$\").
806 `f90-break-delimiters'
807 Regexp holding list of delimiters at which lines may be broken
808 (default \"[-+*/><=,% \\t]\").
809 `f90-break-before-delimiters'
810 Non-nil causes `f90-do-auto-fill' to break lines before delimiters
812 `f90-beginning-ampersand'
813 Automatic insertion of \& at beginning of continuation lines (default t).
815 From an END statement, check and fill the end using matching block start.
816 Allowed values are 'blink, 'no-blink, and nil, which determine
817 whether to blink the matching beginning (default 'blink).
818 `f90-auto-keyword-case'
819 Automatic change of case of keywords (default nil).
820 The possibilities are 'downcase-word, 'upcase-word, 'capitalize-word.
822 Do not left-justify line numbers (default nil).
824 Turning on F90 mode calls the value of the variable `f90-mode-hook'
825 with no args, if that value is non-nil."
827 (kill-all-local-variables)
828 (setq major-mode
'f90-mode
830 local-abbrev-table f90-mode-abbrev-table
)
831 (set-syntax-table f90-mode-syntax-table
)
832 (use-local-map f90-mode-map
)
833 (set (make-local-variable 'indent-line-function
) 'f90-indent-line
)
834 (set (make-local-variable 'indent-region-function
) 'f90-indent-region
)
835 (set (make-local-variable 'require-final-newline
) mode-require-final-newline
)
836 (set (make-local-variable 'comment-start
) "!")
837 (set (make-local-variable 'comment-start-skip
) "!+ *")
838 (set (make-local-variable 'comment-indent-function
) 'f90-comment-indent
)
839 (set (make-local-variable 'abbrev-all-caps
) t
)
840 (set (make-local-variable 'normal-auto-fill-function
) 'f90-do-auto-fill
)
841 (setq indent-tabs-mode nil
) ; auto buffer local
842 (set (make-local-variable 'font-lock-defaults
)
843 '((f90-font-lock-keywords f90-font-lock-keywords-1
844 f90-font-lock-keywords-2
845 f90-font-lock-keywords-3
846 f90-font-lock-keywords-4
)
848 (set (make-local-variable 'imenu-case-fold-search
) t
)
849 (set (make-local-variable 'imenu-generic-expression
)
850 f90-imenu-generic-expression
)
851 (set (make-local-variable 'beginning-of-defun-function
)
852 'f90-beginning-of-subprogram
)
853 (set (make-local-variable 'end-of-defun-function
) 'f90-end-of-subprogram
)
854 (set (make-local-variable 'add-log-current-defun-function
)
856 (run-mode-hooks 'f90-mode-hook
))
860 (defsubst f90-in-string
()
861 "Return non-nil if point is inside a string.
862 Checks from `point-min', or `f90-cache-position', if that is non-nil
863 and lies before point."
865 (if (and f90-cache-position
(> (point) f90-cache-position
))
868 (nth 3 (parse-partial-sexp beg-pnt
(point)))))
870 (defsubst f90-in-comment
()
871 "Return non-nil if point is inside a comment.
872 Checks from `point-min', or `f90-cache-position', if that is non-nil
873 and lies before point."
875 (if (and f90-cache-position
(> (point) f90-cache-position
))
878 (nth 4 (parse-partial-sexp beg-pnt
(point)))))
880 (defsubst f90-line-continued
()
881 "Return t if the current line is a continued one.
882 This includes comment lines embedded in continued lines, but
883 not the last line of a continued statement."
886 (while (and (looking-at "[ \t]*\\(!\\|$\\)") (zerop (forward-line -
1))))
888 (while (f90-in-comment)
889 (search-backward "!" (line-beginning-position))
890 (skip-chars-backward "!"))
891 (skip-chars-backward " \t")
892 (= (preceding-char) ?
&)))
894 ;; GM this is not right, eg a continuation line starting with a number.
895 ;; Need f90-code-start-position function.
896 ;; And yet, things seems to work with this...
897 ;; cf f90-indent-line
898 ;; (beginning-of-line) ; digits after & \n are not line-nos
899 ;; (if (not (save-excursion (and (f90-previous-statement)
900 ;; (f90-line-continued))))
901 ;; (f90-indent-line-no)
902 (defsubst f90-current-indentation
()
903 "Return indentation of current line.
904 Line-numbers are considered whitespace characters."
905 (save-excursion (beginning-of-line) (skip-chars-forward " \t0-9")))
907 (defsubst f90-indent-to
(col &optional no-line-number
)
908 "Indent current line to column COL.
909 If optional argument NO-LINE-NUMBER is nil, jump over a possible
910 line-number before indenting."
913 (skip-chars-forward " \t0-9"))
914 (delete-horizontal-space)
915 ;; Leave >= 1 space after line number.
916 (indent-to col
(if (zerop (current-column)) 0 1)))
918 (defsubst f90-get-present-comment-type
()
919 "If point lies within a comment, return the string starting the comment.
920 For example, \"!\" or \"!!\", followed by the appropriate amount of
922 ;; Include the whitespace for consistent auto-filling of comment blocks.
924 (when (f90-in-comment)
926 (re-search-forward "!+[ \t]*" (line-end-position))
927 (while (f90-in-string)
928 (re-search-forward "!+[ \t]*" (line-end-position)))
929 (match-string-no-properties 0))))
931 (defsubst f90-equal-symbols
(a b
)
932 "Compare strings A and B neglecting case and allowing for nil value."
933 (equal (if a
(downcase a
) nil
)
934 (if b
(downcase b
) nil
)))
936 (defsubst f90-looking-at-do
()
937 "Return (\"do\" NAME) if a do statement starts after point.
938 NAME is nil if the statement has no label."
939 (if (looking-at "\\(\\(\\sw+\\)[ \t]*:\\)?[ \t]*\\(do\\)\\>")
940 (list (match-string 3) (match-string 2))))
942 (defsubst f90-looking-at-select-case
()
943 "Return (\"select\" NAME) if a select-case statement starts after point.
944 NAME is nil if the statement has no label."
945 (if (looking-at "\\(\\(\\sw+\\)[ \t]*:\\)?[ \t]*\
946 \\(select\\)[ \t]*case[ \t]*(")
947 (list (match-string 3) (match-string 2))))
949 (defsubst f90-looking-at-if-then
()
950 "Return (\"if\" NAME) if an if () then statement starts after point.
951 NAME is nil if the statement has no label."
953 (when (looking-at "\\(\\(\\sw+\\)[ \t]*:\\)?[ \t]*\\(if\\)\\>")
954 (let ((struct (match-string 3))
955 (label (match-string 2))
956 (pos (scan-lists (point) 1 0)))
957 (and pos
(goto-char pos
))
958 (skip-chars-forward " \t")
959 (if (or (looking-at "then\\>")
960 (when (f90-line-continued)
962 (skip-chars-forward " \t0-9&")
963 (looking-at "then\\>")))
964 (list struct label
))))))
966 (defsubst f90-looking-at-where-or-forall
()
967 "Return (KIND NAME) if a where or forall block starts after point.
968 NAME is nil if the statement has no label."
970 (when (looking-at "\\(\\(\\sw+\\)[ \t]*:\\)?[ \t]*\
971 \\(where\\|forall\\)\\>")
972 (let ((struct (match-string 3))
973 (label (match-string 2))
974 (pos (scan-lists (point) 1 0)))
975 (and pos
(goto-char pos
))
976 (skip-chars-forward " \t")
977 (if (looking-at "\\(!\\|$\\)") (list struct label
))))))
979 (defsubst f90-looking-at-type-like
()
980 "Return (KIND NAME) if a type/interface/block-data block starts after point.
981 NAME is non-nil only for type."
983 ((looking-at f90-type-def-re
)
984 (list (match-string 1) (match-string 2)))
985 ((looking-at "\\(interface\\|block[ \t]*data\\)\\>")
986 (list (match-string 1) nil
))))
988 (defsubst f90-looking-at-program-block-start
()
989 "Return (KIND NAME) if a program block with name NAME starts after point."
990 ;;;NAME is nil for an un-named main PROGRAM block."
992 ((looking-at "\\(program\\)[ \t]+\\(\\sw+\\)\\>")
993 (list (match-string 1) (match-string 2)))
994 ((and (not (looking-at "module[ \t]*procedure\\>"))
995 (looking-at "\\(module\\)[ \t]+\\(\\sw+\\)\\>"))
996 (list (match-string 1) (match-string 2)))
997 ((and (not (looking-at "end[ \t]*\\(function\\|subroutine\\)"))
998 (looking-at "[^!'\"\&\n]*\\(function\\|subroutine\\)[ \t]+\
1000 (list (match-string 1) (match-string 2)))))
1001 ;; Following will match an un-named main program block; however
1002 ;; one needs to check if there is an actual PROGRAM statement after
1003 ;; point (and before any END program). Adding this will require
1004 ;; change to eg f90-calculate-indent.
1005 ;;; ((save-excursion
1006 ;;; (not (f90-previous-statement)))
1007 ;;; '("program" nil))))
1009 (defsubst f90-looking-at-program-block-end
()
1010 "Return (KIND NAME) if a block with name NAME ends after point."
1011 (if (looking-at (concat "end[ \t]*" f90-blocks-re
1012 "?\\([ \t]+\\(\\sw+\\)\\)?\\>"))
1013 (list (match-string 1) (match-string 3))))
1015 (defsubst f90-comment-indent
()
1016 "Return the indentation to be used for a comment starting at point.
1017 Used for `comment-indent-function' by F90 mode.
1018 \"!!!\", `f90-directive-comment-re', variable `f90-comment-region' return 0.
1019 `f90-indented-comment-re' (if not trailing code) calls `f90-calculate-indent'.
1020 All others return `comment-column', leaving at least one space after code."
1021 (cond ((looking-at "!!!") 0)
1022 ((and f90-directive-comment-re
1023 (looking-at f90-directive-comment-re
)) 0)
1024 ((looking-at (regexp-quote f90-comment-region
)) 0)
1025 ((and (looking-at f90-indented-comment-re
)
1026 ;; Don't attempt to indent trailing comment as code.
1028 (skip-chars-backward " \t")
1030 (f90-calculate-indent))
1032 (skip-chars-backward " \t")
1033 (max (if (bolp) 0 (1+ (current-column))) comment-column
)))))
1035 (defsubst f90-present-statement-cont
()
1036 "Return continuation properties of present statement.
1037 Possible return values are:
1038 single - statement is not continued.
1039 begin - current line is the first in a continued statement.
1040 end - current line is the last in a continued statement
1041 middle - current line is neither first nor last in a continued statement.
1042 Comment lines embedded amongst continued lines return 'middle."
1045 (setq pcont
(if (f90-previous-statement) (f90-line-continued))))
1046 (setq cont
(f90-line-continued))
1047 (cond ((and (not pcont
) (not cont
)) 'single
)
1048 ((and (not pcont
) cont
) 'begin
)
1049 ((and pcont
(not cont
)) 'end
)
1050 ((and pcont cont
) 'middle
)
1051 (t (error "The impossible occurred")))))
1053 (defsubst f90-indent-line-no
()
1054 "If `f90-leave-line-no' is nil, left-justify a line number.
1055 Leaves point at the first non-blank character after the line number.
1056 Call from beginning of line."
1057 (and (null f90-leave-line-no
) (looking-at "[ \t]+[0-9]")
1058 (delete-horizontal-space))
1059 (skip-chars-forward " \t0-9"))
1061 (defsubst f90-no-block-limit
()
1062 "Return nil if point is at the edge of a code block.
1063 Searches line forward for \"function\" or \"subroutine\",
1066 (not (or (looking-at "end")
1067 (looking-at "\\(do\\|if\\|else\\(if\\|where\\)?\
1068 \\|select[ \t]*case\\|case\\|where\\|forall\\)\\>")
1069 (looking-at "\\(program\\|module\\|interface\\|\
1070 block[ \t]*data\\)\\>")
1071 (looking-at "\\(contains\\|\\sw+[ \t]*:\\)")
1072 (looking-at f90-type-def-re
)
1073 (re-search-forward "\\(function\\|subroutine\\)"
1074 (line-end-position) t
)))))
1076 (defsubst f90-update-line
()
1077 "Change case of current line as per `f90-auto-keyword-case'."
1078 (if f90-auto-keyword-case
1079 (f90-change-keywords f90-auto-keyword-case
1080 (line-beginning-position) (line-end-position))))
1082 (defun f90-electric-insert (&optional arg
)
1083 "Change keyword case and auto-fill line as operators are inserted."
1085 (self-insert-command arg
)
1086 (if auto-fill-function
(f90-do-auto-fill) ; also updates line
1090 (defun f90-get-correct-indent ()
1091 "Get correct indent for a line starting with line number.
1092 Does not check type and subprogram indentation."
1093 (let ((epnt (line-end-position)) icol cont
)
1095 (while (and (f90-previous-statement)
1097 (setq cont
(f90-present-statement-cont))
1098 (or (eq cont
'end
) (eq cont
'middle
)))
1099 (looking-at "[ \t]*[0-9]"))))
1100 (setq icol
(current-indentation))
1102 (when (re-search-forward "\\(if\\|do\\|select\\|where\\|forall\\)"
1103 (line-end-position) t
)
1105 (skip-chars-forward " \t")
1106 (cond ((f90-looking-at-do)
1107 (setq icol
(+ icol f90-do-indent
)))
1108 ((or (f90-looking-at-if-then)
1109 (f90-looking-at-where-or-forall)
1110 (f90-looking-at-select-case))
1111 (setq icol
(+ icol f90-if-indent
))))
1113 (while (re-search-forward
1114 "\\(if\\|do\\|select\\|where\\|forall\\)" epnt t
)
1116 (skip-chars-forward " \t0-9")
1117 (cond ((f90-looking-at-do)
1118 (setq icol
(+ icol f90-do-indent
)))
1119 ((or (f90-looking-at-if-then)
1120 (f90-looking-at-where-or-forall)
1121 (f90-looking-at-select-case))
1122 (setq icol
(+ icol f90-if-indent
)))
1123 ((looking-at f90-end-if-re
)
1124 (setq icol
(- icol f90-if-indent
)))
1125 ((looking-at "end[ \t]*do\\>")
1126 (setq icol
(- icol f90-do-indent
))))
1130 (defun f90-calculate-indent ()
1131 "Calculate the indent column based on previous statements."
1133 (let (icol cont
(case-fold-search t
) (pnt (point)))
1135 (if (not (f90-previous-statement))
1136 ;; If f90-previous-statement returns nil, we must have been
1137 ;; called from on or before the first line of the first statement.
1138 (setq icol
(if (save-excursion
1139 ;; f90-previous-statement has moved us over
1140 ;; comment/blank lines, so we need to get
1141 ;; back to the first code statement.
1142 (when (looking-at "[ \t]*\\([!#]\\|$\\)")
1143 (f90-next-statement))
1144 (skip-chars-forward " \t0-9")
1145 (f90-looking-at-program-block-start))
1147 ;; No explicit PROGRAM start statement.
1148 f90-program-indent
))
1149 (setq cont
(f90-present-statement-cont))
1151 (while (not (eq 'begin
(f90-present-statement-cont)))
1152 (f90-previous-statement)))
1153 (cond ((eq cont
'begin
)
1154 (setq icol
(+ (f90-current-indentation)
1155 f90-continuation-indent
)))
1156 ((eq cont
'middle
) (setq icol
(current-indentation)))
1157 (t (setq icol
(f90-current-indentation))
1158 (skip-chars-forward " \t")
1159 (if (looking-at "[0-9]")
1160 (setq icol
(f90-get-correct-indent))
1161 (cond ((or (f90-looking-at-if-then)
1162 (f90-looking-at-where-or-forall)
1163 (f90-looking-at-select-case)
1164 (looking-at f90-else-like-re
))
1165 (setq icol
(+ icol f90-if-indent
)))
1166 ((f90-looking-at-do)
1167 (setq icol
(+ icol f90-do-indent
)))
1168 ((f90-looking-at-type-like)
1169 (setq icol
(+ icol f90-type-indent
)))
1170 ((or (f90-looking-at-program-block-start)
1171 (looking-at "contains[ \t]*\\($\\|!\\)"))
1172 (setq icol
(+ icol f90-program-indent
)))))
1175 (cond ((looking-at "[ \t]*$"))
1176 ((looking-at "[ \t]*#") ; check for cpp directive
1179 (skip-chars-forward " \t0-9")
1180 (cond ((or (looking-at f90-else-like-re
)
1181 (looking-at f90-end-if-re
))
1182 (setq icol
(- icol f90-if-indent
)))
1183 ((looking-at "end[ \t]*do\\>")
1184 (setq icol
(- icol f90-do-indent
)))
1185 ((looking-at f90-end-type-re
)
1186 (setq icol
(- icol f90-type-indent
)))
1187 ((or (looking-at "contains[ \t]*\\(!\\|$\\)")
1188 (f90-looking-at-program-block-end))
1189 (setq icol
(- icol f90-program-indent
))))))
1193 (defun f90-previous-statement ()
1194 "Move point to beginning of the previous F90 statement.
1195 If no previous statement is found (i.e. if called from the first
1196 statement in the buffer), move to the start of the buffer and
1197 return nil. A statement is a line which is neither blank nor a
1200 (let (not-first-statement)
1202 (while (and (setq not-first-statement
(zerop (forward-line -
1)))
1203 (looking-at "[ \t0-9]*\\(!\\|$\\|#\\)")))
1204 not-first-statement
))
1206 (defun f90-next-statement ()
1207 "Move point to beginning of the next F90 statement.
1208 Return nil if no later statement is found."
1210 (let (not-last-statement)
1212 (while (and (setq not-last-statement
1213 (and (zerop (forward-line 1))
1215 (looking-at "[ \t0-9]*\\(!\\|$\\)")))
1216 not-last-statement
))
1218 (defun f90-beginning-of-subprogram ()
1219 "Move point to the beginning of the current subprogram.
1220 Return (TYPE NAME), or nil if not found."
1222 (let ((count 1) (case-fold-search t
) matching-beg
)
1224 (while (and (> count
0)
1225 (re-search-backward f90-program-block-re nil
'move
))
1227 (skip-chars-forward " \t0-9")
1228 (cond ((setq matching-beg
(f90-looking-at-program-block-start))
1229 (setq count
(1- count
)))
1230 ((f90-looking-at-program-block-end)
1231 (setq count
(1+ count
)))))
1235 ;; Note this includes the case of an un-named main program,
1236 ;; in which case we go to (point-min).
1237 (message "No beginning found.")
1240 (defun f90-end-of-subprogram ()
1241 "Move point to the end of the current subprogram.
1242 Return (TYPE NAME), or nil if not found."
1244 (let ((case-fold-search t
)
1248 (while (and (> count
0)
1249 (re-search-forward f90-program-block-re nil
'move
))
1251 (skip-chars-forward " \t0-9")
1252 (cond ((f90-looking-at-program-block-start)
1253 (setq count
(1+ count
)))
1254 ((setq matching-end
(f90-looking-at-program-block-end))
1255 (setq count
(1- count
))))
1257 ;; This means f90-end-of-subprogram followed by f90-start-of-subprogram
1258 ;; has a net non-zero effect, which seems odd.
1259 ;;; (forward-line 1)
1262 (message "No end found.")
1266 (defun f90-end-of-block (&optional num
)
1267 "Move point forward to the end of the current code block.
1268 With optional argument NUM, go forward that many balanced blocks.
1269 If NUM is negative, go backward to the start of a block. Checks
1270 for consistency of block types and labels (if present), and
1271 completes outermost block if `f90-smart-end' is non-nil.
1272 Interactively, pushes mark before moving point."
1274 (if (interactive-p) (push-mark (point) t
)) ; can move some distance
1275 (and num
(< num
0) (f90-beginning-of-block (- num
)))
1276 (let ((f90-smart-end (if f90-smart-end
'no-blink
)) ; for final match-end
1277 (case-fold-search t
)
1279 start-list start-this start-type start-label end-type end-label
)
1280 (end-of-line) ; probably want this
1281 (while (and (> count
0) (re-search-forward f90-blocks-re nil
'move
))
1283 (skip-chars-forward " \t0-9")
1284 (cond ((or (f90-in-string) (f90-in-comment)))
1288 (f90-looking-at-select-case)
1289 (f90-looking-at-type-like)
1290 (f90-looking-at-program-block-start)
1291 (f90-looking-at-if-then)
1292 (f90-looking-at-where-or-forall)))
1293 (setq start-list
(cons start-this start-list
) ; not add-to-list!
1295 ((looking-at (concat "end[ \t]*" f90-blocks-re
1296 "[ \t]*\\(\\sw+\\)?"))
1297 (setq end-type
(match-string 1)
1298 end-label
(match-string 2)
1300 ;; Check any internal blocks.
1302 (setq start-this
(car start-list
)
1303 start-list
(cdr start-list
)
1304 start-type
(car start-this
)
1305 start-label
(cadr start-this
))
1306 (or (f90-equal-symbols start-type end-type
)
1307 (error "End type `%s' does not match start type `%s'"
1308 end-type start-type
))
1309 (or (f90-equal-symbols start-label end-label
)
1310 (error "End label `%s' does not match start label `%s'"
1311 end-label start-label
)))))
1313 (if (> count
0) (error "Missing block end"))
1314 ;; Check outermost block.
1318 (skip-chars-forward " \t0-9")
1321 (defun f90-beginning-of-block (&optional num
)
1322 "Move point backwards to the start of the current code block.
1323 With optional argument NUM, go backward that many balanced blocks.
1324 If NUM is negative, go forward to the end of a block.
1325 Checks for consistency of block types and labels (if present).
1326 Does not check the outermost block, because it may be incomplete.
1327 Interactively, pushes mark before moving point."
1329 (if (interactive-p) (push-mark (point) t
))
1330 (and num
(< num
0) (f90-end-of-block (- num
)))
1331 (let ((case-fold-search t
)
1333 end-list end-this end-type end-label
1334 start-this start-type start-label
)
1335 (beginning-of-line) ; probably want this
1336 (while (and (> count
0) (re-search-backward f90-blocks-re nil
'move
))
1338 (skip-chars-forward " \t0-9")
1339 (cond ((or (f90-in-string) (f90-in-comment)))
1340 ((looking-at (concat "end[ \t]*" f90-blocks-re
1341 "[ \t]*\\(\\sw+\\)?"))
1342 (setq end-list
(cons (list (match-string 1) (match-string 2))
1348 (f90-looking-at-select-case)
1349 (f90-looking-at-type-like)
1350 (f90-looking-at-program-block-start)
1351 (f90-looking-at-if-then)
1352 (f90-looking-at-where-or-forall)))
1353 (setq start-type
(car start-this
)
1354 start-label
(cadr start-this
)
1356 ;; Check any internal blocks.
1358 (setq end-this
(car end-list
)
1359 end-list
(cdr end-list
)
1360 end-type
(car end-this
)
1361 end-label
(cadr end-this
))
1362 (or (f90-equal-symbols start-type end-type
)
1363 (error "Start type `%s' does not match end type `%s'"
1364 start-type end-type
))
1365 (or (f90-equal-symbols start-label end-label
)
1366 (error "Start label `%s' does not match end label `%s'"
1367 start-label end-label
))))))
1368 ;; Includes an un-named main program block.
1369 (if (> count
0) (error "Missing block start"))))
1371 (defun f90-next-block (&optional num
)
1372 "Move point forward to the next end or start of a code block.
1373 With optional argument NUM, go forward that many blocks.
1374 If NUM is negative, go backwards.
1375 A block is a subroutine, if-endif, etc."
1377 (let ((case-fold-search t
)
1378 (count (if num
(abs num
) 1)))
1379 (while (and (> count
0)
1380 (if (> num
0) (re-search-forward f90-blocks-re nil
'move
)
1381 (re-search-backward f90-blocks-re nil
'move
)))
1383 (skip-chars-forward " \t0-9")
1384 (cond ((or (f90-in-string) (f90-in-comment)))
1386 (looking-at "end[ \t]*")
1388 (f90-looking-at-select-case)
1389 (f90-looking-at-type-like)
1390 (f90-looking-at-program-block-start)
1391 (f90-looking-at-if-then)
1392 (f90-looking-at-where-or-forall))
1393 (setq count
(1- count
))))
1394 (if (> num
0) (end-of-line)
1395 (beginning-of-line)))))
1398 (defun f90-previous-block (&optional num
)
1399 "Move point backward to the previous end or start of a code block.
1400 With optional argument NUM, go backward that many blocks.
1401 If NUM is negative, go forwards.
1402 A block is a subroutine, if-endif, etc."
1404 (f90-next-block (- (or num
1))))
1407 (defun f90-mark-subprogram ()
1408 "Put mark at end of F90 subprogram, point at beginning, push mark."
1410 (let ((pos (point)) program
)
1411 (f90-end-of-subprogram)
1414 (setq program
(f90-beginning-of-subprogram))
1415 (if (fboundp 'zmacs-activate-region
)
1416 (zmacs-activate-region)
1418 deactivate-mark nil
))
1421 (defun f90-comment-region (beg-region end-region
)
1422 "Comment/uncomment every line in the region.
1423 Insert the variable `f90-comment-region' at the start of every line
1424 in the region, or, if already present, remove it."
1426 (let ((end (copy-marker end-region
)))
1427 (goto-char beg-region
)
1429 (if (looking-at (regexp-quote f90-comment-region
))
1430 (delete-region (point) (match-end 0))
1431 (insert f90-comment-region
))
1432 (while (and (zerop (forward-line 1))
1434 (if (looking-at (regexp-quote f90-comment-region
))
1435 (delete-region (point) (match-end 0))
1436 (insert f90-comment-region
)))
1437 (set-marker end nil
)))
1439 (defun f90-indent-line (&optional no-update
)
1440 "Indent current line as F90 code.
1441 Unless optional argument NO-UPDATE is non-nil, call `f90-update-line'
1444 (let ((case-fold-search t
)
1445 (pos (point-marker))
1446 indent no-line-number
)
1447 (beginning-of-line) ; digits after & \n are not line-nos
1448 (if (not (save-excursion (and (f90-previous-statement)
1449 (f90-line-continued))))
1450 (f90-indent-line-no)
1451 (setq no-line-number t
)
1452 (skip-chars-forward " \t"))
1453 (if (looking-at "!")
1454 (setq indent
(f90-comment-indent))
1455 (and f90-smart-end
(looking-at "end")
1457 (setq indent
(f90-calculate-indent)))
1458 (or (= indent
(current-column))
1459 (f90-indent-to indent no-line-number
))
1460 ;; If initial point was within line's indentation,
1461 ;; position after the indentation. Else stay at same point in text.
1462 (and (< (point) pos
)
1464 (if auto-fill-function
1465 ;; GM NO-UPDATE not honoured, since this calls f90-update-line.
1467 (or no-update
(f90-update-line)))
1468 (set-marker pos nil
)))
1470 (defun f90-indent-new-line ()
1471 "Re-indent current line, insert a newline and indent the newline.
1472 An abbrev before point is expanded if the variable `abbrev-mode' is non-nil.
1473 If run in the middle of a line, the line is not broken."
1475 (if abbrev-mode
(expand-abbrev))
1476 (beginning-of-line) ; reindent where likely to be needed
1477 (f90-indent-line) ; calls indent-line-no, update-line
1479 (delete-horizontal-space) ; destroy trailing whitespace
1480 (let ((string (f90-in-string))
1481 (cont (f90-line-continued)))
1482 (and string
(not cont
) (insert "&"))
1484 (if (or string
(and cont f90-beginning-ampersand
)) (insert "&")))
1485 (f90-indent-line 'no-update
)) ; nothing to update
1488 ;; TODO not add spaces to empty lines at the start.
1489 ;; Why is second line getting extra indent over first?
1490 (defun f90-indent-region (beg-region end-region
)
1491 "Indent every line in region by forward parsing."
1493 (let ((end-region-mark (copy-marker end-region
))
1494 (save-point (point-marker))
1495 (case-fold-search t
)
1496 block-list ind-lev ind-curr ind-b cont struct beg-struct end-struct
)
1497 (goto-char beg-region
)
1498 ;; First find a line which is not a continuation line or comment.
1500 (while (and (looking-at "[ \t]*[0-9]*\\(!\\|#\\|[ \t]*$\\)")
1501 (progn (f90-indent-line 'no-update
)
1502 (zerop (forward-line 1)))
1503 (< (point) end-region-mark
)))
1504 (setq cont
(f90-present-statement-cont))
1505 (while (and (or (eq cont
'middle
) (eq cont
'end
))
1506 (f90-previous-statement))
1507 (setq cont
(f90-present-statement-cont)))
1508 ;; Process present line for beginning of block.
1509 (setq f90-cache-position
(point))
1510 (f90-indent-line 'no-update
)
1511 (setq ind-lev
(f90-current-indentation)
1514 (skip-chars-forward " \t0-9")
1516 ind-b
(cond ((setq struct
(f90-looking-at-do)) f90-do-indent
)
1517 ((or (setq struct
(f90-looking-at-if-then))
1518 (setq struct
(f90-looking-at-select-case))
1519 (setq struct
(f90-looking-at-where-or-forall))
1520 (looking-at f90-else-like-re
))
1522 ((setq struct
(f90-looking-at-type-like))
1524 ((or (setq struct
(f90-looking-at-program-block-start))
1525 (looking-at "contains[ \t]*\\($\\|!\\)"))
1526 f90-program-indent
)))
1527 (if ind-b
(setq ind-lev
(+ ind-lev ind-b
)))
1528 (if struct
(setq block-list
(cons struct block-list
)))
1529 (while (and (f90-line-continued) (zerop (forward-line 1))
1530 (< (point) end-region-mark
))
1531 (if (looking-at "[ \t]*!")
1532 (f90-indent-to (f90-comment-indent))
1533 (or (= (current-indentation)
1534 (+ ind-curr f90-continuation-indent
))
1535 (f90-indent-to (+ ind-curr f90-continuation-indent
) 'no-line-no
))))
1536 ;; Process all following lines.
1537 (while (and (zerop (forward-line 1)) (< (point) end-region-mark
))
1539 (f90-indent-line-no)
1540 (setq f90-cache-position
(point))
1541 (cond ((looking-at "[ \t]*$") (setq ind-curr
0))
1542 ((looking-at "[ \t]*#") (setq ind-curr
0))
1543 ((looking-at "!") (setq ind-curr
(f90-comment-indent)))
1544 ((f90-no-block-limit) (setq ind-curr ind-lev
))
1545 ((looking-at f90-else-like-re
) (setq ind-curr
1546 (- ind-lev f90-if-indent
)))
1547 ((looking-at "contains[ \t]*\\($\\|!\\)")
1548 (setq ind-curr
(- ind-lev f90-program-indent
)))
1550 (cond ((setq struct
(f90-looking-at-do)) f90-do-indent
)
1551 ((or (setq struct
(f90-looking-at-if-then))
1552 (setq struct
(f90-looking-at-select-case))
1553 (setq struct
(f90-looking-at-where-or-forall)))
1555 ((setq struct
(f90-looking-at-type-like))
1557 ((setq struct
(f90-looking-at-program-block-start))
1558 f90-program-indent
)))
1559 (setq ind-curr ind-lev
)
1560 (if ind-b
(setq ind-lev
(+ ind-lev ind-b
)))
1561 (setq block-list
(cons struct block-list
)))
1562 ((setq end-struct
(f90-looking-at-program-block-end))
1563 (setq beg-struct
(car block-list
)
1564 block-list
(cdr block-list
))
1567 (f90-block-match (car beg-struct
) (car (cdr beg-struct
))
1568 (car end-struct
) (car (cdr end-struct
)))))
1570 (cond ((looking-at f90-end-if-re
) f90-if-indent
)
1571 ((looking-at "end[ \t]*do\\>") f90-do-indent
)
1572 ((looking-at f90-end-type-re
) f90-type-indent
)
1573 ((f90-looking-at-program-block-end)
1574 f90-program-indent
)))
1575 (if ind-b
(setq ind-lev
(- ind-lev ind-b
)))
1576 (setq ind-curr ind-lev
))
1577 (t (setq ind-curr ind-lev
)))
1578 ;; Do the indentation if necessary.
1579 (or (= ind-curr
(current-column))
1580 (f90-indent-to ind-curr
))
1581 (while (and (f90-line-continued) (zerop (forward-line 1))
1582 (< (point) end-region-mark
))
1583 (if (looking-at "[ \t]*!")
1584 (f90-indent-to (f90-comment-indent))
1585 (or (= (current-indentation)
1586 (+ ind-curr f90-continuation-indent
))
1588 (+ ind-curr f90-continuation-indent
) 'no-line-no
)))))
1589 ;; Restore point, etc.
1590 (setq f90-cache-position nil
)
1591 (goto-char save-point
)
1592 (set-marker end-region-mark nil
)
1593 (set-marker save-point nil
)
1594 (if (fboundp 'zmacs-deactivate-region
)
1595 (zmacs-deactivate-region)
1596 (deactivate-mark))))
1598 (defun f90-indent-subprogram ()
1599 "Properly indent the subprogram containing point."
1602 (let ((program (f90-mark-subprogram)))
1605 (message "Indenting %s %s..."
1606 (car program
) (car (cdr program
)))
1607 (indent-region (point) (mark) nil
)
1608 (message "Indenting %s %s...done"
1609 (car program
) (car (cdr program
))))
1610 (message "Indenting the whole file...")
1611 (indent-region (point) (mark) nil
)
1612 (message "Indenting the whole file...done")))))
1614 (defun f90-break-line (&optional no-update
)
1615 "Break line at point, insert continuation marker(s) and indent.
1616 Unless in a string or comment, or if the optional argument NO-UPDATE
1617 is non-nil, call `f90-update-line' after inserting the continuation marker."
1619 (cond ((f90-in-string)
1622 (delete-horizontal-space 'backwards
) ; remove trailing whitespace
1623 (insert "\n" (f90-get-present-comment-type)))
1625 (or no-update
(f90-update-line))
1627 (if f90-beginning-ampersand
(insert "&"))))
1628 (indent-according-to-mode))
1630 (defun f90-find-breakpoint ()
1631 "From `fill-column', search backward for break-delimiter."
1632 (re-search-backward f90-break-delimiters
(line-beginning-position))
1633 (if (not f90-break-before-delimiters
)
1634 (forward-char (if (looking-at f90-no-break-re
) 2 1))
1636 (or (looking-at f90-no-break-re
)
1639 (defun f90-do-auto-fill ()
1640 "Break line if non-white characters beyond `fill-column'.
1641 Update keyword case first."
1643 ;; Break line before or after last delimiter (non-word char) if
1644 ;; position is beyond fill-column.
1645 ;; Will not break **, //, or => (as specified by f90-no-break-re).
1647 ;; Need this for `f90-electric-insert' and other f90- callers.
1648 (unless (and (boundp 'comment-auto-fill-only-comments
)
1649 comment-auto-fill-only-comments
1650 (not (f90-in-comment)))
1651 (while (> (current-column) fill-column
)
1652 (let ((pos-mark (point-marker)))
1653 (move-to-column fill-column
)
1654 (or (f90-in-string) (f90-find-breakpoint))
1656 (goto-char pos-mark
)
1657 (set-marker pos-mark nil
)))))
1659 (defun f90-join-lines (&optional arg
)
1660 "Join current line to previous, fix whitespace, continuation, comments.
1661 With optional argument ARG, join current line to following line.
1662 Like `join-line', but handles F90 syntax."
1665 (if arg
(forward-line 1))
1666 (when (eq (preceding-char) ?
\n)
1667 (skip-chars-forward " \t")
1668 (if (looking-at "\&") (delete-char 1))
1670 (delete-region (point) (1- (point)))
1671 (skip-chars-backward " \t")
1672 (and (eq (preceding-char) ?
&) (delete-char -
1))
1673 (and (f90-in-comment)
1674 (looking-at "[ \t]*!+")
1677 (fixup-whitespace))))
1679 (defun f90-fill-region (beg-region end-region
)
1680 "Fill every line in region by forward parsing. Join lines if possible."
1682 (let ((end-region-mark (copy-marker end-region
))
1684 f90-smart-end f90-auto-keyword-case auto-fill-function
)
1685 (goto-char beg-region
)
1687 ;; Join as much as possible.
1690 (skip-chars-backward " \t")
1691 (eq (preceding-char) ?
&))
1692 (f90-join-lines 'forward
))
1693 ;; Chop the line if necessary.
1694 (while (> (save-excursion (end-of-line) (current-column))
1696 (move-to-column fill-column
)
1697 (f90-find-breakpoint)
1698 (f90-break-line 'no-update
))
1699 (setq go-on
(and (< (point) end-region-mark
)
1700 (zerop (forward-line 1)))
1701 f90-cache-position
(point)))
1702 (setq f90-cache-position nil
)
1703 (set-marker end-region-mark nil
)
1704 (if (fboundp 'zmacs-deactivate-region
)
1705 (zmacs-deactivate-region)
1706 (deactivate-mark))))
1708 (defun f90-block-match (beg-block beg-name end-block end-name
)
1709 "Match end-struct with beg-struct and complete end-block if possible.
1710 BEG-BLOCK is the type of block as indicated at the start (e.g., do).
1711 BEG-NAME is the block start name (may be nil).
1712 END-BLOCK is the type of block as indicated at the end (may be nil).
1713 END-NAME is the block end name (may be nil).
1714 Leave point at the end of line."
1715 ;; Hack to deal with the case when this is called from
1716 ;; f90-indent-region on a program block without an explicit PROGRAM
1717 ;; statement at the start. Should really be an error (?).
1718 (or beg-block
(setq beg-block
"program"))
1719 (search-forward "end" (line-end-position))
1721 (if (and end-block
(f90-equal-symbols beg-block end-block
))
1722 (search-forward end-block
)
1725 (message "END %s does not match %s." end-block beg-block
)
1727 (throw 'no-match nil
))
1728 (message "Inserting %s." beg-block
)
1729 (insert (concat " " beg-block
))))
1730 (if (f90-equal-symbols beg-name end-name
)
1731 (and end-name
(search-forward end-name
))
1732 (cond ((and beg-name
(not end-name
))
1733 (message "Inserting %s." beg-name
)
1734 (insert (concat " " beg-name
)))
1735 ((and beg-name end-name
)
1736 (message "Replacing %s with %s." end-name beg-name
)
1737 (search-forward end-name
)
1738 (replace-match beg-name
))
1739 ((and (not beg-name
) end-name
)
1740 (message "Deleting %s." end-name
)
1741 (search-forward end-name
)
1742 (replace-match ""))))
1743 (or (looking-at "[ \t]*!") (delete-horizontal-space))))
1745 (defun f90-match-end ()
1746 "From an end block statement, find the corresponding block and name."
1749 (top-of-window (window-start))
1751 (case-fold-search t
)
1752 matching-beg beg-name end-name beg-block end-block end-struct
)
1753 (when (save-excursion (beginning-of-line) (skip-chars-forward " \t0-9")
1754 (setq end-struct
(f90-looking-at-program-block-end)))
1755 (setq end-block
(car end-struct
)
1756 end-name
(car (cdr end-struct
)))
1759 (while (and (> count
0)
1760 (not (= (line-beginning-position) (point-min))))
1761 (re-search-backward f90-blocks-re nil
'move
)
1763 ;; GM not a line number if continued line.
1764 ;;; (skip-chars-forward " \t")
1765 ;;; (skip-chars-forward "0-9")
1766 (skip-chars-forward " \t0-9")
1767 (cond ((or (f90-in-string) (f90-in-comment)))
1771 (f90-looking-at-if-then)
1772 (f90-looking-at-where-or-forall)
1773 (f90-looking-at-select-case)
1774 (f90-looking-at-type-like)
1775 (f90-looking-at-program-block-start)
1776 ;; Interpret a single END without a block
1777 ;; start to be the END of a program block
1778 ;; without an initial PROGRAM line.
1779 (if (= (line-beginning-position) (point-min))
1781 (setq count
(1- count
)))
1782 ((looking-at (concat "end[ \t]*" f90-blocks-re
))
1783 (setq count
(1+ count
)))))
1785 (message "No matching beginning.")
1787 (if (eq f90-smart-end
'blink
)
1788 (if (< (point) top-of-window
)
1789 (message "Matches %s: %s"
1792 (line-beginning-position)
1793 (line-end-position)))
1794 (sit-for blink-matching-delay
)))
1795 (setq beg-block
(car matching-beg
)
1796 beg-name
(car (cdr matching-beg
)))
1797 (goto-char end-point
)
1799 (f90-block-match beg-block beg-name end-block end-name
))))))
1801 (defun f90-insert-end ()
1802 "Insert a complete end statement matching beginning of present block."
1804 (let ((f90-smart-end (or f90-smart-end
'blink
)))
1806 (f90-indent-new-line)))
1808 ;; Abbrevs and keywords.
1810 (defun f90-abbrev-start ()
1811 "Typing `\\[help-command] or `? lists all the F90 abbrevs.
1812 Any other key combination is executed normally."
1814 (insert last-command-char
)
1816 (if (fboundp 'next-command-event
) ; XEmacs
1817 (setq event
(next-command-event)
1818 char
(and (fboundp 'event-to-character
)
1819 (event-to-character event
)))
1820 (setq event
(read-event)
1822 ;; Insert char if not equal to `?', or if abbrev-mode is off.
1823 (if (and abbrev-mode
(or (eq char ??
) (eq char help-char
)))
1825 (setq unread-command-events
(list event
)))))
1827 (defun f90-abbrev-help ()
1828 "List the currently defined abbrevs in F90 mode."
1830 (message "Listing abbrev table...")
1831 (display-buffer (f90-prepare-abbrev-list-buffer))
1832 (message "Listing abbrev table...done"))
1834 (defun f90-prepare-abbrev-list-buffer ()
1835 "Create a buffer listing the F90 mode abbreviations."
1837 (set-buffer (get-buffer-create "*Abbrevs*"))
1839 (insert-abbrev-table-description 'f90-mode-abbrev-table t
)
1840 (goto-char (point-min))
1841 (set-buffer-modified-p nil
)
1842 (edit-abbrevs-mode))
1843 (get-buffer-create "*Abbrevs*"))
1845 (defun f90-upcase-keywords ()
1846 "Upcase all F90 keywords in the buffer."
1848 (f90-change-keywords 'upcase-word
))
1850 (defun f90-capitalize-keywords ()
1851 "Capitalize all F90 keywords in the buffer."
1853 (f90-change-keywords 'capitalize-word
))
1855 (defun f90-downcase-keywords ()
1856 "Downcase all F90 keywords in the buffer."
1858 (f90-change-keywords 'downcase-word
))
1860 (defun f90-upcase-region-keywords (beg end
)
1861 "Upcase all F90 keywords in the region."
1863 (f90-change-keywords 'upcase-word beg end
))
1865 (defun f90-capitalize-region-keywords (beg end
)
1866 "Capitalize all F90 keywords in the region."
1868 (f90-change-keywords 'capitalize-word beg end
))
1870 (defun f90-downcase-region-keywords (beg end
)
1871 "Downcase all F90 keywords in the region."
1873 (f90-change-keywords 'downcase-word beg end
))
1875 ;; Change the keywords according to argument.
1876 (defun f90-change-keywords (change-word &optional beg end
)
1877 "Change the case of F90 keywords in the region (if specified) or buffer.
1878 CHANGE-WORD should be one of 'upcase-word, 'downcase-word, 'capitalize-word."
1880 (setq beg
(or beg
(point-min))
1881 end
(or end
(point-max)))
1884 f90-keywords-re
"\\|" f90-procedures-re
"\\|"
1885 f90-hpf-keywords-re
"\\|" f90-operators-re
"\\)"))
1886 (ref-point (point-min))
1887 (modified (buffer-modified-p))
1888 state saveword back-point
)
1891 (while (re-search-forward keyword-re end t
)
1893 (setq state
(parse-partial-sexp ref-point
(point)))
1894 (or (nth 3 state
) (nth 4 state
)
1895 ;; GM f90-directive-comment-re?
1896 (save-excursion ; check for cpp directive
1898 (skip-chars-forward " \t0-9")
1900 (setq ref-point
(point)
1901 back-point
(save-excursion (backward-word 1) (point))
1902 saveword
(buffer-substring back-point ref-point
))
1903 (funcall change-word -
1)
1904 (or (string= saveword
(buffer-substring back-point ref-point
))
1905 (setq modified t
))))
1906 (or modified
(set-buffer-modified-p nil
))))))
1909 (defun f90-current-defun ()
1910 "Function to use for `add-log-current-defun-function' in F90 mode."
1912 (nth 1 (f90-beginning-of-subprogram))))
1915 (defun f90-backslash-not-special (&optional all
)
1916 "Make the backslash character (\\) be non-special in the current buffer.
1917 With optional argument ALL, change the default for all present
1918 and future F90 buffers. F90 mode normally treats backslash as an
1920 (or (eq major-mode
'f90-mode
)
1921 (error "This function should only be used in F90 buffers"))
1922 (when (equal (char-syntax ?
\\ ) ?
\\ )
1923 (or all
(set-syntax-table (copy-syntax-table (syntax-table))))
1924 (modify-syntax-entry ?
\\ ".")))
1929 ;;; arch-tag: fceac97c-c147-44bd-aec0-172d4b560ef8
1930 ;;; f90.el ends here