Function: TeX-fold-buffer-substring

TeX-fold-buffer-substring is a byte-compiled function defined in tex-fold.el.

Signature

(TeX-fold-buffer-substring START END)

Documentation

Return the contents of buffer from START to END as a string.

Like buffer-substring but copy overlay display strings as well.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/tex-fold.el
(defun TeX-fold-buffer-substring (start end)
  "Return the contents of buffer from START to END as a string.
Like `buffer-substring' but copy overlay display strings as well."
  ;; Swap values of `start' and `end' if necessary.
  (when (> start end) (let ((tmp start)) (setq start end end tmp)))
  (let ((overlays (overlays-in start end))
        result)
    ;; Get rid of overlays not under our control or not completely
    ;; inside the specified region.
    (dolist (ov overlays)
      (when (or (not (eq (overlay-get ov 'category) 'TeX-fold))
                (< (overlay-start ov) start)
                (> (overlay-end ov) end))
        (setq overlays (remove ov overlays))))
    (if (null overlays)
        (buffer-substring start end)
      ;; Sort list according to ascending starts.
      (setq overlays (sort (copy-sequence overlays)
                           (lambda (a b)
                             (< (overlay-start a) (overlay-start b)))))
      ;; Get the string from the start of the region up to the first overlay.
      (setq result (buffer-substring start (overlay-start (car overlays))))
      (let (ov)
        (while overlays
          (setq ov (car overlays)
                overlays (cdr overlays))
          ;; Add the display string of the overlay.
          (setq result (concat result (overlay-get ov 'display)))
          ;; Remove overlays contained in the current one.
          (dolist (elt overlays)
            (when (< (overlay-start elt) (overlay-end ov))
              (setq overlays (remove elt overlays))))
          ;; Add the string from the end of the current overlay up to
          ;; the next overlay or the end of the specified region.
          (setq result (concat result (buffer-substring (overlay-end ov)
                                                        (if overlays
                                                            (overlay-start
                                                             (car overlays))
                                                          end))))))
      result)))