Mercurial > emacs
comparison lisp/progmodes/fortran.el @ 20805:918448e5d294
Various docstring and commentary fixes, including
note of current maintainer.
(fortran-mode): Use imenu-syntax-alist.
(fortran-imenu-generic-expression): Use
fortran-continuation-string, not always `+'.
(fortran-font-lock-keywords-1): Include symbol syntax as well
as word, following syntax table changes.
(fortran-imenu-generic-expression): Likewise.
(fortran-mode-map): Add a menu.
(fortran-mode-version, fortran-startup-message): Delete
misleading variables.
(fortran-mode): Don't use them.
(fortran-column-ruler-fixed, fortran-column-ruler-tab): Fix
leading \ which made `0' into null.
(fortran-join-lines): New function and key binding.
(fortran-narrow-to-subprogram): New function and key binding.
(fortran-mode-syntax-table): Make ?., ?_, ?$ symbol, not word.
author | Dave Love <fx@gnu.org> |
---|---|
date | Fri, 30 Jan 1998 17:49:37 +0000 |
parents | b7f5af6127d5 |
children | f3f9df46d008 |
comparison
equal
deleted
inserted
replaced
20804:14fa73136e64 | 20805:918448e5d294 |
---|---|
1 ;;; fortran.el --- Fortran mode for GNU Emacs | 1 ;;; fortran.el --- Fortran mode for GNU Emacs |
2 | 2 |
3 ;; Copyright (c) 1986, 1993, 1994, 1995, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (c) 1986, 1993, 1994, 1995, 1997, 1998 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Michael D. Prange <prange@erl.mit.edu> | 5 ;; Author: Michael D. Prange <prange@erl.mit.edu> |
6 ;; Maintainer: bug-fortran-mode@erl.mit.edu (Steve Gildea and others) | 6 ;; Maintainer: Dave Love <fx@gnu.org> |
7 ;; Version 1.30.6 (July 27, 1995) | |
8 ;; Keywords: languages | 7 ;; Keywords: languages |
9 | 8 |
10 ;; This file is part of GNU Emacs. | 9 ;; This file is part of GNU Emacs. |
11 | 10 |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | 11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
25 ;; Boston, MA 02111-1307, USA. | 24 ;; Boston, MA 02111-1307, USA. |
26 | 25 |
27 ;;; Commentary: | 26 ;;; Commentary: |
28 | 27 |
29 ;; Fortran mode has been upgraded and is now maintained by Stephen A. Wood | 28 ;; This mode is documented in the Emacs manual. |
30 ;; (saw@cebaf.gov). It now will use either fixed format continuation line | 29 ;; |
31 ;; markers (character in 6th column), or tab format continuation line style | 30 ;; Note that it is for editing Fortran77 or Fortran90 fixed source |
32 ;; (digit after a TAB character.) A auto-fill mode has been added to | 31 ;; form. For editing Fortran90 free format source, use `f90-mode' |
33 ;; automatically wrap fortran lines that get too long. | 32 ;; (f90.el). |
33 | |
34 ;;; History: | |
35 | |
36 ;; Fortran mode was upgraded by Stephen A. Wood (saw@cebaf.gov). | |
34 | 37 |
35 ;; We acknowledge many contributions and valuable suggestions by | 38 ;; We acknowledge many contributions and valuable suggestions by |
36 ;; Lawrence R. Dodd, Ralf Fassel, Ralph Finch, Stephen Gildea, | 39 ;; Lawrence R. Dodd, Ralf Fassel, Ralph Finch, Stephen Gildea, |
37 ;; Dr. Anil Gokhale, Ulrich Mueller, Mark Neale, Eric Prestemon, | 40 ;; Dr. Anil Gokhale, Ulrich Mueller, Mark Neale, Eric Prestemon, |
38 ;; Gary Sabot and Richard Stallman. | 41 ;; Gary Sabot and Richard Stallman. |
39 | 42 |
40 ;; This file may be used with GNU Emacs version 18.xx if the following | |
41 ;; variable and function substitutions are made. | |
42 ;; Replace: | |
43 ;; frame-width with screen-width | |
44 ;; auto-fill-function with auto-fill-hook | |
45 ;; comment-indent-function with comment-indent-hook | |
46 ;; (setq unread-command-events (list c)) with (setq unread-command-char c) | |
47 | |
48 ;; Bugs to bug-fortran-mode@erl.mit.edu | |
49 | |
50 ;;; Code: | 43 ;;; Code: |
51 | 44 |
52 (defconst fortran-mode-version "version 1.30.6") | 45 (require 'easymenu) |
53 | 46 |
54 (defgroup fortran nil | 47 (defgroup fortran nil |
55 "Fortran mode for Emacs" | 48 "Fortran mode for Emacs" |
56 :group 'languages) | 49 :group 'languages) |
57 | 50 |
100 "*Extra indentation applied to Fortran continuation lines." | 93 "*Extra indentation applied to Fortran continuation lines." |
101 :type 'integer | 94 :type 'integer |
102 :group 'fortran-indent) | 95 :group 'fortran-indent) |
103 | 96 |
104 (defcustom fortran-comment-indent-style 'fixed | 97 (defcustom fortran-comment-indent-style 'fixed |
105 "*nil forces comment lines not to be touched, | 98 "*How to indent comments. |
99 nil forces comment lines not to be touched, | |
106 'fixed makes fixed comment indentation to `fortran-comment-line-extra-indent' | 100 'fixed makes fixed comment indentation to `fortran-comment-line-extra-indent' |
107 columns beyond `fortran-minimum-statement-indent-fixed' (for | 101 columns beyond `fortran-minimum-statement-indent-fixed' (for |
108 `indent-tabs-mode' of nil) or `fortran-minimum-statement-indent-tab' (for | 102 `indent-tabs-mode' of nil) or `fortran-minimum-statement-indent-tab' (for |
109 `indent-tabs-mode' of t), and 'relative indents to current | 103 `indent-tabs-mode' of t), and 'relative indents to current |
110 Fortran indentation plus `fortran-comment-line-extra-indent'." | 104 Fortran indentation plus `fortran-comment-line-extra-indent'." |
173 :type 'string | 167 :type 'string |
174 :group 'fortran) | 168 :group 'fortran) |
175 | 169 |
176 (defcustom fortran-comment-region "c$$$" | 170 (defcustom fortran-comment-region "c$$$" |
177 "*String inserted by \\[fortran-comment-region]\ | 171 "*String inserted by \\[fortran-comment-region]\ |
178 at start of each line in region." | 172 at start of each line in region." |
179 :type 'string | 173 :type 'string |
180 :group 'fortran-comment) | 174 :group 'fortran-comment) |
181 | 175 |
182 (defcustom fortran-electric-line-number t | 176 (defcustom fortran-electric-line-number t |
183 "*Non-nil causes line number digits to be moved to the correct column as\ | 177 "*Non-nil causes line number digits to be moved to the correct column as\ |
184 typed." | 178 typed." |
185 :type 'boolean | 179 :type 'boolean |
186 :group 'fortran) | 180 :group 'fortran) |
187 | 181 |
188 (defcustom fortran-startup-message t | 182 (defcustom fortran-startup-message t |
189 "*Non-nil displays a startup message when Fortran mode is first called." | 183 "*Non-nil displays a startup message when Fortran mode is first called." |
190 :type 'boolean | 184 :type 'boolean |
191 :group 'fortran) | 185 :group 'fortran) |
192 | 186 |
193 (defvar fortran-column-ruler-fixed | 187 (defvar fortran-column-ruler-fixed |
194 "0 4 6 10 20 30 40 5\ | 188 "0 4 6 10 20 30 40 5\ |
195 \0 60 70\n\ | 189 0 60 70\n\ |
196 \[ ]|{ | | | | | | | | \ | 190 \[ ]|{ | | | | | | | | \ |
197 \| | | | |}\n" | 191 \| | | | |}\n" |
198 "*String displayed above current line by \\[fortran-column-ruler]. | 192 "*String displayed above current line by \\[fortran-column-ruler]. |
199 This variable used in fixed format mode.") | 193 This variable used in fixed format mode.") |
200 | 194 |
201 (defvar fortran-column-ruler-tab | 195 (defvar fortran-column-ruler-tab |
202 "0 810 20 30 40 5\ | 196 "0 810 20 30 40 5\ |
203 \0 60 70\n\ | 197 0 60 70\n\ |
204 \[ ]| { | | | | | | | | \ | 198 \[ ]| { | | | | | | | | \ |
205 \| | | | |}\n" | 199 \| | | | |}\n" |
206 "*String displayed above current line by \\[fortran-column-ruler]. | 200 "*String displayed above current line by \\[fortran-column-ruler]. |
207 This variable used in TAB format mode.") | 201 This variable used in TAB format mode.") |
208 | 202 |
212 (defvar fortran-mode-syntax-table nil | 206 (defvar fortran-mode-syntax-table nil |
213 "Syntax table in use in Fortran mode buffers.") | 207 "Syntax table in use in Fortran mode buffers.") |
214 | 208 |
215 (defvar fortran-analyze-depth 100 | 209 (defvar fortran-analyze-depth 100 |
216 "Number of lines to scan to determine whether to use fixed or TAB format\ | 210 "Number of lines to scan to determine whether to use fixed or TAB format\ |
217 style.") | 211 style.") |
218 | 212 |
219 (defcustom fortran-break-before-delimiters t | 213 (defcustom fortran-break-before-delimiters t |
220 "*Non-nil causes `fortran-fill' to break lines before delimiters." | 214 "*Non-nil causes `fortran-fill' to break lines before delimiters." |
221 :type 'boolean | 215 :type 'boolean |
222 :group 'fortran) | 216 :group 'fortran) |
223 | 217 |
224 (if fortran-mode-syntax-table | 218 (if fortran-mode-syntax-table |
225 () | 219 () |
226 (setq fortran-mode-syntax-table (make-syntax-table)) | 220 (setq fortran-mode-syntax-table (make-syntax-table)) |
221 ;; We might like `;' to be punctuation (g77 multi-statement lines), | |
222 ;; but that screws abbrevs. | |
227 (modify-syntax-entry ?\; "w" fortran-mode-syntax-table) | 223 (modify-syntax-entry ?\; "w" fortran-mode-syntax-table) |
228 (modify-syntax-entry ?\r " " fortran-mode-syntax-table) | 224 (modify-syntax-entry ?\r " " fortran-mode-syntax-table) |
229 (modify-syntax-entry ?+ "." fortran-mode-syntax-table) | 225 (modify-syntax-entry ?+ "." fortran-mode-syntax-table) |
230 (modify-syntax-entry ?- "." fortran-mode-syntax-table) | 226 (modify-syntax-entry ?- "." fortran-mode-syntax-table) |
231 (modify-syntax-entry ?= "." fortran-mode-syntax-table) | 227 (modify-syntax-entry ?= "." fortran-mode-syntax-table) |
232 (modify-syntax-entry ?* "." fortran-mode-syntax-table) | 228 (modify-syntax-entry ?* "." fortran-mode-syntax-table) |
233 (modify-syntax-entry ?/ "." fortran-mode-syntax-table) | 229 (modify-syntax-entry ?/ "." fortran-mode-syntax-table) |
234 (modify-syntax-entry ?\' "\"" fortran-mode-syntax-table) | 230 (modify-syntax-entry ?\' "\"" fortran-mode-syntax-table) |
235 (modify-syntax-entry ?\" "\"" fortran-mode-syntax-table) | 231 (modify-syntax-entry ?\" "\"" fortran-mode-syntax-table) |
236 (modify-syntax-entry ?\\ "/" fortran-mode-syntax-table) | 232 (modify-syntax-entry ?\\ "/" fortran-mode-syntax-table) |
237 (modify-syntax-entry ?. "w" fortran-mode-syntax-table) | 233 ;; This might be better as punctuation, as for C, but this way you |
238 (modify-syntax-entry ?_ "w" fortran-mode-syntax-table) | 234 ;; can treat floating-point numbers as symbols. |
235 (modify-syntax-entry ?. "_" fortran-mode-syntax-table) ; e.g. `a.ne.b' | |
236 (modify-syntax-entry ?_ "_" fortran-mode-syntax-table) | |
237 (modify-syntax-entry ?$ "_" fortran-mode-syntax-table) ; esp. VMSisms | |
239 (modify-syntax-entry ?\! "<" fortran-mode-syntax-table) | 238 (modify-syntax-entry ?\! "<" fortran-mode-syntax-table) |
240 (modify-syntax-entry ?\n ">" fortran-mode-syntax-table)) | 239 (modify-syntax-entry ?\n ">" fortran-mode-syntax-table)) |
241 | 240 |
242 ;; Comments are real pain in Fortran because there is no way to represent the | 241 ;; Comments are real pain in Fortran because there is no way to represent the |
243 ;; standard comment syntax in an Emacs syntax table (we can for VAX-style). | 242 ;; standard comment syntax in an Emacs syntax table (we can for VAX-style). |
370 "Default expressions to highlight in Fortran mode.") | 369 "Default expressions to highlight in Fortran mode.") |
371 | 370 |
372 (defvar fortran-imenu-generic-expression | 371 (defvar fortran-imenu-generic-expression |
373 ;; These patterns could be confused by sequence nos. in cols 72+ and | 372 ;; These patterns could be confused by sequence nos. in cols 72+ and |
374 ;; don't allow continuations everywhere. | 373 ;; don't allow continuations everywhere. |
375 '((nil | 374 (list |
376 ;; Lines below are: 1. leading whitespace; 2. function | 375 (list |
377 ;; declaration with optional type, e.g. `real', `real*4', | 376 nil |
378 ;; character(*), `double precision' and possible statement | 377 ;; Lines below are: 1. leading whitespace; 2. function |
379 ;; continuation; 3. untyped declarations; 4. the variable to | 378 ;; declaration with optional type, e.g. `real', `real*4', |
380 ;; index. [This will be fooled by `end function' allowed by G77. | 379 ;; character(*), `double precision' and possible statement |
381 ;; Also, it assumes sensible whitespace is employed.] | 380 ;; continuation; 3. untyped declarations; 4. the variable to |
382 "^\\s-+\\(\ | 381 ;; index. [This will be fooled by `end function' allowed by G77. |
382 ;; Also, it assumes sensible whitespace is employed.] | |
383 (concat "^\\s-+\\(\ | |
383 \\(\\sw\\|\\s-\\|[*()+]\\)*\\<function\\|\ | 384 \\(\\sw\\|\\s-\\|[*()+]\\)*\\<function\\|\ |
384 subroutine\\|entry\\|block\\s-*data\\|program\\)[ \t+]+\ | 385 subroutine\\|entry\\|block\\s-*data\\|program\\)[ \t" fortran-continuation-string "]+\ |
385 \\(\\sw+\\)" | 386 \\(\\sw+\\)") |
386 3) | 387 3) |
387 ;; Un-named block data | 388 ;; Un-named block data |
388 (nil "^\\s-+\\(block\\s-*data\\)\\s-*$" 1)) | 389 (list nil "^\\s-+\\(block\\s-*data\\)\\s-*$" 1)) |
389 "imenu generic expression for `imenu-default-create-index-function'.") | 390 "imenu generic expression for `imenu-default-create-index-function'.") |
390 | 391 |
391 (defvar fortran-mode-map () | 392 (defvar fortran-mode-map () |
392 "Keymap used in Fortran mode.") | 393 "Keymap used in Fortran mode.") |
393 (if fortran-mode-map | 394 (if fortran-mode-map |
404 (define-key fortran-mode-map "\e\C-q" 'fortran-indent-subprogram) | 405 (define-key fortran-mode-map "\e\C-q" 'fortran-indent-subprogram) |
405 (define-key fortran-mode-map "\C-c\C-w" 'fortran-window-create-momentarily) | 406 (define-key fortran-mode-map "\C-c\C-w" 'fortran-window-create-momentarily) |
406 (define-key fortran-mode-map "\C-c\C-r" 'fortran-column-ruler) | 407 (define-key fortran-mode-map "\C-c\C-r" 'fortran-column-ruler) |
407 (define-key fortran-mode-map "\C-c\C-p" 'fortran-previous-statement) | 408 (define-key fortran-mode-map "\C-c\C-p" 'fortran-previous-statement) |
408 (define-key fortran-mode-map "\C-c\C-n" 'fortran-next-statement) | 409 (define-key fortran-mode-map "\C-c\C-n" 'fortran-next-statement) |
410 (define-key fortran-mode-map "\C-c\C-d" 'fortran-join-line) | |
409 (define-key fortran-mode-map "\t" 'fortran-indent-line) | 411 (define-key fortran-mode-map "\t" 'fortran-indent-line) |
410 (define-key fortran-mode-map "0" 'fortran-electric-line-number) | 412 (define-key fortran-mode-map "0" 'fortran-electric-line-number) |
411 (define-key fortran-mode-map "1" 'fortran-electric-line-number) | 413 (define-key fortran-mode-map "1" 'fortran-electric-line-number) |
412 (define-key fortran-mode-map "2" 'fortran-electric-line-number) | 414 (define-key fortran-mode-map "2" 'fortran-electric-line-number) |
413 (define-key fortran-mode-map "3" 'fortran-electric-line-number) | 415 (define-key fortran-mode-map "3" 'fortran-electric-line-number) |
414 (define-key fortran-mode-map "4" 'fortran-electric-line-number) | 416 (define-key fortran-mode-map "4" 'fortran-electric-line-number) |
415 (define-key fortran-mode-map "5" 'fortran-electric-line-number) | 417 (define-key fortran-mode-map "5" 'fortran-electric-line-number) |
416 (define-key fortran-mode-map "6" 'fortran-electric-line-number) | 418 (define-key fortran-mode-map "6" 'fortran-electric-line-number) |
417 (define-key fortran-mode-map "7" 'fortran-electric-line-number) | 419 (define-key fortran-mode-map "7" 'fortran-electric-line-number) |
418 (define-key fortran-mode-map "8" 'fortran-electric-line-number) | 420 (define-key fortran-mode-map "8" 'fortran-electric-line-number) |
419 (define-key fortran-mode-map "9" 'fortran-electric-line-number)) | 421 (define-key fortran-mode-map "9" 'fortran-electric-line-number) |
422 | |
423 ;; Menu | |
424 (unless (boundp 'fortran-mode-menu) | |
425 (easy-menu-define | |
426 fortran-mode-menu fortran-mode-map "" | |
427 '("Fortran" | |
428 ["Toggle Auto-fill" fortran-auto-fill-mode :style toggle | |
429 :selected (eq auto-fill-function 'fortran-do-auto-fill)] | |
430 ["Toggle abbrev-mode" abbrev-mode :style toggle :selected abbrev-mode] | |
431 "----" | |
432 ["Comment-out Region" fortran-comment-region mark-active] | |
433 ["Uncomment-out region" | |
434 (fortran-comment-region (region-beginning) (region-end) 1) | |
435 mark-active] | |
436 ["Indent Region" indent-region mark-active] | |
437 ["Indent Subprogram" fortran-indent-subprogram t] | |
438 "----" | |
439 ["Beginning of Subprogram" beginning-of-fortran-subprogram t] | |
440 ["End of Subprogram" end-of-fortran-subprogram t] | |
441 ("Mark" | |
442 ["Subprogram" mark-fortran-subprogram t] | |
443 ["IF Block" fortran-mark-if t] | |
444 ["DO Block" fortran-mark-do t]) | |
445 ["Narrow to Subprogram" fortran-narrow-to-subprogram t] | |
446 ["Widen" widen t] | |
447 "----" | |
448 ["Temporary column ruler" fortran-column-ruler t] | |
449 ["72-column window" fortran-window-create t] | |
450 ["Full Width Window" | |
451 (enlarge-window-horizontally (- (frame-width) (window-width))) | |
452 (< (window-width) (frame-width))] | |
453 ["Momentary 72-column window" fortran-window-create-momentarily t] | |
454 "----" | |
455 ["Break Line at Point" fortran-split-line t] | |
456 ["Join Continuation Line" fortran-join-line t] | |
457 "----" | |
458 ["Add imenu menu" | |
459 (progn (imenu-add-to-menubar "Index") | |
460 ;; Prod menu bar to update -- is this the right way? | |
461 (menu-bar-mode 1)) | |
462 t])))) | |
420 | 463 |
421 (defvar fortran-mode-abbrev-table nil) | 464 (defvar fortran-mode-abbrev-table nil) |
422 (if fortran-mode-abbrev-table | 465 (if fortran-mode-abbrev-table |
423 () | 466 () |
424 (let ((ac abbrevs-changed)) | 467 (let ((ac abbrevs-changed)) |
481 (define-abbrev fortran-mode-abbrev-table ";vo" "volatile" nil) | 524 (define-abbrev fortran-mode-abbrev-table ";vo" "volatile" nil) |
482 (define-abbrev fortran-mode-abbrev-table ";w" "write" nil) | 525 (define-abbrev fortran-mode-abbrev-table ";w" "write" nil) |
483 (define-abbrev fortran-mode-abbrev-table ";wh" "where" nil) | 526 (define-abbrev fortran-mode-abbrev-table ";wh" "where" nil) |
484 (setq abbrevs-changed ac))) | 527 (setq abbrevs-changed ac))) |
485 | 528 |
529 (eval-when-compile (defvar imenu-syntax-alist nil)) ; silence compiler | |
530 | |
486 ;;;###autoload | 531 ;;;###autoload |
487 (defun fortran-mode () | 532 (defun fortran-mode () |
488 "Major mode for editing Fortran code. | 533 "Major mode for editing Fortran code. |
489 \\[fortran-indent-line] indents the current Fortran line correctly. | 534 \\[fortran-indent-line] indents the current Fortran line correctly. |
490 DO statements must not share a common CONTINUE. | 535 DO statements must not share a common CONTINUE. |
548 Non-nil causes line number digits to be moved to the correct column | 593 Non-nil causes line number digits to be moved to the correct column |
549 as typed. (default t) | 594 as typed. (default t) |
550 fortran-break-before-delimiters | 595 fortran-break-before-delimiters |
551 Non-nil causes `fortran-fill' breaks lines before delimiters. | 596 Non-nil causes `fortran-fill' breaks lines before delimiters. |
552 (default t) | 597 (default t) |
553 fortran-startup-message | |
554 Set to nil to inhibit message first time Fortran mode is used. | |
555 | 598 |
556 Turning on Fortran mode calls the value of the variable `fortran-mode-hook' | 599 Turning on Fortran mode calls the value of the variable `fortran-mode-hook' |
557 with no args, if that value is non-nil." | 600 with no args, if that value is non-nil." |
558 (interactive) | 601 (interactive) |
559 (kill-all-local-variables) | 602 (kill-all-local-variables) |
560 (if fortran-startup-message | |
561 (message "Emacs Fortran mode %s. Bugs to %s" | |
562 fortran-mode-version bug-fortran-mode)) | |
563 (setq fortran-startup-message nil) | |
564 (setq local-abbrev-table fortran-mode-abbrev-table) | 603 (setq local-abbrev-table fortran-mode-abbrev-table) |
565 (set-syntax-table fortran-mode-syntax-table) | 604 (set-syntax-table fortran-mode-syntax-table) |
566 ;; Font Lock mode support. | 605 ;; Font Lock mode support. |
567 (make-local-variable 'font-lock-defaults) | 606 (make-local-variable 'font-lock-defaults) |
568 (setq font-lock-defaults '((fortran-font-lock-keywords | 607 (setq font-lock-defaults '((fortran-font-lock-keywords |
569 fortran-font-lock-keywords-1 | 608 fortran-font-lock-keywords-1 |
570 fortran-font-lock-keywords-2 | 609 fortran-font-lock-keywords-2 |
571 fortran-font-lock-keywords-3) | 610 fortran-font-lock-keywords-3) |
572 t t ((?/ . "$/")))) | 611 t t ((?/ . "$/") ("_$" . "w")))) |
573 (make-local-variable 'fortran-break-before-delimiters) | 612 (make-local-variable 'fortran-break-before-delimiters) |
574 (setq fortran-break-before-delimiters t) | 613 (setq fortran-break-before-delimiters t) |
575 (make-local-variable 'indent-line-function) | 614 (make-local-variable 'indent-line-function) |
576 (setq indent-line-function 'fortran-indent-line) | 615 (setq indent-line-function 'fortran-indent-line) |
577 (make-local-variable 'comment-indent-function) | 616 (make-local-variable 'comment-indent-function) |
603 (make-local-variable 'fortran-column-ruler-fixed) | 642 (make-local-variable 'fortran-column-ruler-fixed) |
604 (make-local-variable 'fortran-column-ruler-tab) | 643 (make-local-variable 'fortran-column-ruler-tab) |
605 (make-local-variable 'fortran-tab-mode-string) | 644 (make-local-variable 'fortran-tab-mode-string) |
606 (setq fortran-tab-mode-string " TAB-format") | 645 (setq fortran-tab-mode-string " TAB-format") |
607 (setq indent-tabs-mode (fortran-analyze-file-format)) | 646 (setq indent-tabs-mode (fortran-analyze-file-format)) |
647 (setq imenu-case-fold-search t) | |
608 (make-local-variable 'imenu-generic-expression) | 648 (make-local-variable 'imenu-generic-expression) |
609 (setq imenu-generic-expression fortran-imenu-generic-expression) | 649 (setq imenu-generic-expression fortran-imenu-generic-expression) |
650 (setq imenu-syntax-alist '(("_$" . "w"))) | |
610 (run-hooks 'fortran-mode-hook)) | 651 (run-hooks 'fortran-mode-hook)) |
611 | 652 |
612 (defun fortran-comment-hook () | 653 (defun fortran-comment-hook () |
613 (save-excursion | 654 (save-excursion |
614 (skip-chars-backward " \t") | 655 (skip-chars-backward " \t") |
617 | 658 |
618 (defun fortran-indent-comment () | 659 (defun fortran-indent-comment () |
619 "Align or create comment on current line. | 660 "Align or create comment on current line. |
620 Existing comments of all types are recognized and aligned. | 661 Existing comments of all types are recognized and aligned. |
621 If the line has no comment, a side-by-side comment is inserted and aligned | 662 If the line has no comment, a side-by-side comment is inserted and aligned |
622 if the value of comment-start is not nil. | 663 if the value of `comment-start' is not nil. |
623 Otherwise, a separate-line comment is inserted, on this line | 664 Otherwise, a separate-line comment is inserted, on this line |
624 or on a new line inserted before this line if this line is not blank." | 665 or on a new line inserted before this line if this line is not blank." |
625 (interactive) | 666 (interactive) |
626 (beginning-of-line) | 667 (beginning-of-line) |
627 ;; Recognize existing comments of either kind. | 668 ;; Recognize existing comments of either kind. |
656 fortran-comment-indent-char) | 697 fortran-comment-indent-char) |
657 (- (calculate-fortran-indent) (current-column)))))) | 698 (- (calculate-fortran-indent) (current-column)))))) |
658 | 699 |
659 (defun fortran-comment-region (beg-region end-region arg) | 700 (defun fortran-comment-region (beg-region end-region arg) |
660 "Comments every line in the region. | 701 "Comments every line in the region. |
661 Puts fortran-comment-region at the beginning of every line in the region. | 702 Puts `fortran-comment-region' at the beginning of every line in the region. |
662 BEG-REGION and END-REGION are args which specify the region boundaries. | 703 BEG-REGION and END-REGION are args which specify the region boundaries. |
663 With non-nil ARG, uncomments the region." | 704 With non-nil ARG, uncomments the region." |
664 (interactive "*r\nP") | 705 (interactive "*r\nP") |
665 (let ((end-region-mark (make-marker)) (save-point (point-marker))) | 706 (let ((end-region-mark (make-marker)) (save-point (point-marker))) |
666 (set-marker end-region-mark end-region) | 707 (set-marker end-region-mark end-region) |
709 (set-buffer-modified-p nil) | 750 (set-buffer-modified-p nil) |
710 (edit-abbrevs-mode)) | 751 (edit-abbrevs-mode)) |
711 (get-buffer-create "*Abbrevs*")) | 752 (get-buffer-create "*Abbrevs*")) |
712 | 753 |
713 (defun fortran-column-ruler () | 754 (defun fortran-column-ruler () |
714 "Inserts a column ruler momentarily above current line, till next keystroke. | 755 "Insert a column ruler momentarily above current line, till next keystroke. |
715 The ruler is defined by the value of `fortran-column-ruler-fixed' when in fixed | 756 The ruler is defined by the value of `fortran-column-ruler-fixed' when in fixed |
716 format mode, and `fortran-column-ruler-tab' when in TAB format mode. | 757 format mode, and `fortran-column-ruler-tab' when in TAB format mode. |
717 The key typed is executed unless it is SPC." | 758 The key typed is executed unless it is SPC." |
718 (interactive) | 759 (interactive) |
719 (momentary-string-display | 760 (momentary-string-display |
727 (progn (forward-line) (point)) | 768 (progn (forward-line) (point)) |
728 (point))) | 769 (point))) |
729 nil "Type SPC or any command to erase ruler.")) | 770 nil "Type SPC or any command to erase ruler.")) |
730 | 771 |
731 (defun fortran-window-create () | 772 (defun fortran-window-create () |
732 "Makes the window 72 columns wide. | 773 "Make the window 72 columns wide. |
733 See also `fortran-window-create-momentarily'." | 774 See also `fortran-window-create-momentarily'." |
734 (interactive) | 775 (interactive) |
735 (condition-case error | 776 (condition-case error |
736 (progn | 777 (progn |
737 (let ((window-min-width 2)) | 778 (let ((window-min-width 2)) |
744 (select-window (previous-window)))) | 785 (select-window (previous-window)))) |
745 (error (message "No room for Fortran window.") | 786 (error (message "No room for Fortran window.") |
746 'error))) | 787 'error))) |
747 | 788 |
748 (defun fortran-window-create-momentarily (&optional arg) | 789 (defun fortran-window-create-momentarily (&optional arg) |
749 "Momentarily makes the window 72 columns wide. | 790 "Momentarily make the window 72 columns wide. |
750 Optional ARG non-nil and non-unity disables the momentary feature. | 791 Optional ARG non-nil and non-unity disables the momentary feature. |
751 See also `fortran-window-create'." | 792 See also `fortran-window-create'." |
752 (interactive "p") | 793 (interactive "p") |
753 (if (or (not arg) | 794 (if (or (not arg) |
754 (= arg 1)) | 795 (= arg 1)) |
771 (insert "\n\t") | 812 (insert "\n\t") |
772 (insert-char (fortran-numerical-continuation-char) 1)) | 813 (insert-char (fortran-numerical-continuation-char) 1)) |
773 (insert "\n " fortran-continuation-string)));Space after \n important | 814 (insert "\n " fortran-continuation-string)));Space after \n important |
774 (fortran-indent-line)) ;when the cont string is C, c or *. | 815 (fortran-indent-line)) ;when the cont string is C, c or *. |
775 | 816 |
817 (defun fortran-join-line () | |
818 "Join a continuation line to the previous one and re-indent." | |
819 (interactive) | |
820 (save-excursion | |
821 (beginning-of-line) | |
822 (cond ((looking-at " \\S-") | |
823 (delete-region (1- (point)) (+ (point) 7))) | |
824 ((looking-at "&") | |
825 (delete-region (1- (point)) (1+ (point)))) | |
826 ((looking-at " *\t[1-9]") | |
827 (apply 'delete-region (match-data)) | |
828 (delete-backward-char 1)) | |
829 (t (error "This isn't a continuation line"))) | |
830 (just-one-space) | |
831 (fortran-indent-line))) | |
832 | |
776 (defun fortran-numerical-continuation-char () | 833 (defun fortran-numerical-continuation-char () |
777 "Return a digit for tab-digit style of continuation lines. | 834 "Return a digit for tab-digit style of continuation lines. |
778 If, previous line is a tab-digit continuation line, returns that digit | 835 If, previous line is a tab-digit continuation line, returns that digit |
779 plus one. Otherwise return 1. Zero not allowed." | 836 plus one. Otherwise return 1. Zero not allowed." |
780 (save-excursion | 837 (save-excursion |
791 (skip-chars-backward chars) | 848 (skip-chars-backward chars) |
792 (delete-region (point) (progn (skip-chars-forward chars) (point)))) | 849 (delete-region (point) (progn (skip-chars-forward chars) (point)))) |
793 | 850 |
794 (defun fortran-electric-line-number (arg) | 851 (defun fortran-electric-line-number (arg) |
795 "Self insert, but if part of a Fortran line number indent it automatically. | 852 "Self insert, but if part of a Fortran line number indent it automatically. |
796 Auto-indent does not happen if a numeric arg is used." | 853 Auto-indent does not happen if a numeric ARG is used." |
797 (interactive "P") | 854 (interactive "P") |
798 (if (or arg (not fortran-electric-line-number)) | 855 (if (or arg (not fortran-electric-line-number)) |
799 (if arg | 856 (if arg |
800 (self-insert-command (prefix-numeric-value arg)) | 857 (self-insert-command (prefix-numeric-value arg)) |
801 (self-insert-command 1)) | 858 (self-insert-command 1)) |
894 (looking-at " [^ 0\n]") | 951 (looking-at " [^ 0\n]") |
895 (looking-at "\t[1-9]") | 952 (looking-at "\t[1-9]") |
896 (looking-at (concat "[ \t]*" comment-start-skip))))) | 953 (looking-at (concat "[ \t]*" comment-start-skip))))) |
897 (if (not not-last-statement) | 954 (if (not not-last-statement) |
898 'last-statement))) | 955 'last-statement))) |
956 | |
957 (defun fortran-narrow-to-subprogram () | |
958 "Make text outside the current subprogram invisible. | |
959 The subprogram visible is the one that contains or follows point." | |
960 (interactive) | |
961 (save-excursion | |
962 (mark-fortran-subprogram) | |
963 (narrow-to-region (region-beginning) | |
964 (region-end)))) | |
899 | 965 |
900 (defun fortran-blink-matching-if () | 966 (defun fortran-blink-matching-if () |
901 ;; From a Fortran ENDIF statement, blink the matching IF statement. | 967 ;; From a Fortran ENDIF statement, blink the matching IF statement. |
902 (let ((top-of-window (window-start)) matching-if | 968 (let ((top-of-window (window-start)) matching-if |
903 (endif-point (point)) message) | 969 (endif-point (point)) message) |
1123 (and (= count 0) | 1189 (and (= count 0) |
1124 ;; All pairs accounted for. | 1190 ;; All pairs accounted for. |
1125 (point)))))) | 1191 (point)))))) |
1126 | 1192 |
1127 (defun fortran-indent-line () | 1193 (defun fortran-indent-line () |
1128 "Indents current Fortran line based on its contents and on previous lines." | 1194 "Indent current Fortran line based on its contents and on previous lines." |
1129 (interactive) | 1195 (interactive) |
1130 (let ((cfi (calculate-fortran-indent))) | 1196 (let ((cfi (calculate-fortran-indent))) |
1131 (save-excursion | 1197 (save-excursion |
1132 (beginning-of-line) | 1198 (beginning-of-line) |
1133 (if (or (not (= cfi (fortran-current-line-indentation))) | 1199 (if (or (not (= cfi (fortran-current-line-indentation))) |
1145 (> (save-excursion (end-of-line) (current-column)) fill-column)) | 1211 (> (save-excursion (end-of-line) (current-column)) fill-column)) |
1146 (save-excursion | 1212 (save-excursion |
1147 (end-of-line) | 1213 (end-of-line) |
1148 (fortran-fill))) | 1214 (fortran-fill))) |
1149 (if fortran-blink-matching-if | 1215 (if fortran-blink-matching-if |
1150 (progn | 1216 (progn |
1151 (fortran-blink-matching-if) | 1217 (fortran-blink-matching-if) |
1152 (fortran-blink-matching-do))))) | 1218 (fortran-blink-matching-do))))) |
1153 | 1219 |
1154 (defun fortran-indent-new-line () | 1220 (defun fortran-indent-new-line () |
1155 "Reindent the current Fortran line, insert a newline and indent the newline. | 1221 "Reindent the current Fortran line, insert a newline and indent the newline. |
1166 (fortran-indent-line))) | 1232 (fortran-indent-line))) |
1167 (newline) | 1233 (newline) |
1168 (fortran-indent-line)) | 1234 (fortran-indent-line)) |
1169 | 1235 |
1170 (defun fortran-indent-subprogram () | 1236 (defun fortran-indent-subprogram () |
1171 "Properly indents the Fortran subprogram which contains point." | 1237 "Properly indent the Fortran subprogram which contains point." |
1172 (interactive) | 1238 (interactive) |
1173 (save-excursion | 1239 (save-excursion |
1174 (mark-fortran-subprogram) | 1240 (mark-fortran-subprogram) |
1175 (message "Indenting subprogram...") | 1241 (message "Indenting subprogram...") |
1176 (indent-region (point) (mark) nil)) | 1242 (indent-region (point) (mark) nil)) |
1303 ;; Move past whitespace. | 1369 ;; Move past whitespace. |
1304 (skip-chars-forward " \t") | 1370 (skip-chars-forward " \t") |
1305 (current-column))) | 1371 (current-column))) |
1306 | 1372 |
1307 (defun fortran-indent-to-column (col) | 1373 (defun fortran-indent-to-column (col) |
1308 "Indents current line with spaces to column COL. | 1374 "Indent current line with spaces to column COL. |
1309 notes: 1) A non-zero/non-blank character in column 5 indicates a continuation | 1375 notes: 1) A non-zero/non-blank character in column 5 indicates a continuation |
1310 line, and this continuation character is retained on indentation; | 1376 line, and this continuation character is retained on indentation; |
1311 2) If `fortran-continuation-string' is the first non-whitespace | 1377 2) If `fortran-continuation-string' is the first non-whitespace |
1312 character, this is a continuation line; | 1378 character, this is a continuation line; |
1313 3) A non-continuation line which has a number as the first | 1379 3) A non-continuation line which has a number as the first |
1378 (or (= (current-column) fortran-line-number-indent) | 1444 (or (= (current-column) fortran-line-number-indent) |
1379 (progn (skip-chars-forward "0-9") | 1445 (progn (skip-chars-forward "0-9") |
1380 (= (current-column) 5)))))) | 1446 (= (current-column) 5)))))) |
1381 | 1447 |
1382 (defun fortran-check-for-matching-do () | 1448 (defun fortran-check-for-matching-do () |
1383 "When called from a numbered statement, returns t if matching DO is found. | 1449 "When called from a numbered statement, return t if matching DO is found. |
1384 Otherwise return a nil." | 1450 Otherwise return nil." |
1385 (let (charnum | 1451 (let (charnum |
1386 (case-fold-search t)) | 1452 (case-fold-search t)) |
1387 (save-excursion | 1453 (save-excursion |
1388 (beginning-of-line) | 1454 (beginning-of-line) |
1389 (if (looking-at "[ \t]*[0-9]+") | 1455 (if (looking-at "[ \t]*[0-9]+") |
1446 ;; found)) | 1512 ;; found)) |
1447 | 1513 |
1448 ;;;From: ralf@up3aud1.gwdg.de (Ralf Fassel) | 1514 ;;;From: ralf@up3aud1.gwdg.de (Ralf Fassel) |
1449 ;;; Test if TAB format continuation lines work. | 1515 ;;; Test if TAB format continuation lines work. |
1450 (defun fortran-is-in-string-p (where) | 1516 (defun fortran-is-in-string-p (where) |
1451 "Return non-nil if POS (a buffer position) is inside a Fortran string, | 1517 "Return non-nil iff WHERE (a buffer position) is inside a Fortran string." |
1452 nil else." | |
1453 (save-excursion | 1518 (save-excursion |
1454 (goto-char where) | 1519 (goto-char where) |
1455 (cond | 1520 (cond |
1456 ((bolp) nil) ; bol is never inside a string | 1521 ((bolp) nil) ; bol is never inside a string |
1457 ((save-excursion ; comment lines too | 1522 ((save-excursion ; comment lines too |
1634 (delete-horizontal-space) | 1699 (delete-horizontal-space) |
1635 (indent-to (fortran-comment-hook)) | 1700 (indent-to (fortran-comment-hook)) |
1636 (insert comment-string))))) | 1701 (insert comment-string))))) |
1637 | 1702 |
1638 (defun fortran-analyze-file-format () | 1703 (defun fortran-analyze-file-format () |
1639 "Returns nil if fixed format is used, t if TAB formatting is used. | 1704 "Return nil if fixed format is used, t if TAB formatting is used. |
1640 Use `fortran-tab-mode-default' if no non-comment statements are found in the | 1705 Use `fortran-tab-mode-default' if no non-comment statements are found in the |
1641 file before the end or the first `fortran-analyze-depth' lines." | 1706 file before the end or the first `fortran-analyze-depth' lines." |
1642 (let ((i 0)) | 1707 (let ((i 0)) |
1643 (save-excursion | 1708 (save-excursion |
1644 (goto-char (point-min)) | 1709 (goto-char (point-min)) |