;;; fortran.el --- Fortran mode for GNU Emacs
;; Copyright (C) 1986, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
;;; fortran.el --- Fortran mode for GNU Emacs
;; Copyright (C) 1986, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-
-(defcustom fortran-tab-mode-string "/t"
- "*String to appear in mode line in TAB format buffers."
+(put 'fortran-tab-mode-default 'safe-local-variable 'booleanp)
+
+;; TODO add more detail of what tab mode is to doc string.
+(defcustom fortran-tab-mode-string
+ (propertize "/t" 'help-echo "This buffer is in Fortran TAB mode"
+ 'mouse-face 'mode-line-highlight
+ 'local-map
+ (make-mode-line-mouse-map 'mouse-1
+ (lambda ()
+ (interactive)
+ (describe-variable
+ 'fortran-tab-mode-string))))
+ "String to appear in mode line in TAB format buffers.
+See Info node `(emacs)ForIndent Cont'."
In fixed format continuation style, this character is inserted in
column 6 by \\[fortran-split-line] to begin a continuation line.
Also, if \\[fortran-indent-line] finds this at the beginning of a
line, it will convert the line into a continuation line of the
In fixed format continuation style, this character is inserted in
column 6 by \\[fortran-split-line] to begin a continuation line.
Also, if \\[fortran-indent-line] finds this at the beginning of a
line, it will convert the line into a continuation line of the
+(put 'fortran-break-before-delimiters 'safe-local-variable 'booleanp)
+
+;; TODO 0 as no-limit, as per g77.
+(defcustom fortran-line-length 72
+ "Maximum number of characters in a line of fixed-form Fortran code.
+Characters beyond this point are treated as comments. Setting
+this variable directly (after fortran mode is loaded) does not
+take effect. Use either \\[customize] (which affects all Fortran
+buffers and the default) or the function
+`fortran-line-length' (which can also operate on just the current
+buffer). This corresponds to the g77 compiler option
+`-ffixed-line-length-N'."
+ :type 'integer
+ :initialize 'custom-initialize-default
+ :set (lambda (symbol value)
+ ;; Do all fortran buffers, and the default.
+ (fortran-line-length value t))
+ :version "23.1"
+ :group 'fortran)
+
+(put 'fortran-line-length 'safe-local-variable 'integerp)
+(make-variable-buffer-local 'fortran-line-length)
-(defvar fortran-font-lock-syntactic-keywords
- '(("^[cd\\*]" 0 (11))
- ("^[^cd\\*\t\n].\\{71\\}\\([^\n]+\\)" 1 (11)))
- "`font-lock-syntactic-keywords' for Fortran.
-These get fixed-format comments fontified.")
+(defun fortran-font-lock-syntactic-keywords ()
+ "Return a value for `font-lock-syntactic-keywords' in Fortran mode.
+This varies according to the value of `fortran-line-length'.
+This is used to fontify fixed-format Fortran comments."
+ `(("^[cd\\*]" 0 (11))
+ (,(format "^[^cd\\*\t\n].\\{%d\\}\\([^\n]+\\)" (1- fortran-line-length))
+ 1 (11))))
-(defvar fortran-mode-abbrev-table
- (progn
- (define-abbrev-table 'fortran-mode-abbrev-table nil)
- fortran-mode-abbrev-table)
- "Abbrev table for Fortran mode.")
-
-(let (abbrevs-changed)
- ;; Use the 6th arg (SYSTEM-FLAG) of define-abbrev if possible.
- ;; Only use `apply' to quieten the byte-compiler.
- (mapcar
- (function (lambda (element)
- (condition-case nil
- (apply 'define-abbrev fortran-mode-abbrev-table
- (append element '(nil 0 t)))
- (wrong-number-of-arguments
- (apply 'define-abbrev fortran-mode-abbrev-table
- (append element '(nil 0)))))))
- '((";au" "automatic" )
- (";b" "byte" )
- (";bd" "block data" )
- (";ch" "character" )
- (";cl" "close" )
- (";c" "continue" )
- (";cm" "common" )
- (";cx" "complex" )
- (";df" "define" )
- (";di" "dimension" )
- (";do" "double" )
- (";dc" "double complex" )
- (";dp" "double precision" )
- (";dw" "do while" )
- (";e" "else" )
- (";ed" "enddo" )
- (";el" "elseif" )
- (";en" "endif" )
- (";eq" "equivalence" )
- (";ew" "endwhere" )
- (";ex" "external" )
- (";ey" "entry" )
- (";f" "format" )
- (";fa" ".false." )
- (";fu" "function" )
- (";g" "goto" )
- (";im" "implicit" )
- (";ib" "implicit byte" )
- (";ic" "implicit complex" )
- (";ich" "implicit character")
- (";ii" "implicit integer" )
- (";il" "implicit logical" )
- (";ir" "implicit real" )
- (";inc" "include" )
- (";in" "integer" )
- (";intr" "intrinsic" )
- (";l" "logical" )
- (";n" "namelist" )
- (";o" "open" ) ; was ;op
- (";pa" "parameter" )
- (";pr" "program" )
- (";ps" "pause" )
- (";p" "print" )
- (";rc" "record" )
- (";re" "real" )
- (";r" "read" )
- (";rt" "return" )
- (";rw" "rewind" )
- (";s" "stop" )
- (";sa" "save" )
- (";st" "structure" )
- (";sc" "static" )
- (";su" "subroutine" )
- (";tr" ".true." )
- (";ty" "type" )
- (";vo" "volatile" )
- (";w" "write" )
- (";wh" "where" ))))
+(define-abbrev-table 'fortran-mode-abbrev-table
+ (mapcar (lambda (e) (list (car e) (cdr e) nil :system t))
+ '((";au" . "automatic" )
+ (";b" . "byte" )
+ (";bd" . "block data" )
+ (";ch" . "character" )
+ (";cl" . "close" )
+ (";c" . "continue" )
+ (";cm" . "common" )
+ (";cx" . "complex" )
+ (";df" . "define" )
+ (";di" . "dimension" )
+ (";do" . "double" )
+ (";dc" . "double complex" )
+ (";dp" . "double precision" )
+ (";dw" . "do while" )
+ (";e" . "else" )
+ (";ed" . "enddo" )
+ (";el" . "elseif" )
+ (";en" . "endif" )
+ (";eq" . "equivalence" )
+ (";ew" . "endwhere" )
+ (";ex" . "external" )
+ (";ey" . "entry" )
+ (";f" . "format" )
+ (";fa" . ".false." )
+ (";fu" . "function" )
+ (";g" . "goto" )
+ (";im" . "implicit" )
+ (";ib" . "implicit byte" )
+ (";ic" . "implicit complex" )
+ (";ich" . "implicit character")
+ (";ii" . "implicit integer" )
+ (";il" . "implicit logical" )
+ (";ir" . "implicit real" )
+ (";inc" . "include" )
+ (";in" . "integer" )
+ (";intr" . "intrinsic" )
+ (";l" . "logical" )
+ (";n" . "namelist" )
+ (";o" . "open" ) ; was ;op
+ (";pa" . "parameter" )
+ (";pr" . "program" )
+ (";ps" . "pause" )
+ (";p" . "print" )
+ (";rc" . "record" )
+ (";re" . "real" )
+ (";r" . "read" )
+ (";rt" . "return" )
+ (";rw" . "rewind" )
+ (";s" . "stop" )
+ (";sa" . "save" )
+ (";st" . "structure" )
+ (";sc" . "static" )
+ (";su" . "subroutine" )
+ (";tr" . ".true." )
+ (";ty" . "type" )
+ (";vo" . "volatile" )
+ (";w" . "write" )
+ (";wh" . "where" )))
+ "Abbrev table for Fortran mode."
+ ;; Accept ; as the first char of an abbrev. Also allow _ in abbrevs.
+ :regexp "\\(?:[^[:word:]_;]\\|^\\)\\(;?[[:word:]_]+\\)[^[:word:]_]*")
+(defun fortran-line-length (nchars &optional global)
+ "Set the length of fixed-form Fortran lines to NCHARS.
+This normally only affects the current buffer, which must be in
+Fortran mode. If the optional argument GLOBAL is non-nil, it
+affects all Fortran buffers, and also the default."
+ (interactive "p")
+ (let (new)
+ (mapc (lambda (buff)
+ (with-current-buffer buff
+ (when (eq major-mode 'fortran-mode)
+ (setq fortran-line-length nchars
+ fill-column fortran-line-length
+ new (fortran-font-lock-syntactic-keywords))
+ ;; Refontify only if necessary.
+ (unless (equal new font-lock-syntactic-keywords)
+ (setq font-lock-syntactic-keywords
+ (fortran-font-lock-syntactic-keywords))
+ (if font-lock-mode (font-lock-mode 1))))))
+ (if global
+ (buffer-list)
+ (list (current-buffer))))
+ (if global
+ (setq-default fortran-line-length nchars))))
+
+(defun fortran-hack-local-variables ()
+ "Fortran mode adds this to `hack-local-variables-hook'."
+ (fortran-line-length fortran-line-length))
+
+(declare-function gud-find-c-expr "gud.el" nil)
+
- ;; No existing comment.
- ;; If side-by-side comments are defined, insert one,
- ;; unless line is now blank.
- ((and comment-start (not (looking-at "[ \t]*$"))
- (string-match comment-start-skip (concat " " comment-start)))
- (end-of-line)
- (delete-horizontal-space)
- (indent-to (fortran-comment-indent))
- (insert comment-start))
- ;; Else insert separate-line comment, making a new line if nec.
- (t
- (if (looking-at "^[ \t]*$")
- (delete-horizontal-space)
- (beginning-of-line)
- (insert ?\n)
- (forward-char -1))
- (insert fortran-comment-line-start)
- (insert-char (if (stringp fortran-comment-indent-char)
- (aref fortran-comment-indent-char 0)
- fortran-comment-indent-char)
- (- (fortran-calculate-indent) (current-column))))))
+ ;; No existing comment.
+ ;; If side-by-side comments are defined, insert one,
+ ;; unless line is now blank.
+ ((and comment-start (not (looking-at "[ \t]*$"))
+ (string-match comment-start-skip (concat " " comment-start)))
+ (end-of-line)
+ (delete-horizontal-space)
+ (indent-to (fortran-comment-indent))
+ (insert comment-start))
+ ;; Else insert separate-line comment, making a new line if nec.
+ (t
+ (if (looking-at "^[ \t]*$")
+ (delete-horizontal-space)
+ (beginning-of-line)
+ (insert ?\n)
+ (forward-char -1))
+ (insert fortran-comment-line-start)
+ (insert-char (if (stringp fortran-comment-indent-char)
+ (aref fortran-comment-indent-char 0)
+ fortran-comment-indent-char)
+ (- (fortran-calculate-indent) (current-column))))))
- (progn
- (condition-case nil
- (fortran-window-create)
- (error (error "No room for Fortran window")))
- (message "Type SPC to continue editing.")
- (let ((char (read-event)))
- (or (equal char ?\s)
- (setq unread-command-events (list char))))))
+ (progn
+ (condition-case nil
+ (fortran-window-create)
+ (error (error "No room for Fortran window")))
+ (message "Type SPC to continue editing.")
+ (let ((char (read-event)))
+ (or (equal char ?\s)
+ (setq unread-command-events (list char))))))
- (eq ?\t (char-after (line-beginning-position)))
- (not (or (eq last-command 'fortran-indent-line)
- (eq last-command
- 'fortran-indent-new-line))))
- (save-excursion
- (re-search-backward "[^ \t0-9]"
- (line-beginning-position)
- t)) ; not a line number
- (looking-at "[0-9]")) ; within a line number
- (self-insert-command (prefix-numeric-value arg))
+ (eq ?\t (char-after (line-beginning-position)))
+ (not (or (eq last-command 'fortran-indent-line)
+ (eq last-command
+ 'fortran-indent-new-line))))
+ (save-excursion
+ (re-search-backward "[^ \t0-9]"
+ (line-beginning-position)
+ t)) ; not a line number
+ (looking-at "[0-9]")) ; within a line number
+ (self-insert-command (prefix-numeric-value arg))
- (if (save-excursion ; on END
- (beginning-of-line)
- (and (looking-at fortran-end-prog-re)
- (fortran-check-end-prog-re)))
- (forward-line)
- (beginning-of-line 2)
- (catch 'ok
- (while (re-search-forward fortran-end-prog-re nil 'move)
- (if (fortran-check-end-prog-re)
- (throw 'ok t))))
- (goto-char (match-beginning 0))
- (forward-line)))))
+ (if (save-excursion ; on END
+ (beginning-of-line)
+ (and (looking-at fortran-end-prog-re)
+ (fortran-check-end-prog-re)))
+ (forward-line)
+ (beginning-of-line 2)
+ (when (catch 'ok
+ (while (re-search-forward fortran-end-prog-re nil 'move)
+ (if (fortran-check-end-prog-re)
+ (throw 'ok t))))
+ (goto-char (match-beginning 0))
+ (forward-line))))))
- (let ((count 1))
- (while (and (not (zerop count))
- (not (eq (fortran-next-statement) 'last-statement))
- ;; Keep local to subprogram.
- (not (and (looking-at fortran-end-prog-re)
- (fortran-check-end-prog-re))))
- (skip-chars-forward " \t0-9")
- (cond ((looking-at "end[ \t]*do\\b")
- (setq count (1- count)))
- ((looking-at
- "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?do[ \t]+[^0-9]")
- (setq count (1+ count)))))
- (and (zerop count)
- ;; All pairs accounted for.
- (point)))))))
+ (let ((count 1))
+ (while (and (not (zerop count))
+ (not (eq (fortran-next-statement) 'last-statement))
+ ;; Keep local to subprogram.
+ (not (and (looking-at fortran-end-prog-re)
+ (fortran-check-end-prog-re))))
+ (skip-chars-forward " \t0-9")
+ (cond ((looking-at "end[ \t]*do\\b")
+ (setq count (1- count)))
+ ((looking-at
+ "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?do[ \t]+[^0-9]")
+ (setq count (1+ count)))))
+ (and (zerop count)
+ ;; All pairs accounted for.
+ (point)))))))
- (let ((count 1))
- (while (and (not (zerop count))
- (not (eq (fortran-previous-statement) 'first-statement))
- ;; Keep local to subprogram.
- (not (and (looking-at fortran-end-prog-re)
- (fortran-check-end-prog-re))))
- (skip-chars-forward " \t0-9")
- (cond ((looking-at dostart-re)
- (setq count (1- count)))
+ (let ((count 1))
+ (while (and (not (zerop count))
+ (not (eq (fortran-previous-statement) 'first-statement))
+ ;; Keep local to subprogram.
+ (not (and (looking-at fortran-end-prog-re)
+ (fortran-check-end-prog-re))))
+ (skip-chars-forward " \t0-9")
+ (cond ((looking-at dostart-re)
+ (setq count (1- count)))
- (let ((count 1))
- (while (and (not (zerop count))
- (not (eq (fortran-next-statement) 'last-statement))
- ;; Keep local to subprogram.
- (not (and (looking-at fortran-end-prog-re)
- (fortran-check-end-prog-re))))
- (skip-chars-forward " \t0-9")
- (cond ((looking-at "end[ \t]*if\\b")
- (setq count (1- count)))
- ((looking-at fortran-if-start-re)
- (save-excursion
- (if (or
- (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
- (let (then-test) ; multi-line if-then
- (while
- (and
- (zerop (forward-line 1))
- ;; Search forward for then.
- (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]")
- (not
- (setq then-test
- (looking-at
- ".*then\\b[ \t]*[^ \t(=a-z0-9]")))))
- then-test))
- (setq count (1+ count)))))))
- (and (zerop count)
- ;; All pairs accounted for.
- (point)))))))
+ (let ((count 1))
+ (while (and (not (zerop count))
+ (not (eq (fortran-next-statement) 'last-statement))
+ ;; Keep local to subprogram.
+ (not (and (looking-at fortran-end-prog-re)
+ (fortran-check-end-prog-re))))
+ (skip-chars-forward " \t0-9")
+ (cond ((looking-at "end[ \t]*if\\b")
+ (setq count (1- count)))
+ ((looking-at fortran-if-start-re)
+ (save-excursion
+ (if (or
+ (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
+ (let (then-test) ; multi-line if-then
+ (while
+ (and
+ (zerop (forward-line 1))
+ ;; Search forward for then.
+ (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]")
+ (not
+ (setq then-test
+ (looking-at
+ ".*then\\b[ \t]*[^ \t(=a-z0-9]")))))
+ then-test))
+ (setq count (1+ count)))))))
+ (and (zerop count)
+ ;; All pairs accounted for.
+ (point)))))))
- ;; May be sitting on multi-line if-then statement, first
- ;; move to beginning of current statement. Note:
- ;; `fortran-previous-statement' moves to previous statement
- ;; *unless* current statement is first one. Only move
- ;; forward if not first-statement.
- (if (not (eq (fortran-previous-statement) 'first-statement))
- (fortran-next-statement))
- (skip-chars-forward " \t0-9")
- (and
- (looking-at fortran-if-start-re)
- (save-match-data
- (or (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
- ;; Multi-line if-then.
- (let (then-test)
- (while
+ ;; May be sitting on multi-line if-then statement, first
+ ;; move to beginning of current statement. Note:
+ ;; `fortran-previous-statement' moves to previous statement
+ ;; *unless* current statement is first one. Only move
+ ;; forward if not first-statement.
+ (if (not (eq (fortran-previous-statement) 'first-statement))
+ (fortran-next-statement))
+ (skip-chars-forward " \t0-9")
+ (and
+ (looking-at fortran-if-start-re)
+ (save-match-data
+ (or (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
+ ;; Multi-line if-then.
+ (let (then-test)
+ (while
- (let ((count 1))
- (while (and (not (zerop count))
- (not (eq (fortran-previous-statement) 'first-statement))
- ;; Keep local to subprogram.
- (not (and (looking-at fortran-end-prog-re)
- (fortran-check-end-prog-re))))
- (skip-chars-forward " \t0-9")
- (cond ((looking-at fortran-if-start-re)
- (save-excursion
- (if (or
- (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
- (let (then-test) ; multi-line if-then
- (while
- (and
- (zerop (forward-line 1))
- ;; Search forward for then.
- (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]")
- (not
- (setq then-test
- (looking-at
- (concat ".*then\\b[ \t]*"
- "[^ \t(=a-z0-9]"))))))
- then-test))
- (setq count (1- count)))))
- ((looking-at "end[ \t]*if\\b")
- (setq count (1+ count)))))
- (and (zerop count)
- ;; All pairs accounted for.
- (point)))))))
+ (let ((count 1))
+ (while (and (not (zerop count))
+ (not (eq (fortran-previous-statement) 'first-statement))
+ ;; Keep local to subprogram.
+ (not (and (looking-at fortran-end-prog-re)
+ (fortran-check-end-prog-re))))
+ (skip-chars-forward " \t0-9")
+ (cond ((looking-at fortran-if-start-re)
+ (save-excursion
+ (if (or
+ (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t(=a-z0-9]")
+ (let (then-test) ; multi-line if-then
+ (while
+ (and
+ (zerop (forward-line 1))
+ ;; Search forward for then.
+ (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]")
+ (not
+ (setq then-test
+ (looking-at
+ (concat ".*then\\b[ \t]*"
+ "[^ \t(=a-z0-9]"))))))
+ then-test))
+ (setq count (1- count)))))
+ ((looking-at "end[ \t]*if\\b")
+ (setq count (1+ count)))))
+ (and (zerop count)
+ ;; All pairs accounted for.
+ (point)))))))
- (and (re-search-forward "^[ \t]*[0-9]+" (+ (point) 4) t)
- (not (fortran-line-number-indented-correctly-p))))
- (fortran-indent-to-column cfi)
- (beginning-of-line)
- (if (fortran-find-comment-start-skip)
- (fortran-indent-comment))))
+ (and (re-search-forward "^[ \t]*[0-9]+" (+ (point) 4) t)
+ (not (fortran-line-number-indented-correctly-p))))
+ (fortran-indent-to-column cfi)
+ (beginning-of-line)
+ (if (fortran-find-comment-start-skip)
+ (fortran-indent-comment))))
- (save-excursion
- (beginning-of-line)
- (if (or (not (= cfi (fortran-current-line-indentation)))
- (and (re-search-forward "^[ \t]*[0-9]+"
- (+ (point) 4) t)
- (not (fortran-line-number-indented-correctly-p))))
- (fortran-indent-to-column cfi)
- (beginning-of-line)
- (if (fortran-find-comment-start-skip)
- (fortran-indent-comment))))
- (fortran-fill)
- ;; Never leave point in left margin.
- (if (< (current-column) cfi)
- (move-to-column cfi)))))
+ (save-excursion
+ (beginning-of-line)
+ (if (or (not (= cfi (fortran-current-line-indentation)))
+ (and (re-search-forward "^[ \t]*[0-9]+"
+ (+ (point) 4) t)
+ (not (fortran-line-number-indented-correctly-p))))
+ (fortran-indent-to-column cfi)
+ (beginning-of-line)
+ (if (fortran-find-comment-start-skip)
+ (fortran-indent-comment))))
+ (fortran-fill)
+ ;; Never leave point in left margin.
+ (if (< (current-column) cfi)
+ (move-to-column cfi)))))
(if (= (point) (point-min))
(setq icol fortran-minimum-statement-indent)
(setq icol (fortran-current-line-indentation)))
(skip-chars-forward " \t0-9")
(cond ((looking-at "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?if[ \t]*(")
(if (or (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t_$(=a-z0-9]")
(if (= (point) (point-min))
(setq icol fortran-minimum-statement-indent)
(setq icol (fortran-current-line-indentation)))
(skip-chars-forward " \t0-9")
(cond ((looking-at "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?if[ \t]*(")
(if (or (looking-at ".*)[ \t]*then\\b[ \t]*[^ \t_$(=a-z0-9]")
- (setq icol fortran-minimum-statement-indent)))))
+ (setq icol fortran-minimum-statement-indent))
+ ;; Previous statement was a numbered DO loop without a
+ ;; closing CONTINUE or END DO, so we indented the
+ ;; terminator like the loop body.
+ ((and fortran-check-all-num-for-matching-do
+ (not (looking-at "\\(continue\\|end[ \t]*do\\)\\>"))
+ (progn
+ (beginning-of-line)
+ (and (looking-at "[ \t]*[0-9]+")
+ (fortran-check-for-matching-do))))
+ (setq icol (- icol fortran-do-indent))))))
- ((looking-at fortran-directive-re)
- (setq fortran-minimum-statement-indent 0 icol 0))
- ((looking-at fortran-comment-line-start-skip)
- (cond ((eq fortran-comment-indent-style 'relative)
- (setq icol (+ icol fortran-comment-line-extra-indent)))
- ((eq fortran-comment-indent-style 'fixed)
- (setq icol (+ fortran-minimum-statement-indent
- fortran-comment-line-extra-indent))))
- (setq fortran-minimum-statement-indent 0))
- ((or (looking-at (concat "[ \t]*"
- (regexp-quote
- fortran-continuation-string)))
- (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]"))
+ ((looking-at fortran-directive-re)
+ (setq fortran-minimum-statement-indent 0 icol 0))
+ ((looking-at fortran-comment-line-start-skip)
+ (cond ((eq fortran-comment-indent-style 'relative)
+ (setq icol (+ icol fortran-comment-line-extra-indent)))
+ ((eq fortran-comment-indent-style 'fixed)
+ (setq icol (+ fortran-minimum-statement-indent
+ fortran-comment-line-extra-indent))))
+ (setq fortran-minimum-statement-indent 0))
+ ((or (looking-at (concat "[ \t]*"
+ (regexp-quote
+ fortran-continuation-string)))
+ (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]"))
- (first-statement)
- ((and fortran-check-all-num-for-matching-do
- (looking-at "[ \t]*[0-9]+")
- (fortran-check-for-matching-do))
- (setq icol (- icol fortran-do-indent)))
- (t
- (skip-chars-forward " \t0-9")
- (cond ((looking-at "end[ \t]*\\(if\\|select\\|where\\)\\b")
- (setq icol (- icol fortran-if-indent)))
- ((looking-at "else\\(if\\)?\\b")
- (setq icol (- icol fortran-if-indent)))
+ (first-statement)
+ ;; The terminating statement is actually part of the
+ ;; loop body, so unless it is a CONTINUE or END DO, we
+ ;; indent it like the loop body (see above).
+ ((and fortran-check-all-num-for-matching-do
+ (looking-at "[ \t]*[0-9]+[ \t]*\
+\\(continue\\|end[ \t]*do\\)\\>")
+ (fortran-check-for-matching-do))
+ (setq icol (- icol fortran-do-indent)))
+ (t
+ (skip-chars-forward " \t0-9")
+ (cond ((looking-at "end[ \t]*\\(if\\|select\\|where\\)\\b")
+ (setq icol (- icol fortran-if-indent)))
+ ((looking-at "else\\(if\\)?\\b")
+ (setq icol (- icol fortran-if-indent)))
- (setq icol (- icol fortran-if-indent)))
- ((looking-at "\\(otherwise\\|else[ \t]*where\\)\\b")
- (setq icol (- icol fortran-if-indent)))
- ((and (looking-at "continue\\b")
- (fortran-check-for-matching-do))
- (setq icol (- icol fortran-do-indent)))
- ((looking-at "end[ \t]*do\\b")
- (setq icol (- icol fortran-do-indent)))
- ((looking-at "end[ \t]*\
+ (setq icol (- icol fortran-if-indent)))
+ ((looking-at "\\(otherwise\\|else[ \t]*where\\)\\b")
+ (setq icol (- icol fortran-if-indent)))
+ ((and (looking-at "continue\\b")
+ (fortran-check-for-matching-do))
+ (setq icol (- icol fortran-do-indent)))
+ ((looking-at "end[ \t]*do\\b")
+ (setq icol (- icol fortran-do-indent)))
+ ((looking-at "end[ \t]*\
- (setq icol (- icol fortran-structure-indent)))
- ((and (looking-at fortran-end-prog-re1)
- (fortran-check-end-prog-re)
- (not (= icol fortran-minimum-statement-indent)))
- (message "Warning: `end' not in column %d. Probably\
+ (setq icol (- icol fortran-structure-indent)))
+ ((and (looking-at fortran-end-prog-re1)
+ (fortran-check-end-prog-re)
+ (not (= icol fortran-minimum-statement-indent)))
+ (message "Warning: `end' not in column %d. Probably\
- (goto-char (match-end 0))
- (skip-chars-forward
- (if (stringp fortran-comment-indent-char)
- fortran-comment-indent-char
- (char-to-string fortran-comment-indent-char))))
- ((or (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]"))
- (goto-char (match-end 0)))
- (t
- ;; Move past line number.
- (skip-chars-forward "[ \t0-9]")))
+ (goto-char (match-end 0))
+ (skip-chars-forward
+ (if (stringp fortran-comment-indent-char)
+ fortran-comment-indent-char
+ (char-to-string fortran-comment-indent-char))))
+ ((or (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]"))
+ (goto-char (match-end 0)))
+ (t
+ ;; Move past line number.
+ (skip-chars-forward "[ \t0-9]")))
- (if fortran-comment-indent-style
- (let* ((char (if (stringp fortran-comment-indent-char)
- (aref fortran-comment-indent-char 0)
- fortran-comment-indent-char))
- (chars (string ?\s ?\t char)))
- (goto-char (match-end 0))
- (skip-chars-backward chars)
- (delete-region (point) (progn (skip-chars-forward chars)
- (point)))
- (insert-char char (- col (current-column)))))
+ (if fortran-comment-indent-style
+ (let* ((char (if (stringp fortran-comment-indent-char)
+ (aref fortran-comment-indent-char 0)
+ fortran-comment-indent-char))
+ (chars (string ?\s ?\t char)))
+ (goto-char (match-end 0))
+ (skip-chars-backward chars)
+ (delete-region (point) (progn (skip-chars-forward chars)
+ (point)))
+ (insert-char char (- col (current-column)))))
- (if indent-tabs-mode
- (goto-char (match-end 0))
- (delete-char 2)
- (insert-char ?\s 5)
- (insert fortran-continuation-string))
- (if (looking-at " \\{5\\}[^ 0\n]")
- (if indent-tabs-mode
- (progn (delete-char 6)
- (insert ?\t (fortran-numerical-continuation-char) 1))
- (forward-char 6))
- (delete-horizontal-space)
- ;; Put line number in columns 0-4, or
+ (if indent-tabs-mode
+ (goto-char (match-end 0))
+ (delete-char 2)
+ (insert-char ?\s 5)
+ (insert fortran-continuation-string))
+ (if (looking-at " \\{5\\}[^ 0\n]")
+ (if indent-tabs-mode
+ (progn (delete-char 6)
+ (insert ?\t (fortran-numerical-continuation-char) 1))
+ (forward-char 6))
+ (delete-horizontal-space)
+ ;; Put line number in columns 0-4, or
- (cond ((eobp))
- ((looking-at (regexp-quote fortran-continuation-string))
- (if indent-tabs-mode
- (progn
- (indent-to
- (if indent-tabs-mode
- fortran-minimum-statement-indent-tab
- fortran-minimum-statement-indent-fixed))
- (delete-char 1)
- (insert-char (fortran-numerical-continuation-char) 1))
- (indent-to 5)
- (forward-char 1)))
- ((looking-at "[0-9]+")
- (let ((extra-space (- 5 (- (match-end 0) (point)))))
- (if (< extra-space 0)
- (message "Warning: line number exceeds 5-digit limit.")
- (indent-to (min fortran-line-number-indent extra-space))))
- (skip-chars-forward "0-9")))))
+ (cond ((eobp))
+ ((looking-at (regexp-quote fortran-continuation-string))
+ (if indent-tabs-mode
+ (progn
+ (indent-to
+ (if indent-tabs-mode
+ fortran-minimum-statement-indent-tab
+ fortran-minimum-statement-indent-fixed))
+ (delete-char 1)
+ (insert-char (fortran-numerical-continuation-char) 1))
+ (indent-to 5)
+ (forward-char 1)))
+ ((looking-at "[0-9]+")
+ (let ((extra-space (- 5 (- (match-end 0) (point)))))
+ (if (< extra-space 0)
+ (message "Warning: line number exceeds 5-digit limit.")
+ (indent-to (min fortran-line-number-indent extra-space))))
+ (skip-chars-forward "0-9")))))
- (quoted-comment-start (if comment-start
- (regexp-quote comment-start)))
- (not-done t)
- parse-limit end-of-line)
- ;; Move to start of current statement.
- (fortran-next-statement)
- (fortran-previous-statement)
- ;; Now parse up to WHERE.
- (while not-done
- (if (or ;; Skip to next line if:
- ;; - comment line?
- (looking-at fortran-comment-line-start-skip)
- ;; - at end of line?
- (eolp)
- ;; - not in a string and after comment-start?
- (and (not (nth 3 parse-state))
- comment-start
- (equal comment-start
- (char-to-string (preceding-char)))))
- (if (> (forward-line) 0)
- (setq not-done nil))
- ;; else:
- ;; If we are at beginning of code line, skip any
- ;; whitespace, labels and tab continuation markers.
- (if (bolp) (skip-chars-forward " \t0-9"))
- ;; If we are in column <= 5 now, check for continuation char.
- (cond ((= 5 (current-column)) (forward-char 1))
- ((and (< (current-column) 5)
- (equal fortran-continuation-string
- (char-to-string (following-char)))
- (forward-char 1))))
- ;; Find out parse-limit from here.
- (setq end-of-line (line-end-position))
- (setq parse-limit (min where end-of-line))
- ;; Parse max up to comment-start, if non-nil and in current line.
- (if comment-start
- (save-excursion
- (if (re-search-forward quoted-comment-start end-of-line t)
- (setq parse-limit (min (point) parse-limit)))))
- ;; Now parse if still in limits.
- (if (< (point) where)
- (setq parse-state (parse-partial-sexp
- (point) parse-limit nil nil parse-state))
- (setq not-done nil))))
- ;; Result.
- (nth 3 parse-state))))))
+ (quoted-comment-start (if comment-start
+ (regexp-quote comment-start)))
+ (not-done t)
+ parse-limit end-of-line)
+ ;; Move to start of current statement.
+ (fortran-next-statement)
+ (fortran-previous-statement)
+ ;; Now parse up to WHERE.
+ (while not-done
+ (if (or ;; Skip to next line if:
+ ;; - comment line?
+ (looking-at fortran-comment-line-start-skip)
+ ;; - at end of line?
+ (eolp)
+ ;; - not in a string and after comment-start?
+ (and (not (nth 3 parse-state))
+ comment-start
+ (equal comment-start
+ (char-to-string (preceding-char)))))
+ (if (> (forward-line) 0)
+ (setq not-done nil))
+ ;; else:
+ ;; If we are at beginning of code line, skip any
+ ;; whitespace, labels and tab continuation markers.
+ (if (bolp) (skip-chars-forward " \t0-9"))
+ ;; If we are in column <= 5 now, check for continuation char.
+ (cond ((= 5 (current-column)) (forward-char 1))
+ ((and (< (current-column) 5)
+ (equal fortran-continuation-string
+ (char-to-string (following-char)))
+ (forward-char 1))))
+ ;; Find out parse-limit from here.
+ (setq end-of-line (line-end-position))
+ (setq parse-limit (min where end-of-line))
+ ;; Parse max up to comment-start, if non-nil and in current line.
+ (if comment-start
+ (save-excursion
+ (if (re-search-forward quoted-comment-start end-of-line t)
+ (setq parse-limit (min (point) parse-limit)))))
+ ;; Now parse if still in limits.
+ (if (< (point) where)
+ (setq parse-state (parse-partial-sexp
+ (point) parse-limit nil nil parse-state))
+ (setq not-done nil))))
+ ;; Result.
+ (nth 3 parse-state))))))