- (while (not (eobp))
- (end-of-line)
- (when (> (- width (current-column)) 0)
- (insert (make-string (- width (current-column)) ? )))
- (forward-line 1)))
- (list max (count-lines (point-min) (point-max)) (buffer-string)))))
+ ;; If the buffer is totally empty, then put a single blank
+ ;; line here.
+ (if (zerop (buffer-size))
+ (insert (make-string width ? ))
+ ;; Otherwise, fill the buffer.
+ (while (not (eobp))
+ (end-of-line)
+ (when (> (- width (current-column)) 0)
+ (insert (make-string (- width (current-column)) ? )))
+ (forward-line 1))))
+ (list max
+ (count-lines (point-min) (point-max))
+ (buffer-string)
+ (and fill
+ (shr-collect-overlays))))))
+
+(defun shr-collect-overlays ()
+ (save-excursion
+ (goto-char (point-min))
+ (let ((overlays nil))
+ (while (not (eobp))
+ (push (shr-overlays-in-region (point) (line-end-position))
+ overlays)
+ (forward-line 1))
+ (nreverse overlays))))
+
+(defun shr-overlays-in-region (start end)
+ (let (result)
+ (dolist (overlay (overlays-in start end))
+ (push (list (if (> start (overlay-start overlay))
+ (- end start)
+ (- end (overlay-start overlay)))
+ (if (< end (overlay-end overlay))
+ 0
+ (- end (overlay-end overlay)))
+ (overlay-properties overlay))
+ result))
+ (nreverse result)))