Function: outline-reveal-toggle-invisible

outline-reveal-toggle-invisible is a byte-compiled function defined in outline.el.gz.

Signature

(outline-reveal-toggle-invisible O HIDEP)

Source Code

;; Defined in /usr/src/emacs/lisp/outline.el.gz
(defun outline-reveal-toggle-invisible (o hidep)
  (save-excursion
    (goto-char (overlay-start o))
    (if hidep
        ;; When hiding the area again, we could just clean it up and let
        ;; reveal do the rest, by simply doing:
        ;; (remove-overlays (overlay-start o) (overlay-end o)
        ;;                  'invisible 'outline)
        ;;
        ;; That works fine as long as everything is in sync, but if the
        ;; structure of the document is changed while revealing parts of it,
        ;; the resulting behavior can be ugly.  I.e. we need to make
        ;; sure that we hide exactly a subtree.
        (progn
          (let ((end (overlay-end o)))
            (delete-overlay o)
            (while (progn
                     (outline-hide-subtree)
                     (outline-next-visible-heading 1)
                     (and (not (eobp)) (< (point) end))))))

      ;; When revealing, we just need to reveal sublevels.  If point is
      ;; inside one of the sublevels, reveal will call us again.
      ;; But we need to preserve the original overlay.
      (let ((o1 (copy-overlay o)))
        (overlay-put o 'invisible nil)  ;Show (most of) the text.
        (while (progn
                 (outline-show-entry)
                 (outline-show-children)
                 ;; Normally just the above is needed.
                 ;; But in odd cases, the above might fail to show anything.
                 ;; To avoid an infinite loop, we have to make sure that
                 ;; *something* gets shown.
                 (and (equal (overlay-start o) (overlay-start o1))
                      (< (point) (overlay-end o))
                      (= 0 (forward-line 1)))))
        ;; If still nothing was shown, just kill the damn thing.
        (when (equal (overlay-start o) (overlay-start o1))
          ;; I've seen it happen at the end of buffer.
          (delete-overlay o1))))))