Function: outline-hide-sublevels
outline-hide-sublevels is an interactive and byte-compiled function
defined in outline.el.gz.
Signature
(outline-hide-sublevels LEVELS)
Documentation
Hide everything but the top LEVELS levels of headers, in whole buffer.
This also unhides the top heading-less body, if any.
Interactively, the prefix argument supplies the value of LEVELS. When invoked without a prefix argument, LEVELS defaults to the level of the current heading, or to 1 if the current line is not a heading.
This function has :around advice: outline-hide-sublevels@fix-for-org-fold.
Key Bindings
Aliases
hide-sublevels (obsolete since 25.1)
Source Code
;; Defined in /usr/src/emacs/lisp/outline.el.gz
(defun outline-hide-sublevels (levels)
"Hide everything but the top LEVELS levels of headers, in whole buffer.
This also unhides the top heading-less body, if any.
Interactively, the prefix argument supplies the value of LEVELS.
When invoked without a prefix argument, LEVELS defaults to the level
of the current heading, or to 1 if the current line is not a heading."
(interactive (list
(cond
(current-prefix-arg (prefix-numeric-value current-prefix-arg))
((save-excursion
(forward-line 0)
(if outline-search-function
(funcall outline-search-function nil nil nil t)
(looking-at outline-regexp)))
(funcall outline-level))
(t 1))))
(if (< levels 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)))))
(if (< end beg)
(setq beg (prog1 end (setq end beg))))
;; First hide everything.
(outline-flag-region beg end t)
;; Then unhide the top level headers.
(outline-map-region
(lambda ()
(if (<= (funcall outline-level) levels)
(outline-show-heading)))
beg end)
;; Finally unhide any trailing newline.
(goto-char (point-max))
(if (and (bolp) (not (bobp)) (outline-invisible-p (1- (point))))
(outline-flag-region (1- (point)) (point) nil))))
(run-hooks 'outline-view-change-hook))