Function: fortran-end-if

fortran-end-if is a byte-compiled function defined in fortran.el.gz.

Signature

(fortran-end-if)

Documentation

Search forwards for first unmatched ENDIF.

Return point or nil.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/fortran.el.gz
(defun fortran-end-if ()
  "Search forwards for first unmatched ENDIF.
Return point or nil."
  (let ((case-fold-search t))
    (if (save-excursion (beginning-of-line)
                        (skip-chars-forward " \t0-9")
                        (looking-at "end[ \t]*if\\b"))
        ;; Sitting on one.
        (match-beginning 0)
      ;; Search for one.  The point has been already been moved to first
      ;; letter on line but this should not cause troubles.
      (save-excursion
        (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)))))))