Function: rst-hdr-hierarchy

rst-hdr-hierarchy is a byte-compiled function defined in rst.el.gz.

Signature

(rst-hdr-hierarchy &optional IGNORE-POSITION)

Documentation

Return the hierarchy of section titles in the file as a rst-Hdr list.

Each returned element may be used directly to create a section adornment on that level. If IGNORE-POSITION a title containing this position is not taken into account when building the hierarchy unless it appears again elsewhere. This catches cases where the current title is edited and may not be final regarding its level.

Uses and sets rst-hdr-hierarchy-cache unless IGNORE-POSITION is given.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/rst.el.gz
(defun rst-hdr-hierarchy (&optional ignore-position)
  ;; testcover: ok.
  "Return the hierarchy of section titles in the file as a `rst-Hdr' list.
Each returned element may be used directly to create a section
adornment on that level.  If IGNORE-POSITION a title containing
this position is not taken into account when building the
hierarchy unless it appears again elsewhere.  This catches cases
where the current title is edited and may not be final regarding
its level.

Uses and sets `rst-hdr-hierarchy-cache' unless IGNORE-POSITION is
given."
  (let* ((all-ttls (rst-all-ttls))
	 (ignore-ttl
	  (if ignore-position
	      (cl-find-if
               (lambda (ttl)
                 (equal (rst-Ttl-contains ttl ignore-position) 0))
	       all-ttls)))
	 (really-ignore
	  (if ignore-ttl
	      (<= (cl-count-if
                   (lambda (ttl)
                     (rst-Ado-equal (rst-Ttl-ado ignore-ttl)
                                 (rst-Ttl-ado ttl)))
		   all-ttls)
		  1)))
	 (real-ttls (delq (if really-ignore ignore-ttl) all-ttls)))
    (copy-sequence ; Protect cache.
     (if (and (not ignore-position) rst-hdr-hierarchy-cache)
	 (if (eq rst-hdr-hierarchy-cache t)
	     nil
	   rst-hdr-hierarchy-cache)
       (let ((r (rst-infer-hdr-hierarchy (mapcar #'rst-Ttl-hdr real-ttls))))
	 (setq rst-hdr-hierarchy-cache
	       (if ignore-position
		   ;; Clear cache reflecting that a possible update is not
		   ;; reflected.
		   nil
		 (or r t)))
	 r)))))