aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Love2000-07-11 17:56:56 +0000
committerDave Love2000-07-11 17:56:56 +0000
commit315aa1de5cfdadbe91bfc8a51cb061f98d08f7a3 (patch)
tree6c4402509df72b20631461cd3fc225b287a440f5
parent89492072de2a6ddd787eecb83a9f4ecd0bbec801 (diff)
downloademacs-315aa1de5cfdadbe91bfc8a51cb061f98d08f7a3.tar.gz
emacs-315aa1de5cfdadbe91bfc8a51cb061f98d08f7a3.zip
Don't require easymenu. Use repeat counts in various regexps.
(fortran-mode-syntax-table): Defvar directly. (fortran-font-lock-keywords-1, fortran-font-lock-keywords-2) (fortran-font-lock-keywords-3, fortran-font-lock-syntactic-keywords): Use defvar, not defconst. (fortran-mode-map): Change locals in `let'. Use `fortran-auto-fill'. (fortran-mode): Set fortran-comment-line-start-skip, fortran-comment-line-start-skip, dabbrev-case-fold-search. (fortran-comment-indent): Use defsubst. (fortran-indent-comment, fortran-indent-to-column, fortran-break-line): Use fortran-comment-indent, not fortran-comment-indent-function. (fortran-comment-region, fortran-electric-line-number): Simplify. (fortran-auto-fill): New function. (fortran-do-auto-fill): Deleted. (fortran-find-comment-start-skip): Check for non-null comment-start-skip. (fortran-auto-fill-mode, fortran-fill-statement): Use fortran-auto-fill. (fortran-fill): Use fortran-auto-fill. Check for null comment-start-skip. Simplify final clause and use end-of-line finally.
-rw-r--r--lisp/ChangeLog25
-rw-r--r--lisp/progmodes/fortran.el299
2 files changed, 183 insertions, 141 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2599d0dce48..9b3a21770c1 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,30 @@
12000-07-11 Dave Love <fx@gnu.org> 12000-07-11 Dave Love <fx@gnu.org>
2 2
3 * progmodes/fortran.el: Don't require easymenu. Use repeat counts
4 in various regexps.
5 (fortran-mode-syntax-table): Defvar directly.
6 (fortran-font-lock-keywords-1, fortran-font-lock-keywords-2)
7 (fortran-font-lock-keywords-3,
8 fortran-font-lock-syntactic-keywords): Use defvar, not defconst.
9 (fortran-mode-map): Change locals in `let'. Use
10 `fortran-auto-fill'.
11 (fortran-mode): Set fortran-comment-line-start-skip,
12 fortran-comment-line-start-skip, dabbrev-case-fold-search.
13 (fortran-comment-indent): Use defsubst.
14 (fortran-indent-comment, fortran-indent-to-column,
15 fortran-break-line): Use fortran-comment-indent, not
16 fortran-comment-indent-function.
17 (fortran-comment-region, fortran-electric-line-number): Simplify.
18 (fortran-auto-fill): New function.
19 (fortran-do-auto-fill): Deleted.
20 (fortran-find-comment-start-skip): Check for non-null
21 comment-start-skip.
22 (fortran-auto-fill-mode, fortran-fill-statement): Use
23 fortran-auto-fill.
24 (fortran-fill): Use fortran-auto-fill. Check for null
25 comment-start-skip. Simplify final clause and use end-of-line
26 finally.
27
3 * widget.el (widget-plist-member): New alias. 28 * widget.el (widget-plist-member): New alias.
4 29
52000-07-11 Eli Zaretskii <eliz@is.elta.co.il> 302000-07-11 Eli Zaretskii <eliz@is.elta.co.il>
diff --git a/lisp/progmodes/fortran.el b/lisp/progmodes/fortran.el
index 9ae439f192e..fe1850cddaa 100644
--- a/lisp/progmodes/fortran.el
+++ b/lisp/progmodes/fortran.el
@@ -1,6 +1,7 @@
1;;; fortran.el --- Fortran mode for GNU Emacs 1;;; fortran.el --- Fortran mode for GNU Emacs
2 2
3;; Copyright (c) 1986, 93, 94, 95, 97, 98, 99, 2000 Free Software Foundation, Inc. 3;; Copyright (c) 1986, 93, 94, 95, 97, 98, 99, 2000
4;; Free Software Foundation, Inc.
4 5
5;; Author: Michael D. Prange <prange@erl.mit.edu> 6;; Author: Michael D. Prange <prange@erl.mit.edu>
6;; Maintainer: Dave Love <fx@gnu.org> 7;; Maintainer: Dave Love <fx@gnu.org>
@@ -44,14 +45,12 @@
44 45
45;; Todo: 46;; Todo:
46 47
47;; * Tidy it all up! 48;; * Tidy it all up (more)!
48;; * Implement insertion and removal of statement continuations in 49;; * Implement insertion and removal of statement continuations in
49;; mixed f77/f90 style, with the first `&' past column 72 and the 50;; mixed f77/f90 style, with the first `&' past column 72 and the
50;; second in column 6. 51;; second in column 6.
51;; * Support any other extensions to f77 grokked by GNU Fortran. 52;; * Support any other extensions to f77 grokked by GNU Fortran.
52 53
53(require 'easymenu)
54
55(defgroup fortran nil 54(defgroup fortran nil
56 "Fortran mode for Emacs" 55 "Fortran mode for Emacs"
57 :link '(custom-manual "(emacs)Fortran") 56 :link '(custom-manual "(emacs)Fortran")
@@ -211,9 +210,6 @@ This variable used in fixed format mode.")
211 "String displayed above current line by \\[fortran-column-ruler]. 210 "String displayed above current line by \\[fortran-column-ruler].
212This variable used in TAB format mode.") 211This variable used in TAB format mode.")
213 212
214(defvar fortran-mode-syntax-table nil
215 "Syntax table in use in Fortran mode buffers.")
216
217(defvar fortran-analyze-depth 100 213(defvar fortran-analyze-depth 100
218 "Number of lines to scan to determine whether to use fixed or TAB \ 214 "Number of lines to scan to determine whether to use fixed or TAB \
219format style.") 215format style.")
@@ -223,48 +219,46 @@ format style.")
223 :type 'boolean 219 :type 'boolean
224 :group 'fortran) 220 :group 'fortran)
225 221
226(if fortran-mode-syntax-table 222(defvar fortran-mode-syntax-table
227 () 223 (let ((table (make-syntax-table)))
228 (setq fortran-mode-syntax-table (make-syntax-table)) 224 ;; We might like `;' to be punctuation (g77 multi-statement
229 ;; We might like `;' to be punctuation (g77 multi-statement lines), 225 ;; lines), but that screws abbrevs.
230 ;; but that screws abbrevs. 226 (modify-syntax-entry ?\; "w" table)
231 (modify-syntax-entry ?\; "w" fortran-mode-syntax-table) 227 (modify-syntax-entry ?\r " " table)
232 (modify-syntax-entry ?\r " " fortran-mode-syntax-table) 228 (modify-syntax-entry ?+ "." table)
233 (modify-syntax-entry ?+ "." fortran-mode-syntax-table) 229 (modify-syntax-entry ?- "." table)
234 (modify-syntax-entry ?- "." fortran-mode-syntax-table) 230 (modify-syntax-entry ?= "." table)
235 (modify-syntax-entry ?= "." fortran-mode-syntax-table) 231 (modify-syntax-entry ?* "." table)
236 (modify-syntax-entry ?* "." fortran-mode-syntax-table) 232 (modify-syntax-entry ?/ "." table)
237 (modify-syntax-entry ?/ "." fortran-mode-syntax-table) 233 (modify-syntax-entry ?\' "\"" table)
238 (modify-syntax-entry ?\' "\"" fortran-mode-syntax-table) 234 (modify-syntax-entry ?\" "\"" table)
239 (modify-syntax-entry ?\" "\"" fortran-mode-syntax-table) 235 (modify-syntax-entry ?\\ "\\" table)
240 (modify-syntax-entry ?\\ "\\" fortran-mode-syntax-table) 236 ;; This might be better as punctuation, as for C, but this way you
241 ;; This might be better as punctuation, as for C, but this way you 237 ;; can treat floating-point numbers as symbols.
242 ;; can treat floating-point numbers as symbols. 238 (modify-syntax-entry ?. "_" table) ; e.g. `a.ne.b'
243 (modify-syntax-entry ?. "_" fortran-mode-syntax-table) ; e.g. `a.ne.b' 239 (modify-syntax-entry ?_ "_" table)
244 (modify-syntax-entry ?_ "_" fortran-mode-syntax-table) 240 (modify-syntax-entry ?$ "_" table) ; esp. VMSisms
245 (modify-syntax-entry ?$ "_" fortran-mode-syntax-table) ; esp. VMSisms 241 (modify-syntax-entry ?\! "<" table)
246 (modify-syntax-entry ?\! "<" fortran-mode-syntax-table) 242 (modify-syntax-entry ?\n ">" table)
247 (modify-syntax-entry ?\n ">" fortran-mode-syntax-table)) 243 table)
244 "Syntax table in use in Fortran mode buffers.")
248 245
249;; Comments are real pain in Fortran because there is no way to 246;; Comments are real pain in Fortran because there is no way to
250;; represent the standard comment syntax in an Emacs syntax table. 247;; represent the standard comment syntax in an Emacs syntax table.
251;; (We can do so for F90-style). Therefore an unmatched quote in a 248;; (We can do so for F90-style). Therefore an unmatched quote in a
252;; standard comment will throw fontification off on the wrong track. 249;; standard comment will throw fontification off on the wrong track.
253;; So we do syntactic fontification with regexps. 250;; So we do syntactic fontification with regexps.
254
255;; Regexps done by simon@gnu with help from Ulrik Dickow <dickow@nbi.dk> and
256;; probably others Si's forgotten about (sorry).
257 251
258(defconst fortran-font-lock-keywords-1 nil 252(defvar fortran-font-lock-keywords-1 nil
259 "Subdued level highlighting for Fortran mode.") 253 "Subdued level highlighting for Fortran mode.")
260 254
261(defconst fortran-font-lock-keywords-2 nil 255(defvar fortran-font-lock-keywords-2 nil
262 "Medium level highlighting for Fortran mode.") 256 "Medium level highlighting for Fortran mode.")
263 257
264(defconst fortran-font-lock-keywords-3 nil 258(defvar fortran-font-lock-keywords-3 nil
265 "Gaudy level highlighting for Fortran mode.") 259 "Gaudy level highlighting for Fortran mode.")
266 260
267(defconst fortran-font-lock-syntactic-keywords nil 261(defvar fortran-font-lock-syntactic-keywords nil
268 "`font-lock-syntactic-keywords' for Fortran. 262 "`font-lock-syntactic-keywords' for Fortran.
269These get fixed-format comments fontified.") 263These get fixed-format comments fontified.")
270 264
@@ -289,9 +283,9 @@ These get fixed-format comments fontified.")
289 structured-types) 283 structured-types)
290 structured-types 284 structured-types
291 other-types))))) 285 other-types)))))
292 ;; In the optimized regexp above, replace spaces by regexp 286 ;; In the optimized regexp above, replace spaces by a
293 ;; for optional whitespace, which regexp-opt would have 287 ;; regexp for optional whitespace; regexp-opt would have
294 ;; escaped. 288 ;; escaped that.
295 (mapconcat #'identity (split-string re) "[ \t]*")))) 289 (mapconcat #'identity (split-string re) "[ \t]*"))))
296 (fortran-keywords 290 (fortran-keywords
297 (eval-when-compile 291 (eval-when-compile
@@ -307,7 +301,7 @@ These get fixed-format comments fontified.")
307 ;; Fixed format comments. (!-style handled normally.) 301 ;; Fixed format comments. (!-style handled normally.)
308 (list 302 (list
309 (list (concat "^[" comment-chars "]") 0 '(11)) 303 (list (concat "^[" comment-chars "]") 0 '(11))
310 (list (concat "^[^" comment-chars "\t\n]" (make-string 71 ?.) 304 (list (concat "^[^" comment-chars "\t\n]" ".\\{71\\}"
311 "\\([^\n]+\\)") 305 "\\([^\n]+\\)")
312 1 '(11)))) 306 1 '(11))))
313 (setq fortran-font-lock-keywords-1 307 (setq fortran-font-lock-keywords-1
@@ -401,33 +395,33 @@ These get fixed-format comments fontified.")
401 "Imenu generic expression for `imenu-default-create-index-function'.") 395 "Imenu generic expression for `imenu-default-create-index-function'.")
402 396
403(defvar fortran-mode-map 397(defvar fortran-mode-map
404 (let ((fortran-mode-map (make-sparse-keymap))) 398 (let ((map (make-sparse-keymap)))
405 (define-key fortran-mode-map ";" 'fortran-abbrev-start) 399 (define-key map ";" 'fortran-abbrev-start)
406 (define-key fortran-mode-map "\C-c;" 'fortran-comment-region) 400 (define-key map "\C-c;" 'fortran-comment-region)
407 (define-key fortran-mode-map "\M-;" 'fortran-indent-comment) 401 (define-key map "\M-;" 'fortran-indent-comment)
408 (define-key fortran-mode-map "\M-\n" 'fortran-split-line) 402 (define-key map "\M-\n" 'fortran-split-line)
409 (define-key fortran-mode-map "\M-\C-q" 'fortran-indent-subprogram) 403 (define-key map "\M-\C-q" 'fortran-indent-subprogram)
410 (define-key fortran-mode-map "\C-c\C-w" 'fortran-window-create-momentarily) 404 (define-key map "\C-c\C-w" 'fortran-window-create-momentarily)
411 (define-key fortran-mode-map "\C-c\C-r" 'fortran-column-ruler) 405 (define-key map "\C-c\C-r" 'fortran-column-ruler)
412 (define-key fortran-mode-map "\C-c\C-p" 'fortran-previous-statement) 406 (define-key map "\C-c\C-p" 'fortran-previous-statement)
413 (define-key fortran-mode-map "\C-c\C-n" 'fortran-next-statement) 407 (define-key map "\C-c\C-n" 'fortran-next-statement)
414 (define-key fortran-mode-map "\C-c\C-d" 'fortran-join-line) ; like f90 408 (define-key map "\C-c\C-d" 'fortran-join-line) ; like f90
415 (define-key fortran-mode-map "\M-^" 'fortran-join-line) ; subvert delete-indentation 409 (define-key map "\M-^" 'fortran-join-line) ; subvert delete-indentation
416 (define-key fortran-mode-map "0" 'fortran-electric-line-number) 410 (define-key map "0" 'fortran-electric-line-number)
417 (define-key fortran-mode-map "1" 'fortran-electric-line-number) 411 (define-key map "1" 'fortran-electric-line-number)
418 (define-key fortran-mode-map "2" 'fortran-electric-line-number) 412 (define-key map "2" 'fortran-electric-line-number)
419 (define-key fortran-mode-map "3" 'fortran-electric-line-number) 413 (define-key map "3" 'fortran-electric-line-number)
420 (define-key fortran-mode-map "4" 'fortran-electric-line-number) 414 (define-key map "4" 'fortran-electric-line-number)
421 (define-key fortran-mode-map "5" 'fortran-electric-line-number) 415 (define-key map "5" 'fortran-electric-line-number)
422 (define-key fortran-mode-map "6" 'fortran-electric-line-number) 416 (define-key map "6" 'fortran-electric-line-number)
423 (define-key fortran-mode-map "7" 'fortran-electric-line-number) 417 (define-key map "7" 'fortran-electric-line-number)
424 (define-key fortran-mode-map "8" 'fortran-electric-line-number) 418 (define-key map "8" 'fortran-electric-line-number)
425 (define-key fortran-mode-map "9" 'fortran-electric-line-number) 419 (define-key map "9" 'fortran-electric-line-number)
426 420
427 ;; Menu 421 ;; Menu
428 (unless (boundp 'fortran-mode-menu) 422 (unless (boundp 'fortran-mode-menu)
429 (easy-menu-define 423 (easy-menu-define
430 fortran-mode-menu fortran-mode-map "" 424 fortran-mode-menu map ""
431 `("Fortran" 425 `("Fortran"
432 ["Manual" (info "(emacs)Fortran")] 426 ["Manual" (info "(emacs)Fortran")]
433;;; This loads cus-edit as things stand -- needs to be done lazily. 427;;; This loads cus-edit as things stand -- needs to be done lazily.
@@ -439,7 +433,7 @@ These get fixed-format comments fontified.")
439;;; ["Reset to Standard Settings" Custom-reset-standard t] 433;;; ["Reset to Standard Settings" Custom-reset-standard t]
440 "----" 434 "----"
441 ["Toggle Auto-fill" fortran-auto-fill-mode :style toggle 435 ["Toggle Auto-fill" fortran-auto-fill-mode :style toggle
442 :selected (eq auto-fill-function 'fortran-do-auto-fill)] 436 :selected (eq auto-fill-function 'fortran-auto-fill)]
443 ["Toggle abbrev-mode" abbrev-mode :style toggle :selected abbrev-mode] 437 ["Toggle abbrev-mode" abbrev-mode :style toggle :selected abbrev-mode]
444 "----" 438 "----"
445 ["Comment-out Region" fortran-comment-region mark-active] 439 ["Comment-out Region" fortran-comment-region mark-active]
@@ -472,7 +466,7 @@ These get fixed-format comments fontified.")
472 ["Add imenu menu" 466 ["Add imenu menu"
473 imenu-add-menubar-index (not (and (boundp 'imenu--index-alist) 467 imenu-add-menubar-index (not (and (boundp 'imenu--index-alist)
474 imenu--index-alist))]))) 468 imenu--index-alist))])))
475 fortran-mode-map) 469 map)
476 "Keymap used in Fortran mode.") 470 "Keymap used in Fortran mode.")
477 471
478(defvar fortran-mode-abbrev-table 472(defvar fortran-mode-abbrev-table
@@ -563,8 +557,8 @@ Key definitions:
563Variables controlling indentation style and extra features: 557Variables controlling indentation style and extra features:
564 558
565 `comment-start' 559 `comment-start'
566 Normally nil in Fortran mode. If you want to use comments 560 If you want to use comments starting with `!',
567 starting with `!', set this to the string \"!\". 561 set this to the string \"!\".
568 `fortran-do-indent' 562 `fortran-do-indent'
569 Extra indentation within do blocks. (default 3) 563 Extra indentation within do blocks. (default 3)
570 `fortran-if-indent' 564 `fortran-if-indent'
@@ -637,11 +631,13 @@ with no args, if that value is non-nil."
637 (make-local-variable 'indent-line-function) 631 (make-local-variable 'indent-line-function)
638 (setq indent-line-function 'fortran-indent-line) 632 (setq indent-line-function 'fortran-indent-line)
639 (make-local-variable 'comment-indent-function) 633 (make-local-variable 'comment-indent-function)
640 (setq comment-indent-function 'fortran-comment-indent-function) 634 (setq comment-indent-function 'fortran-comment-indent)
641 (make-local-variable 'comment-start-skip) 635 (make-local-variable 'comment-start-skip)
642 (setq comment-start-skip "![ \t]*") 636 (setq comment-start-skip "![ \t]*")
637 (setq fortran-comment-line-start-skip
638 "^[Cc*]\\(\\([^ \t\n]\\)\\2\\2*\\)?[ \t]*\\|^#.*")
643 (make-local-variable 'comment-start) 639 (make-local-variable 'comment-start)
644 (setq comment-start "C") 640 (setq fortran-comment-line-start "c")
645 (make-local-variable 'require-final-newline) 641 (make-local-variable 'require-final-newline)
646 (setq require-final-newline t) 642 (setq require-final-newline t)
647 (make-local-variable 'abbrev-all-caps) 643 (make-local-variable 'abbrev-all-caps)
@@ -676,9 +672,10 @@ with no args, if that value is non-nil."
676 #'fortran-end-of-subprogram) 672 #'fortran-end-of-subprogram)
677 (set (make-local-variable 'add-log-current-defun-function) 673 (set (make-local-variable 'add-log-current-defun-function)
678 #'fortran-current-defun) 674 #'fortran-current-defun)
675 (set (make-local-variable 'dabbrev-case-fold-search) 'case-fold-search)
679 (run-hooks 'fortran-mode-hook)) 676 (run-hooks 'fortran-mode-hook))
680 677
681(defun fortran-comment-indent-function () 678(defsubst fortran-comment-indent ()
682 (save-excursion 679 (save-excursion
683 (skip-chars-backward " \t") 680 (skip-chars-backward " \t")
684 (max (+ 1 (current-column)) 681 (max (+ 1 (current-column))
@@ -700,9 +697,10 @@ or on a new line inserted before this line if this line is not blank."
700 ; leaves point after comment-start-skip 697 ; leaves point after comment-start-skip
701 (if comment-start-skip 698 (if comment-start-skip
702 (progn (goto-char (match-beginning 0)) 699 (progn (goto-char (match-beginning 0))
703 (if (not (= (current-column) (fortran-comment-indent-function))) 700 (if (not (= (current-column)
701 (fortran-comment-indent)))
704 (progn (delete-horizontal-space) 702 (progn (delete-horizontal-space)
705 (indent-to (fortran-comment-indent-function))))) 703 (indent-to (fortran-comment-indent)))))
706 (end-of-line))) ; otherwise goto end of line or sth else? 704 (end-of-line))) ; otherwise goto end of line or sth else?
707 ;; No existing comment. 705 ;; No existing comment.
708 ;; If side-by-side comments are defined, insert one, 706 ;; If side-by-side comments are defined, insert one,
@@ -710,7 +708,7 @@ or on a new line inserted before this line if this line is not blank."
710 ((and comment-start (not (looking-at "^[ \t]*$"))) 708 ((and comment-start (not (looking-at "^[ \t]*$")))
711 (end-of-line) 709 (end-of-line)
712 (delete-horizontal-space) 710 (delete-horizontal-space)
713 (indent-to (fortran-comment-indent-function)) 711 (indent-to (fortran-comment-indent))
714 (insert comment-start)) 712 (insert comment-start))
715 ;; Else insert separate-line comment, making a new line if nec. 713 ;; Else insert separate-line comment, making a new line if nec.
716 (t 714 (t
@@ -731,8 +729,8 @@ Puts `fortran-comment-region' at the beginning of every line in the region.
731BEG-REGION and END-REGION are args which specify the region boundaries. 729BEG-REGION and END-REGION are args which specify the region boundaries.
732With non-nil ARG, uncomments the region." 730With non-nil ARG, uncomments the region."
733 (interactive "*r\nP") 731 (interactive "*r\nP")
734 (let ((end-region-mark (make-marker)) (save-point (point-marker))) 732 (let ((end-region-mark (copy-marker beg-region))
735 (set-marker end-region-mark end-region) 733 (save-point (point-marker)))
736 (goto-char beg-region) 734 (goto-char beg-region)
737 (beginning-of-line) 735 (beginning-of-line)
738 (if (not arg) ;comment the region 736 (if (not arg) ;comment the region
@@ -891,7 +889,7 @@ Auto-indent does not happen if a numeric ARG is used."
891 (if (or (and (= 5 (current-column)) 889 (if (or (and (= 5 (current-column))
892 (save-excursion 890 (save-excursion
893 (beginning-of-line) 891 (beginning-of-line)
894 (looking-at " "))) ;In col 5 with only spaces to left. 892 (looking-at " \\{5\\}"))) ;In col 5 with only spaces to left.
895 (and (= (if indent-tabs-mode 893 (and (= (if indent-tabs-mode
896 fortran-minimum-statement-indent-tab 894 fortran-minimum-statement-indent-tab
897 fortran-minimum-statement-indent-fixed) (current-column)) 895 fortran-minimum-statement-indent-fixed) (current-column))
@@ -971,12 +969,13 @@ non-comment Fortran statement in the file, and nil otherwise."
971 (and 969 (and
972 (not (looking-at fortran-comment-line-start-skip)) 970 (not (looking-at fortran-comment-line-start-skip))
973 (or (looking-at 971 (or (looking-at
974 (concat "[ \t]*" (regexp-quote fortran-continuation-string))) 972 (concat "[ \t]*"
975 (looking-at " [^ 0\n]\\|\t[1-9]")))) 973 (regexp-quote fortran-continuation-string)))
974 (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]"))))
976 (while (and (setq not-first-statement (= (forward-line -1) 0)) 975 (while (and (setq not-first-statement (= (forward-line -1) 0))
977 (or (looking-at fortran-comment-line-start-skip) 976 (or (looking-at fortran-comment-line-start-skip)
978 (looking-at "[ \t]*$\\| [^ 0\n]\\|\t[1-9]") 977 (looking-at "[ \t]*$\\| \\{5\\}[^ 0\n]\\|\t[1-9]")
979 (looking-at (concat "[ \t]*" comment-start-skip))))) 978 (looking-at (concat "[ \t]*" comment-start-skip)))))
980 (cond ((and continue-test 979 (cond ((and continue-test
981 (not not-first-statement)) 980 (not not-first-statement))
982 (message "Incomplete continuation statement.")) 981 (message "Incomplete continuation statement."))
@@ -997,7 +996,7 @@ non-comment Fortran statement in the file, and nil otherwise."
997 (not (eobp)))) 996 (not (eobp))))
998 (or (looking-at fortran-comment-line-start-skip) 997 (or (looking-at fortran-comment-line-start-skip)
999 (looking-at "[ \t]*$\\| [^ 0\n]\\|\t[1-9]") 998 (looking-at "[ \t]*$\\| [^ 0\n]\\|\t[1-9]")
1000 (looking-at (concat "[ \t]*" comment-start-skip))))) 999 (looking-at (concat "[ \t]*" comment-start-skip)))))
1001 (if (not not-last-statement) 1000 (if (not not-last-statement)
1002 'last-statement))) 1001 'last-statement)))
1003 1002
@@ -1148,13 +1147,14 @@ Return point or nil."
1148 (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]") 1147 (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
1149 (let (then-test) ; Multi-line if-then. 1148 (let (then-test) ; Multi-line if-then.
1150 (while 1149 (while
1151 (and (= (forward-line 1) 0) 1150 (and
1152 ;; Search forward for then. 1151 (= (forward-line 1) 0)
1153 (looking-at " [^ 0\n]\\|\t[1-9]") 1152 ;; Search forward for then.
1154 (not 1153 (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]")
1155 (setq then-test 1154 (not
1156 (looking-at 1155 (setq then-test
1157 ".*then\\b[ \t]*[^ \t(=a-z0-9]"))))) 1156 (looking-at
1157 ".*then\\b[ \t]*[^ \t(=a-z0-9]")))))
1158 then-test)) 1158 then-test))
1159 (setq count (+ count 1))))))) 1159 (setq count (+ count 1)))))))
1160 (and (= count 0) 1160 (and (= count 0)
@@ -1183,7 +1183,7 @@ Return point or nil."
1183 (while 1183 (while
1184 (and (= (forward-line 1) 0) 1184 (and (= (forward-line 1) 0)
1185 ;; Search forward for then. 1185 ;; Search forward for then.
1186 (looking-at " [^ 0\n]\\|\t[1-9]") 1186 (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]")
1187 (not 1187 (not
1188 (setq then-test 1188 (setq then-test
1189 (looking-at 1189 (looking-at
@@ -1206,13 +1206,15 @@ Return point or nil."
1206 (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]") 1206 (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
1207 (let (then-test) ; Multi-line if-then. 1207 (let (then-test) ; Multi-line if-then.
1208 (while 1208 (while
1209 (and (= (forward-line 1) 0) 1209 (and
1210 ;; Search forward for then. 1210 (= (forward-line 1) 0)
1211 (looking-at " [^ 0\n]\\|\t[1-9]") 1211 ;; Search forward for then.
1212 (not 1212 (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]")
1213 (setq then-test 1213 (not
1214 (looking-at 1214 (setq then-test
1215 ".*then\\b[ \t]*[^ \t(=a-z0-9]"))))) 1215 (looking-at
1216 (concat ".*then\\b[ \t]*"
1217 "[^ \t(=a-z[0-9]]"))))))
1216 then-test)) 1218 then-test))
1217 (setq count (- count 1))))) 1219 (setq count (- count 1)))))
1218 ((looking-at "end[ \t]*if\\b") 1220 ((looking-at "end[ \t]*if\\b")
@@ -1249,6 +1251,25 @@ Return point or nil."
1249 (fortran-blink-matching-if) 1251 (fortran-blink-matching-if)
1250 (fortran-blink-matching-do))))) 1252 (fortran-blink-matching-do)))))
1251 1253
1254(defun fortran-auto-fill ()
1255 (if (> (current-column) (current-fill-column))
1256 (let ((cfi (fortran-calculate-indent)))
1257 (save-excursion
1258 (beginning-of-line)
1259 (if (or (not (= cfi (fortran-current-line-indentation)))
1260 (and (re-search-forward "^[ \t]*[0-9]+"
1261 (+ (point) 4) t)
1262 (not (fortran-line-number-indented-correctly-p))))
1263 (fortran-indent-to-column cfi)
1264 (beginning-of-line)
1265 (if (and (not (looking-at fortran-comment-line-start-skip))
1266 (fortran-find-comment-start-skip))
1267 (fortran-indent-comment))))
1268 (fortran-fill)
1269 ;; Never leave point in left margin.
1270 (if (< (current-column) cfi)
1271 (move-to-column cfi)))))
1272
1252;; Historically this was a separate function which advertised itself 1273;; Historically this was a separate function which advertised itself
1253;; as reindenting but only did so where `most likely to be necessary'. 1274;; as reindenting but only did so where `most likely to be necessary'.
1254(defalias 'fortran-indent-new-line 'reindent-then-newline-and-indent) 1275(defalias 'fortran-indent-new-line 'reindent-then-newline-and-indent)
@@ -1283,7 +1304,7 @@ Return point or nil."
1283 (let (then-test) ;multi-line if-then 1304 (let (then-test) ;multi-line if-then
1284 (while (and (= (forward-line 1) 0) 1305 (while (and (= (forward-line 1) 0)
1285 ;;search forward for then 1306 ;;search forward for then
1286 (looking-at " [^ 0\n]\\|\t[1-9]") 1307 (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]")
1287 (not (setq then-test 1308 (not (setq then-test
1288 (looking-at 1309 (looking-at
1289 ".*then\\b[ \t]\ 1310 ".*then\\b[ \t]\
@@ -1325,7 +1346,7 @@ Return point or nil."
1325 ((or (looking-at (concat "[ \t]*" 1346 ((or (looking-at (concat "[ \t]*"
1326 (regexp-quote 1347 (regexp-quote
1327 fortran-continuation-string))) 1348 fortran-continuation-string)))
1328 (looking-at " [^ 0\n]\\|\t[1-9]")) 1349 (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]"))
1329 (setq icol (+ icol fortran-continuation-indent))) 1350 (setq icol (+ icol fortran-continuation-indent)))
1330 ((looking-at "[ \t]*#") ; Check for cpp directive. 1351 ((looking-at "[ \t]*#") ; Check for cpp directive.
1331 (setq fortran-minimum-statement-indent 0 icol 0)) 1352 (setq fortran-minimum-statement-indent 0 icol 0))
@@ -1373,7 +1394,7 @@ non-indentation text within the comment."
1373 (if (stringp fortran-comment-indent-char) 1394 (if (stringp fortran-comment-indent-char)
1374 fortran-comment-indent-char 1395 fortran-comment-indent-char
1375 (char-to-string fortran-comment-indent-char)))) 1396 (char-to-string fortran-comment-indent-char))))
1376 ((or (looking-at " [^ 0\n]\\|\t[1-9]")) 1397 ((or (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]"))
1377 (goto-char (match-end 0))) 1398 (goto-char (match-end 0)))
1378 (t 1399 (t
1379 ;; Move past line number. 1400 ;; Move past line number.
@@ -1410,7 +1431,7 @@ notes: 1) A non-zero/non-blank character in column 5 indicates a continuation
1410 (delete-char 2) 1431 (delete-char 2)
1411 (insert-char ? 5) 1432 (insert-char ? 5)
1412 (insert fortran-continuation-string)) 1433 (insert fortran-continuation-string))
1413 (if (looking-at " [^ 0\n]") 1434 (if (looking-at " \\{5\\}[^ 0\n]")
1414 (if indent-tabs-mode 1435 (if indent-tabs-mode
1415 (progn (delete-char 6) 1436 (progn (delete-char 6)
1416 (insert ?\t (fortran-numerical-continuation-char) 1)) 1437 (insert ?\t (fortran-numerical-continuation-char) 1))
@@ -1445,10 +1466,9 @@ notes: 1) A non-zero/non-blank character in column 5 indicates a continuation
1445 (fortran-find-comment-start-skip)) 1466 (fortran-find-comment-start-skip))
1446 (progn (goto-char (match-beginning 0)) 1467 (progn (goto-char (match-beginning 0))
1447 (if (not (= (current-column) 1468 (if (not (= (current-column)
1448 (fortran-comment-indent-function))) 1469 (fortran-comment-indent)))
1449 (progn (delete-horizontal-space) 1470 (progn (delete-horizontal-space)
1450 (indent-to 1471 (indent-to (fortran-comment-indent)))))))))
1451 (fortran-comment-indent-function)))))))))
1452 1472
1453(defun fortran-line-number-indented-correctly-p () 1473(defun fortran-line-number-indented-correctly-p ()
1454 "Return t if current line's line number is correctly indented. 1474 "Return t if current line's line number is correctly indented.
@@ -1481,11 +1501,14 @@ Otherwise return nil."
1481 (save-excursion 1501 (save-excursion
1482 (narrow-to-defun) 1502 (narrow-to-defun)
1483 (and (re-search-backward 1503 (and (re-search-backward
1484 (concat "\\(^[ \t0-9]*do[ \t]*0*" charnum "\\b\\)\\|" 1504 (concat
1485 "\\(^[ \t]*0*" charnum "\\b\\)") 1505 "\\(^[ \t0-9]*do[ \t]*0*"
1506 charnum "\\b\\)\\|" "\\(^[ \t]*0*"
1507 charnum "\\b\\)")
1486 nil t) 1508 nil t)
1487 (looking-at (concat "^[ \t0-9]*do[ \t]*0*" 1509 (looking-at
1488 charnum)))))))))) 1510 (concat "^[ \t0-9]*do[ \t]*0*"
1511 charnum))))))))))
1489 1512
1490(defun fortran-find-comment-start-skip () 1513(defun fortran-find-comment-start-skip ()
1491 "Move to past `comment-start-skip' found on current line. 1514 "Move to past `comment-start-skip' found on current line.
@@ -1493,10 +1516,11 @@ Return t if `comment-start-skip' found, nil if not."
1493 ;; In order to move point only if comment-start-skip is found, this 1516 ;; In order to move point only if comment-start-skip is found, this
1494 ;; one uses a lot of save-excursions. Note that re-search-forward 1517 ;; one uses a lot of save-excursions. Note that re-search-forward
1495 ;; moves point even if comment-start-skip is inside a string-constant. 1518 ;; moves point even if comment-start-skip is inside a string-constant.
1496 ;; Some code expects certain values for match-beginning and end 1519 ;; Some code expects certain values for match-beginning and end.
1497 (interactive) 1520 (interactive)
1498 (if (save-excursion 1521 (if (and comment-start-skip
1499 (re-search-forward comment-start-skip (line-end-position) t)) 1522 (save-excursion
1523 (re-search-forward comment-start-skip (line-end-position) t)))
1500 (let ((save-match-beginning (match-beginning 0)) 1524 (let ((save-match-beginning (match-beginning 0))
1501 (save-match-end (match-end 0))) 1525 (save-match-end (match-end 0)))
1502 (if (fortran-is-in-string-p (match-beginning 0)) 1526 (if (fortran-is-in-string-p (match-beginning 0))
@@ -1506,8 +1530,7 @@ Return t if `comment-start-skip' found, nil if not."
1506 (goto-char save-match-beginning) 1530 (goto-char save-match-beginning)
1507 (re-search-forward comment-start-skip (line-end-position) t) 1531 (re-search-forward comment-start-skip (line-end-position) t)
1508 (goto-char (match-end 0)) 1532 (goto-char (match-end 0))
1509 t)) 1533 t))))
1510 nil))
1511 1534
1512;;From: ralf@up3aud1.gwdg.de (Ralf Fassel) 1535;;From: ralf@up3aud1.gwdg.de (Ralf Fassel)
1513;; Test if TAB format continuation lines work. 1536;; Test if TAB format continuation lines work.
@@ -1579,16 +1602,12 @@ automatically breaks the line at a previous space."
1579 (if (if (null arg) 1602 (if (if (null arg)
1580 (not auto-fill-function) 1603 (not auto-fill-function)
1581 (> (prefix-numeric-value arg) 0)) 1604 (> (prefix-numeric-value arg) 0))
1582 #'fortran-do-auto-fill 1605 #'fortran-auto-fill
1583 nil)) 1606 nil))
1584 (force-mode-line-update))) 1607 (force-mode-line-update)))
1585 1608
1586(defun fortran-do-auto-fill ()
1587 (if (> (current-column) fill-column)
1588 (fortran-indent-line)))
1589
1590(defun fortran-fill () 1609(defun fortran-fill ()
1591 (let* ((auto-fill-function #'fortran-do-auto-fill) 1610 (let* ((auto-fill-function #'fortran-auto-fill)
1592 (opoint (point)) 1611 (opoint (point))
1593 (bol (line-beginning-position)) 1612 (bol (line-beginning-position))
1594 (eol (line-end-position)) 1613 (eol (line-end-position))
@@ -1639,7 +1658,8 @@ automatically breaks the line at a previous space."
1639 ;; Need to use fortran-find-comment-start-skip to make sure that quoted !'s 1658 ;; Need to use fortran-find-comment-start-skip to make sure that quoted !'s
1640 ;; don't prevent a break. 1659 ;; don't prevent a break.
1641 (if (not (or (save-excursion 1660 (if (not (or (save-excursion
1642 (if (and (re-search-backward comment-start-skip bol t) 1661 (if (and comment-start-skip
1662 (re-search-backward comment-start-skip bol t)
1643 (not (fortran-is-in-string-p (point)))) 1663 (not (fortran-is-in-string-p (point))))
1644 (progn 1664 (progn
1645 (skip-chars-backward " \t") 1665 (skip-chars-backward " \t")
@@ -1647,20 +1667,15 @@ automatically breaks the line at a previous space."
1647 (save-excursion 1667 (save-excursion
1648 (goto-char fill-point) 1668 (goto-char fill-point)
1649 (bolp)))) 1669 (bolp))))
1650 (if (> (save-excursion 1670 (when (> (save-excursion
1651 (goto-char fill-point) 1671 (goto-char opoint)
1652 (current-column)) 1672 (current-column))
1653 (1+ fill-column)) 1673 (min (1+ fill-column)
1654 (progn (goto-char fill-point) 1674 (+ (fortran-calculate-indent)
1655 (fortran-break-line)) 1675 fortran-continuation-indent)))
1656 (save-excursion 1676 (goto-char fill-point)
1657 (if (> (save-excursion 1677 (fortran-break-line)
1658 (goto-char fill-point) 1678 (end-of-line)))))
1659 (current-column))
1660 (+ (fortran-calculate-indent) fortran-continuation-indent))
1661 (progn
1662 (goto-char fill-point)
1663 (fortran-break-line))))))))
1664 1679
1665(defun fortran-break-line () 1680(defun fortran-break-line ()
1666 (let ((opoint (point)) 1681 (let ((opoint (point))
@@ -1675,7 +1690,7 @@ automatically breaks the line at a previous space."
1675 (delete-region (point) eol)))) 1690 (delete-region (point) eol))))
1676 ;; Forward line 1 really needs to go to next non white line 1691 ;; Forward line 1 really needs to go to next non white line
1677 (if (save-excursion (forward-line) 1692 (if (save-excursion (forward-line)
1678 (or (looking-at " [^ 0\n]\\|\t[1-9]"))) 1693 (or (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]")))
1679 (progn 1694 (progn
1680 (end-of-line) 1695 (end-of-line)
1681 (delete-region (point) (match-end 0)) 1696 (delete-region (point) (match-end 0))
@@ -1687,7 +1702,7 @@ automatically breaks the line at a previous space."
1687 (goto-char bol) 1702 (goto-char bol)
1688 (end-of-line) 1703 (end-of-line)
1689 (delete-horizontal-space) 1704 (delete-horizontal-space)
1690 (indent-to (fortran-comment-indent-function)) 1705 (indent-to (fortran-comment-indent))
1691 (insert comment-string))))) 1706 (insert comment-string)))))
1692 1707
1693(defun fortran-analyze-file-format () 1708(defun fortran-analyze-file-format ()
@@ -1701,13 +1716,13 @@ file before the end or the first `fortran-analyze-depth' lines."
1701 (while (not (or 1716 (while (not (or
1702 (eobp) 1717 (eobp)
1703 (eq (char-after) ?\t) 1718 (eq (char-after) ?\t)
1704 (looking-at " ") 1719 (looking-at " \\{6\\}")
1705 (> i fortran-analyze-depth))) 1720 (> i fortran-analyze-depth)))
1706 (forward-line) 1721 (forward-line)
1707 (setq i (1+ i))) 1722 (setq i (1+ i)))
1708 (cond 1723 (cond
1709 ((eq (char-after) ?\t) t) 1724 ((eq (char-after) ?\t) t)
1710 ((looking-at " ") nil) 1725 ((looking-at " \\{6\\}") nil)
1711 (fortran-tab-mode-default t) 1726 (fortran-tab-mode-default t)
1712 (t nil))))) 1727 (t nil)))))
1713 1728
@@ -1763,13 +1778,14 @@ Intended as the value of `fill-paragraph-function'."
1763(defun fortran-fill-statement () 1778(defun fortran-fill-statement ()
1764 "Fill a fortran statement up to `fill-column'." 1779 "Fill a fortran statement up to `fill-column'."
1765 (interactive) 1780 (interactive)
1766 (let ((auto-fill-function #'fortran-do-auto-fill)) 1781 (let ((auto-fill-function #'fortran-auto-fill))
1767 (if (not (save-excursion 1782 (if (not (save-excursion
1768 (beginning-of-line) 1783 (beginning-of-line)
1769 (or (looking-at "[ \t]*$") 1784 (or (looking-at "[ \t]*$")
1770 (looking-at fortran-comment-line-start-skip) 1785 (looking-at fortran-comment-line-start-skip)
1771 (and comment-start-skip 1786 (and comment-start-skip
1772 (looking-at (concat "[ \t]*" comment-start-skip)))))) 1787 (looking-at (concat "[ \t]*"
1788 comment-start-skip))))))
1773 (save-excursion 1789 (save-excursion
1774 ;; Find beginning of statement. 1790 ;; Find beginning of statement.
1775 (fortran-next-statement) 1791 (fortran-next-statement)
@@ -1805,8 +1821,9 @@ prefix arg DO-SPACE prevent stripping the whitespace."
1805 (let ((case-fold-search t)) ; case-insensitive 1821 (let ((case-fold-search t)) ; case-insensitive
1806 ;; search for fortran subprogram start 1822 ;; search for fortran subprogram start
1807 (if (re-search-forward 1823 (if (re-search-forward
1808 "^[ \t]*\\(program\\|subroutine\\|function\ 1824 (concat "^[ \t]*\\(program\\|subroutine\\|function"
1809\\|[ \ta-z0-9*()]*[ \t]+function\\|\\(block[ \t]*data\\)\\)" 1825 "\\|[ \ta-z0-9*()]*[ \t]+function\\|"
1826 "\\(block[ \t]*data\\)\\)")
1810 (save-excursion (fortran-end-of-subprogram) 1827 (save-excursion (fortran-end-of-subprogram)
1811 (point)) 1828 (point))
1812 t) 1829 t)