Function: fortran-fill

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

Signature

(fortran-fill)

Documentation

Fill the current line at an appropriate point(s).

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/fortran.el.gz
(defun fortran-fill ()
  "Fill the current line at an appropriate point(s)."
  (let* ((auto-fill-function #'fortran-auto-fill)
         (opoint (point))
         (bol (line-beginning-position))
         (eol (line-end-position))
         (bos (min eol (+ bol (fortran-current-line-indentation))))
         ;; If in a string at fill-column, break it either before the
         ;; initial quote, or at fill-col (if string is too long).
         (quote
          (save-excursion
            (goto-char bol)
            ;; OK to break quotes on comment lines.
            (unless (looking-at fortran-comment-line-start-skip)
              (let (fcpoint start)
                (move-to-column fill-column)
                (when (fortran-is-in-string-p (setq fcpoint (point)))
                  (save-excursion
                    (re-search-backward "\\S\"\\s\"\\S\"?" bol t)
                    (setq start
                          (if fortran-break-before-delimiters
                              (point)
                            (1+ (point)))))
                  (if (re-search-forward "\\S\"\\s\"\\S\"" eol t)
                      (backward-char 2))
                  ;; If the current string is longer than (fill-column
                  ;; - 6) chars, break it at the fill column (else
                  ;; infinite loop).
                  (if (> (- (point) start)
                         (- fill-column 6 fortran-continuation-indent))
                      fcpoint
                    start))))))
         ;; Decide where to split the line. If a position for a quoted
         ;; string was found above then use that, else break the line
         ;; before/after the last delimiter.
         (fill-point
          (or quote
              (save-excursion
                ;; If f-b-b-d is t, have an extra column to play with,
                ;; since delimiter gets shifted to new line.
                (move-to-column (if fortran-break-before-delimiters
                                    (1+ fill-column)
                                  fill-column))
                (let ((repeat t))
                  (while repeat
                    (setq repeat nil)
                    ;; Adapted from f90-find-breakpoint.
                    (re-search-backward fortran-break-delimiters-re bol)
                    (if (not fortran-break-before-delimiters)
                        (if (looking-at fortran-no-break-re)
                            ;; Deal with cases such as "**" split over
                            ;; fill-col. Simpler alternative would be
                            ;; to start from (1- fill-column) above.
                            (if (> (+ 2 (current-column)) fill-column)
                                (setq repeat t)
                              (forward-char 2))
                          (forward-char 1))
                      (backward-char)
                      (or (looking-at fortran-no-break-re)
                          (forward-char)))))
                ;; Line indented beyond fill-column?
                (when (<= (point) bos)
                  (move-to-column (1+ fill-column))
                  ;; What is this doing???
                  (or (re-search-forward "[-\t\n,'+/*)=]" eol t)
                      (goto-char bol)))
                (if (bolp)
                    (re-search-forward "[ \t]" opoint t))
                (point)))))
    ;; If we are in an in-line comment, don't break unless the
    ;; line of code is longer than it should be. Otherwise
    ;; break the line at the column computed above.
    ;;
    ;; Need to use fortran-find-comment-start-skip to make sure that
    ;; quoted !'s don't prevent a break.
    (when (and (save-excursion
                 (beginning-of-line)
                 (if (not (fortran-find-comment-start-skip))
                     t
                   (goto-char (match-beginning 0))
                   (>= (point) fill-point)))
               (save-excursion
                 (goto-char fill-point)
                 (not (bolp)))
               (> (save-excursion
                    (goto-char opoint)
                    (current-column))
                  (min (1+ fill-column)
                       (+ (fortran-calculate-indent)
                          fortran-continuation-indent))))
      (goto-char fill-point)
      (fortran-break-line)
      (end-of-line))))