Function: f90-block-match

f90-block-match is a byte-compiled function defined in f90.el.gz.

Signature

(f90-block-match BEG-BLOCK BEG-NAME END-BLOCK END-NAME)

Documentation

Match end-struct with beg-struct and complete end-block if possible.

BEG-BLOCK is the type of block as indicated at the start (e.g., do). BEG-NAME is the block start name (may be nil). END-BLOCK is the type of block as indicated at the end (may be nil). END-NAME is the block end name (may be nil). If the block type matches f90-end-block-optional-name, do not add an end name if f90-smart-end-names is nil, but always update an incorrect end name if there already was one. Leave point at the end of line.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/f90.el.gz
(defun f90-block-match (beg-block beg-name end-block end-name)
  "Match end-struct with beg-struct and complete end-block if possible.
BEG-BLOCK is the type of block as indicated at the start (e.g., do).
BEG-NAME is the block start name (may be nil).
END-BLOCK is the type of block as indicated at the end (may be nil).
END-NAME is the block end name (may be nil).
If the block type matches `f90-end-block-optional-name', do not add
an end name if `f90-smart-end-names' is nil, but always update an
incorrect end name if there already was one.
Leave point at the end of line."
  ;; Hack to deal with the case when this is called from
  ;; f90-indent-region on a program block without an explicit PROGRAM
  ;; statement at the start. Should really be an error (?).
  (or beg-block (setq beg-block "program"))
  (search-forward "end" (line-end-position))
  (catch 'no-match
    (if (and end-block (f90-equal-symbols beg-block end-block))
        (search-forward end-block)
      (if end-block
          (progn
            (message "END %s does not match %s." end-block beg-block)
            (end-of-line)
            (throw 'no-match nil))
        (message "Inserting %s." beg-block)
        (insert (concat " " beg-block))))
    (if (f90-equal-symbols beg-name end-name)
        (and end-name (search-forward end-name))
      (cond ((and beg-name (not end-name))
             (unless (and (not f90-smart-end-names)
                          (member-ignore-case beg-block
                                              f90-end-block-optional-name))
               (message "Inserting %s." beg-name)
               (insert (concat " " beg-name))))
            ((and beg-name end-name)
             (message "Replacing %s with %s." end-name beg-name)
             (search-forward end-name)
             (replace-match beg-name))
            ((and (not beg-name) end-name)
             (message "Deleting %s." end-name)
             (search-forward end-name)
             (replace-match ""))))
    (or (looking-at "[ \t]*!") (delete-horizontal-space))))