feat(tree-sitter): add ts to open/close all

also refactor +fold-open-all, +fold-close-all to use cond instead of the
when case for vimish fold.
This commit is contained in:
Jeetaditya Chatterjee 2021-10-28 15:07:03 +01:00
parent c3e360eeaa
commit 7b9d00d661
No known key found for this signature in database
GPG key ID: 09D54CECD2132B91

View file

@ -109,18 +109,20 @@ Targets `vimmish-fold', `hideshow', `ts-fold' and `outline' folds."
"Open folds at LEVEL (or all folds if LEVEL is nil)." "Open folds at LEVEL (or all folds if LEVEL is nil)."
(interactive (interactive
(list (if current-prefix-arg (prefix-numeric-value current-prefix-arg)))) (list (if current-prefix-arg (prefix-numeric-value current-prefix-arg))))
(when (featurep 'vimish-fold) (cond ((+fold--ts-fold-p)
(vimish-fold-unfold-all)) (ts-fold-open-all))
(save-excursion ((featurep 'vimish-fold)
(+fold--ensure-hideshow-mode) (vimish-fold-unfold-all))
(if (integerp level) (t (save-excursion
(progn (+fold--ensure-hideshow-mode)
(outline-hide-sublevels (max 1 (1- level))) (if (integerp level)
(hs-life-goes-on (progn
(hs-hide-level-recursive (1- level) (point-min) (point-max)))) (outline-hide-sublevels (max 1 (1- level)))
(hs-show-all) (hs-life-goes-on
(when (fboundp 'outline-show-all) (hs-hide-level-recursive (1- level) (point-min) (point-max))))
(outline-show-all))))) (hs-show-all)
(when (fboundp 'outline-show-all)
(outline-show-all)))))))
;;;###autoload ;;;###autoload
(defun +fold/close-all (&optional level) (defun +fold/close-all (&optional level)
@ -128,13 +130,15 @@ Targets `vimmish-fold', `hideshow', `ts-fold' and `outline' folds."
(interactive (interactive
(list (if current-prefix-arg (prefix-numeric-value current-prefix-arg)))) (list (if current-prefix-arg (prefix-numeric-value current-prefix-arg))))
(save-excursion (save-excursion
(when (featurep 'vimish-fold) (cond ((+fold--ts-fold-p)
(vimish-fold-refold-all)) (ts-fold-close-all))
(+fold--ensure-hideshow-mode) (t (when (featurep 'vimish-fold)
(hs-life-goes-on (vimish-fold-refold-all))
(if (integerp level) (+fold--ensure-hideshow-mode)
(hs-hide-level-recursive (1- level) (point-min) (point-max)) (hs-life-goes-on
(hs-hide-all))))) (if (integerp level)
(hs-hide-level-recursive (1- level) (point-min) (point-max))
(hs-hide-all)))))))
;;;###autoload ;;;###autoload
(defun +fold/next (count) (defun +fold/next (count)