Setup hideshow.el

This commit is contained in:
Case Duckworth 2021-12-28 18:20:24 -06:00
parent f485d590ec
commit 8515985057
2 changed files with 53 additions and 0 deletions

View File

@ -247,6 +247,15 @@
"M-n" nil
"M-p" nil))
(setup hideshow
(:also-load +hideshow)
(:with-mode hs-minor-mode
(:hook-into prog-mode)
(:bind "C-<tab>" #'+hs-cycle
"C-S-<tab>" #'+hs-global-cycle
;; but y tho
"C-S-<iso-lefttab>" #'+hs-global-cycle)))
(setup ibuffer
(:also-load ibuf-ext)
(:option ibuffer-expert t

44
lisp/+hideshow.el Normal file
View File

@ -0,0 +1,44 @@
;;; +hideshow.el -*- lexical-binding: t; -*-
;;; Commentary:
;; initiated by https://karthinks.com/software/simple-folding-with-hideshow/
;;; Code:
(defun +hs-cycle (&optional level)
(interactive "p")
(let (message-log-max
(inhibit-message t))
(if (= level 1)
(pcase last-command
('+hs-cycle
(hs-hide-level 1)
(setq this-command 'hs-cycle-children))
('hs-cycle-children
;; TODO: Fix this case. `hs-show-block' needs to be
;; called twice to open all folds of the parent
;; block.
(save-excursion (hs-show-block))
(hs-show-block)
(setq this-command 'hs-cycle-subtree))
('hs-cycle-subtree
(hs-hide-block))
(_
(if (not (hs-already-hidden-p))
(hs-hide-block)
(hs-hide-level 1)
(setq this-command 'hs-cycle-children))))
(hs-hide-level level)
(setq this-command 'hs-hide-level))))
(defun +hs-global-cycle ()
(interactive)
(pcase last-command
('+hs-global-cycle
(save-excursion (hs-show-all))
(setq this-command 'hs-global-show))
(_ (hs-hide-all))))
(provide '+hideshow)
;;; +hideshow.el ends here