Function: f90-calculate-indent

f90-calculate-indent is an interactive and byte-compiled function defined in f90.el.gz.

Signature

(f90-calculate-indent)

Documentation

Calculate the indent column based on previous statements.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/f90.el.gz
(defun f90-calculate-indent ()
  "Calculate the indent column based on previous statements."
  (interactive)
  (let (icol cont (case-fold-search t) (pnt (point)))
    (save-excursion
      (if (not (f90-previous-statement))
          ;; If f90-previous-statement returns nil, we must have been
          ;; called from on or before the first line of the first statement.
          (setq icol (if (or (save-excursion
                               (goto-char pnt)
                               (beginning-of-line)
                               ;; Preprocessor line before code statement.
                               (looking-at "[ \t]*#"))
                             (progn
                               ;; f90-previous-statement has moved us over
                               ;; comment/blank lines, so we need to get
                               ;; back to the first code statement.
                               (when (looking-at "[ \t]*\\([!#]\\|$\\)")
                                 (f90-next-statement))
                               (skip-chars-forward " \t0-9")
                               (f90-looking-at-program-block-start)))
                         0
                       ;; No explicit PROGRAM start statement.
                       f90-program-indent))
        (setq cont (f90-present-statement-cont))
        (if (eq cont 'end)
            (while (not (eq 'begin (f90-present-statement-cont)))
              (f90-previous-statement)))
        (cond ((eq cont 'begin)
               (setq icol (+ (f90-current-indentation)
                             f90-continuation-indent)))
              ((eq cont 'middle) (setq icol (current-indentation)))
              (t (setq icol (f90-current-indentation))
                 (skip-chars-forward " \t")
                 (if (looking-at "[0-9]")
                     (setq icol (f90-get-correct-indent))
                   (cond ((or (f90-looking-at-if-then)
                              (f90-looking-at-where-or-forall)
                              (f90-looking-at-select-case)
                              (looking-at f90-else-like-re))
                          (setq icol (+ icol f90-if-indent)))
                         ((f90-looking-at-do)
                          (setq icol (+ icol f90-do-indent)))
                         ((f90-looking-at-type-like)
                          (setq icol (+ icol f90-type-indent)))
                         ((f90-looking-at-associate)
                          (setq icol (+ icol f90-associate-indent)))
                         ((f90-looking-at-critical)
                          (setq icol (+ icol f90-critical-indent)))
                         ((or (f90-looking-at-program-block-start)
                              (looking-at "contains[ \t]*\\($\\|!\\)"))
                          (setq icol (+ icol f90-program-indent)))))
                 (goto-char pnt)
                 (beginning-of-line)
                 (cond ((looking-at "[ \t]*$"))
                       ((looking-at "[ \t]*#") ; check for cpp directive
                        (setq icol 0))
                       (t
                        (skip-chars-forward " \t0-9")
                        (cond ((or (looking-at f90-else-like-re)
                                   (looking-at f90-end-if-re))
                               (setq icol (- icol f90-if-indent)))
                              ((looking-at "end[ \t]*do\\_>")
                               (setq icol (- icol f90-do-indent)))
                              ((looking-at f90-end-type-re)
                               (setq icol (- icol f90-type-indent)))
                              ((looking-at f90-end-associate-re)
                               (setq icol (- icol f90-associate-indent)))
                              ((f90-looking-at-end-critical)
                               (setq icol (- icol f90-critical-indent)))
                              ((or (looking-at "contains[ \t]*\\(!\\|$\\)")
                                   (f90-looking-at-program-block-end))
                               (setq icol (- icol f90-program-indent))))))))))
    icol))