Function: fortran-beginning-if

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

Signature

(fortran-beginning-if)

Documentation

Search backwards for first unmatched IF-THEN.

Return point or nil.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/fortran.el.gz
(defun fortran-beginning-if ()
  "Search backwards for first unmatched IF-THEN.
Return point or nil."
  (let ((case-fold-search t))
    (if (save-excursion
          ;; 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
                       (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)))))
        ;; Sitting on one.
        (match-beginning 0)
      ;; Search for one.
      (save-excursion
        (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)))))))