Function: fortran-beginning-of-subprogram
fortran-beginning-of-subprogram is an interactive and byte-compiled
function defined in fortran.el.gz.
Signature
(fortran-beginning-of-subprogram &optional ARG)
Documentation
Move point to the beginning of the current Fortran subprogram.
If ARG is negative, and point is between subprograms, the
"current" subprogram is the next one.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/fortran.el.gz
;; This is more complex than first expected because the beginning of a
;; main program may be implicit (ie not marked by a PROGRAM statement).
;; This would be fine (we could just go to bob in the absence of a match),
;; except it need not even be the first subprogram in the file (eg it
;; could follow a subroutine). Hence we have to search for END
;; statements instead.
;; cf fortran-beginning-of-block, f90-beginning-of-subprogram
;; Note that unlike the latter, we don't have to worry about nested
;; subprograms (?).
;; FIXME push-mark?
(defun fortran-beginning-of-subprogram (&optional arg)
"Move point to the beginning of the current Fortran subprogram.
If ARG is negative, and point is between subprograms, the
\"current\" subprogram is the next one."
(interactive)
(if (and arg
(< arg 0))
(progn
(fortran-end-of-subprogram)
(fortran-beginning-of-subprogram))
(let ((case-fold-search t))
;; If called already at the start of subprogram, go to the previous.
(beginning-of-line (if (bolp) 0 1))
(save-match-data
(or (looking-at fortran-start-prog-re)
;; This leaves us at bob if before the first subprogram.
(eq (fortran-previous-statement) 'first-statement)
(if (or (catch 'ok
(while (re-search-backward fortran-end-prog-re nil 'move)
(if (fortran-check-end-prog-re) (throw 'ok t))))
;; If the search failed, must be at bob.
;; First code line is the start of the subprogram.
;; FIXME use a more rigorous test, cf fortran-next-statement?
;; Though that needs to handle continuations too.
(not (looking-at "^\\([ \t]*[0-9]\\|[ \t]+[^!#]\\)")))
(fortran-next-statement)))))))