You could define the following function
(defun hs-show-all-on-editing ()
(unless (member last-command-event '(up down left right))
(hs-show-all)
(remove-hook 'pre-command-hook #'hs-show-all-on-editing)))
and then advise hs-show-all
to add this function to the pre-command-hook
:
(advice-add 'hs-hide-all :after (lambda () (add-hook 'pre-command-hook #'hs-show-all-on-editing nil t)))
The logic in the function calls hs-show-all
only when some other key than an arrow key is pressed, but you could add more 'keys' (that should not trigger hs-show-all
) to the list.
Of course, this only works if you use hs-hide-all
to hide the blocks (but you can always advise more functions).
If you'd like to use SPC
or RET
to trigger hs-show-all
without inserting, then you could conditionally remove the inserted char using the post-command-hook
:
(defun hs-show-delete-backward-char ()
(when (memq last-command-event '(13 32))
(delete-backward-char 1)
(remove-hook 'post-command-hook #'hs-show-all-on-editing)))
(advice-add 'hs-hide-all :after (lambda () (add-hook 'post-command-hook #'hs-show-delete-backward-char nil t)))
Be aware that you should call hs-hide-all
via a shortcut, because if you call it via M-x
(which requires pressing RET
) then this hook function will run directly after running hs-hide-all
.
This is the most pragmatic solution. A better solution might be implemented by defining a minor mode, but this would require fully rewriting this answer, and as long as thing work fine, they work fine.
Although this idea does not seem bad at all, personally I am mostly using imenu
(with helm/counsel/consult, i.e. SPC j i
in Spacemacs) and 'evil marks' for quick navigation.