Function: reftex-index-phrases-fixup-line

reftex-index-phrases-fixup-line is a byte-compiled function defined in reftex-index.el.gz.

Signature

(reftex-index-phrases-fixup-line BEG END)

Documentation

Insert newlines before BEG and/or after END to shorten line.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/reftex-index.el.gz
(defun reftex-index-phrases-fixup-line (beg end)
  "Insert newlines before BEG and/or after END to shorten line."
  (let (bol eol space1 space2)
    (save-excursion
      ;; Find line boundaries and possible line breaks near BEG and END
      (beginning-of-line)
      (setq bol (point))
      (end-of-line)
      (setq eol (point))
      (goto-char beg)
      (skip-chars-backward "^ \n")
      (if (and (equal (preceding-char) ?\ )
               (string-match "\\S-" (buffer-substring bol (point))))
          (setq space1 (1- (point))))
      (goto-char end)
      (skip-chars-forward "^ \n")
      (if (and (equal (following-char) ?\ )
               (string-match "\\S-" (buffer-substring (point) eol)))
          (setq space2 (point)))
      ;; Now check what we have and insert the newlines
      (if (<= (- eol bol) fill-column)
          ;; Line is already short
          nil
        (cond
         ((and (not space1) (not space2))) ; No spaces available
         ((not space2)                  ; Do space1
          (reftex-index-phrases-replace-space space1))
         ((not space1)                  ; Do space2
          (reftex-index-phrases-replace-space space2))
         (t ; We have both spaces
          (let ((l1 (- space1 bol))
                (l2 (- space2 space1))
                (l3 (- eol space2)))
            (if (> l2 fill-column)
                ;; The central part alone is more than one line
                (progn
                  (reftex-index-phrases-replace-space space1)
                  (reftex-index-phrases-replace-space space2))
              (if (> (+ l1 l2) fill-column)
                  ;; Need to split beginning
                  (reftex-index-phrases-replace-space space1))
              (if (> (+ l2 l3) fill-column)
                  ;; Need to split end
                  (reftex-index-phrases-replace-space space2))))))))))