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