Function: outline--show-headings-up-to-level
outline--show-headings-up-to-level is a byte-compiled function defined
in outline.el.gz.
Signature
(outline--show-headings-up-to-level LEVEL)
Documentation
Show only headings up to a LEVEL level.
Like outline-hide-sublevels but, for each heading at level
LEVEL, decides of subtree visibility according to
outline-default-rules.
Source Code
;; Defined in /usr/src/emacs/lisp/outline.el.gz
(defun outline--show-headings-up-to-level (level)
"Show only headings up to a LEVEL level.
Like `outline-hide-sublevels' but, for each heading at level
LEVEL, decides of subtree visibility according to
`outline-default-rules'."
(if (not outline-default-rules)
(outline-hide-sublevels level)
(if (< level 1)
(error "Must keep at least one level of headers"))
(save-excursion
(let* (outline-view-change-hook
(beg (progn
(goto-char (point-min))
;; Skip the prelude, if any.
(unless (outline-on-heading-p t) (outline-next-heading))
(point)))
(end (progn
(goto-char (point-max))
;; Keep empty last line, if available.
(if (bolp) (1- (point)) (point))))
(heading-regexp
(cdr-safe
(assoc 'match-regexp outline-default-rules)))
(check-line-count
(memq 'subtree-is-long outline-default-rules))
(check-long-lines
(memq 'subtree-has-long-lines outline-default-rules))
(custom-function
(cdr-safe
(assoc 'custom-function outline-default-rules))))
(if (< end beg)
(setq beg (prog1 end (setq end beg))))
;; First hide everything.
(outline-hide-sublevels level)
;; Then unhide the top level headers.
(outline-map-region
(lambda ()
(let ((current-level (funcall outline-level)))
(when (< current-level level)
(outline-show-heading)
(outline-show-entry))
(when (= current-level level)
(cond
((and heading-regexp
(let ((beg (point))
(end (progn (outline-end-of-heading) (point))))
(string-match-p heading-regexp (buffer-substring beg end))))
;; hide entry when heading match regexp
(outline-hide-entry))
((and check-line-count
(save-excursion
(let ((beg (point))
(end (progn (outline-end-of-subtree) (point))))
(<= outline-default-line-count (count-lines beg end)))))
;; show only branches when line count of subtree >
;; threshold
(outline-show-branches))
((and check-long-lines
(save-excursion
(let ((beg (point))
(end (progn (outline-end-of-subtree) (point))))
(save-restriction
(narrow-to-region beg end)
(let ((so-long-skip-leading-comments nil)
(so-long-threshold outline-default-long-line)
(so-long-max-lines nil))
(so-long-detected-long-line-p))))))
;; show only branches when long lines are detected
;; in subtree
(outline-show-branches))
(custom-function
;; call custom function if defined
(funcall custom-function))
(t
;; if no previous clause succeeds, show subtree
(outline-show-subtree))))))
beg end)))
(run-hooks 'outline-view-change-hook)))