Function: outline--hidden-headings-paths

outline--hidden-headings-paths is a byte-compiled function defined in outline.el.gz.

Signature

(outline--hidden-headings-paths)

Documentation

Return (HASH-TABLE CURRENT-HEADING).

HASH-TABLE holds the headings of currently hidden outlines. Every key is a list whose elements compose a complete path of headings descending from the top level down to the bottom level. Every entry's value is non-nil if that entry should be hidden. The specific non-nil vale can be t to hide just the entry, or a number LEVEL to mean that not just the entry should be hidden but also all the subsequent elements of level higher or equal to LEVEL. This is useful to save the hidden outlines and restore them later after reverting the buffer. CURRENT-HEADING is the heading where point is located.

Source Code

;; Defined in /usr/src/emacs/lisp/outline.el.gz
(defun outline--hidden-headings-paths ()
  "Return (HASH-TABLE CURRENT-HEADING).
HASH-TABLE holds the headings of currently hidden outlines.
Every key is a list whose elements compose a complete path
of headings descending from the top level down to the bottom level.
Every entry's value is non-nil if that entry should be hidden.
The specific non-nil vale can be t to hide just the entry, or a number
LEVEL to mean that not just the entry should be hidden but also all the
subsequent elements of level higher or equal to LEVEL.
This is useful to save the hidden outlines and restore them later
after reverting the buffer.
CURRENT-HEADING is the heading where point is located."
  (let* ((paths (make-hash-table :test #'equal))
         path current-path
         (current-heading-p (outline-on-heading-p))
         (current-beg (when current-heading-p (pos-bol)))
         (current-end (when current-heading-p (pos-eol))))
    (outline-map-region
     (lambda ()
       (let ((level (funcall outline-level)))
         (if (outline-invisible-p)
             ;; Covered by "the" previous heading.
             (cl-callf (lambda (l) (if (numberp l) (min l level) level))
                 (gethash (mapcar #'car path) paths))
           (let ((heading (buffer-substring-no-properties (pos-bol) (pos-eol))))
             (while (and path (>= (cdar path) level))
               (pop path))
             (push (cons heading level) path)
             (when (save-excursion
                     (outline-end-of-heading)
                     (outline-invisible-p))
               (setf (gethash (mapcar #'car path) paths) t))))
         (when (and current-heading-p (<= current-beg (point) current-end))
           (setq current-path (mapcar #'car path)))))
     (point-min) (point-max))
    (list paths current-path)))