3

I want to combine the commands hs-hide-all and hs-show-all.

It would be great if I'd have a function that detects the "status" of all blocks. If there are blocks that aren't hidden, the function should hide them, thus all blocks are hidden. Applying it when all blocks are hidden, the function ought to show all of them.

1 Answer 1

4

hideshow uses overlays to hide text. Because of this you can make the semi-maybe-safe assumption that if the number of overlays in the current buffer doesn't increase after running hs-hide-all, then all top level blocks must have been already hidden.

(defun my-hs-toggle-all ()
  "If anything isn't hidden, run `hs-hide-all', else run `hs-show-all'."
  (interactive)
  (let ((starting-ov-count (length (overlays-in (point-min) (point-max)))))
    (hs-hide-all)
    (when (equal (length (overlays-in (point-min) (point-max))) starting-ov-count)
      (hs-show-all))))

I couldn't see an obvious "right" way to do this in hideshow but this hack seems to work.

1
  • nice...thx a lot
    – bertfred
    Mar 11, 2016 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.