Function: hs-cycle

hs-cycle is an interactive and byte-compiled function defined in hideshow.el.gz.

Signature

(hs-cycle &optional LEVEL)

Documentation

Cycle the visibility state of the current block.

This cycles the visibility of the current block between hide the parent block, hide the nested blocks only, and show the parent and nested blocks.

If LEVEL is specified (interactively, the prefix numeric argument), hide only blocks which are that many levels below the level of point.

View in manual

Probably introduced at or before Emacs version 31.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/hideshow.el.gz
(defun hs-cycle (&optional level)
  "Cycle the visibility state of the current block.
This cycles the visibility of the current block between hide the parent
block, hide the nested blocks only, and show the parent and nested
blocks.

If LEVEL is specified (interactively, the prefix numeric argument), hide
only blocks which are that many levels below the level of point."
  (interactive "p")
  (hs-life-goes-on
   (when-let* ((ret (hs-get-near-block :include-comments)))
     (cond ((eq ret 'comment)
            (hs-toggle-hiding)
            (message "Toggle visibility"))
           ((> level 1)
            (pcase-let ((`(,beg ,end) (hs-block-positions)))
              (hs-hide-level-recursive
               level beg end hs-hide-comments-when-hiding-all))
            (message "Hide %d level" level))
           (t
            (let* (hs-allow-nesting
                   (block (hs-block-positions :ad-beg :ad-end))
                   (ov (seq-find
                        (lambda (o)
                          (and (eq (overlay-get o 'invisible) 'hs)))
                        (overlays-in (car block) (cadr block)))))
              (cond
               ;; Hide all if there are no hidden blocks
               ((not ov)
                (hs-hide-block)
                (message "Hide block and nested blocks"))
               ;; Hide the children blocks if the parent block is hidden
               ((and (= (overlay-start ov) (car block))
                     (= (overlay-end ov) (cadr block)))
                (hs-hide-level-recursive
                 1 (car block) (cadr block)
                 hs-hide-comments-when-hiding-all)
                (message "Hide first nested blocks"))
               ;; Otherwise show all in the parent block, we cannot use
               ;; `hs-show-block' here because we already know the
               ;; positions.
               (ov (hs-discard-overlays (car block) (cadr block))
                   (message "Show block and nested blocks")
                   (run-hooks 'hs-show-hook)))))))))