merge: pull request #5401 from jeetelongname/tree-sitter
This commit is contained in:
commit
173396a963
52 changed files with 515 additions and 24 deletions
|
@ -32,6 +32,11 @@
|
|||
(end-of-line)
|
||||
(+fold--hideshow-fold-p))))))
|
||||
|
||||
;; NOTE: does this need more?
|
||||
(defun +fold--ts-fold-p ()
|
||||
(and (bound-and-true-p tree-sitter-mode)
|
||||
(featurep 'ts-fold)))
|
||||
|
||||
(defun +fold--invisible-points (count)
|
||||
(let (points)
|
||||
(save-excursion
|
||||
|
@ -62,7 +67,7 @@
|
|||
(defun +fold/toggle ()
|
||||
"Toggle the fold at point.
|
||||
|
||||
Targets `vimmish-fold', `hideshow' and `outline' folds."
|
||||
Targets `vimmish-fold', `hideshow', `ts-fold' and `outline' folds."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(cond ((+fold--vimish-fold-p) (vimish-fold-toggle))
|
||||
|
@ -70,29 +75,32 @@ Targets `vimmish-fold', `hideshow' and `outline' folds."
|
|||
(cl-letf (((symbol-function #'outline-hide-subtree)
|
||||
(symbol-function #'outline-hide-entry)))
|
||||
(outline-toggle-children)))
|
||||
((+fold--ts-fold-p) (ts-fold-toggle))
|
||||
((+fold--hideshow-fold-p) (+fold-from-eol (hs-toggle-hiding))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +fold/open ()
|
||||
"Open the folded region at point.
|
||||
|
||||
Targets `vimmish-fold', `hideshow' and `outline' folds."
|
||||
Targets `vimmish-fold', `hideshow', `ts-fold' and `outline' folds."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(cond ((+fold--vimish-fold-p) (vimish-fold-unfold))
|
||||
((+fold--outline-fold-p)
|
||||
(outline-show-children)
|
||||
(outline-show-entry))
|
||||
((+fold--ts-fold-p) (ts-fold-open))
|
||||
((+fold--hideshow-fold-p) (+fold-from-eol (hs-show-block))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +fold/close ()
|
||||
"Close the folded region at point.
|
||||
|
||||
Targets `vimmish-fold', `hideshow' and `outline' folds."
|
||||
Targets `vimmish-fold', `hideshow', `ts-fold' and `outline' folds."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(cond ((+fold--vimish-fold-p) (vimish-fold-refold))
|
||||
((+fold--ts-fold-p) (ts-fold-close))
|
||||
((+fold--hideshow-fold-p) (+fold-from-eol (hs-hide-block)))
|
||||
((+fold--outline-fold-p) (outline-hide-subtree)))))
|
||||
|
||||
|
@ -101,18 +109,20 @@ Targets `vimmish-fold', `hideshow' and `outline' folds."
|
|||
"Open folds at LEVEL (or all folds if LEVEL is nil)."
|
||||
(interactive
|
||||
(list (if current-prefix-arg (prefix-numeric-value current-prefix-arg))))
|
||||
(when (featurep 'vimish-fold)
|
||||
(vimish-fold-unfold-all))
|
||||
(save-excursion
|
||||
(+fold--ensure-hideshow-mode)
|
||||
(if (integerp level)
|
||||
(progn
|
||||
(outline-hide-sublevels (max 1 (1- level)))
|
||||
(hs-life-goes-on
|
||||
(hs-hide-level-recursive (1- level) (point-min) (point-max))))
|
||||
(hs-show-all)
|
||||
(when (fboundp 'outline-show-all)
|
||||
(outline-show-all)))))
|
||||
(cond ((+fold--ts-fold-p)
|
||||
(ts-fold-open-all))
|
||||
((featurep 'vimish-fold)
|
||||
(vimish-fold-unfold-all))
|
||||
((save-excursion
|
||||
(+fold--ensure-hideshow-mode)
|
||||
(if (integerp level)
|
||||
(progn
|
||||
(outline-hide-sublevels (max 1 (1- level)))
|
||||
(hs-life-goes-on
|
||||
(hs-hide-level-recursive (1- level) (point-min) (point-max))))
|
||||
(hs-show-all)
|
||||
(when (fboundp 'outline-show-all)
|
||||
(outline-show-all)))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +fold/close-all (&optional level)
|
||||
|
@ -120,13 +130,16 @@ Targets `vimmish-fold', `hideshow' and `outline' folds."
|
|||
(interactive
|
||||
(list (if current-prefix-arg (prefix-numeric-value current-prefix-arg))))
|
||||
(save-excursion
|
||||
(when (featurep 'vimish-fold)
|
||||
(vimish-fold-refold-all))
|
||||
(+fold--ensure-hideshow-mode)
|
||||
(hs-life-goes-on
|
||||
(if (integerp level)
|
||||
(hs-hide-level-recursive (1- level) (point-min) (point-max))
|
||||
(hs-hide-all)))))
|
||||
(if (+fold--ts-fold-p)
|
||||
(ts-fold-close-all)
|
||||
(progn
|
||||
(when (featurep 'vimish-fold)
|
||||
(vimish-fold-refold-all))
|
||||
(+fold--ensure-hideshow-mode)
|
||||
(hs-life-goes-on
|
||||
(if (integerp level)
|
||||
(hs-hide-level-recursive (1- level) (point-min) (point-max))
|
||||
(hs-hide-all)))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +fold/next (count)
|
||||
|
@ -142,7 +155,24 @@ Targets `vimmish-fold', `hideshow' and `outline' folds."
|
|||
(if (> count 0)
|
||||
(evil-vimish-fold/next-fold count)
|
||||
(evil-vimish-fold/previous-fold (- count))))
|
||||
(if (/= (point) orig-pt) (point))))
|
||||
(if (/= (point) orig-pt) (point)))
|
||||
(lambda ()
|
||||
;; ts-fold does not define movement functions so we need to do it ourselves
|
||||
(when (+fold--ts-fold-p)
|
||||
(let* ((arg-list (if (> count 0) ;; depending on direction we need to change the ranges
|
||||
(list (point) (point-max))
|
||||
(list (point-min) (point))))
|
||||
(comp-fun (if (> count 0) ;; also depending on direction we need to change how we sort the list
|
||||
#'<
|
||||
#'>))
|
||||
(ovs (cl-remove-if-not
|
||||
(lambda (ov)
|
||||
(eq (overlay-get ov 'creator) 'ts-fold))
|
||||
;; `overlays-in' does not provide a list that is sorted
|
||||
;; (in the way we need it atleast) so we need to sort it based on direction
|
||||
(cl-sort (apply #'overlays-in arg-list) comp-fun :key #'overlay-start))))
|
||||
(if (and ovs (<= (abs count) (length ovs)))
|
||||
(goto-char (overlay-start (nth (- (abs count) 1) ovs))))))))
|
||||
if (save-excursion (funcall fn))
|
||||
collect it into points
|
||||
finally do
|
||||
|
|
|
@ -86,3 +86,16 @@
|
|||
"zE" #'vimish-fold-delete-all)
|
||||
:config
|
||||
(vimish-fold-global-mode +1))
|
||||
|
||||
(use-package! ts-fold
|
||||
:when (featurep! :tools tree-sitter)
|
||||
:after tree-sitter
|
||||
:config
|
||||
;; we want to use our own face so we nullify this one to have no effect and
|
||||
;; make it more similar to hideshows
|
||||
(custom-set-faces! '(ts-fold-replacement-face :foreground nil
|
||||
:box nil
|
||||
:inherit font-lock-comment-face
|
||||
:weight light))
|
||||
(setq ts-fold-replacement " [...] ")
|
||||
(ts-fold-mode +1))
|
||||
|
|
|
@ -6,3 +6,6 @@
|
|||
(package! vimish-fold :pin "a6501cbfe3db791f9ca17fd986c7202a87f3adb8")
|
||||
(when (featurep! :editor evil)
|
||||
(package! evil-vimish-fold :pin "b6e0e6b91b8cd047e80debef1a536d9d49eef31a"))
|
||||
(when (featurep! :tools tree-sitter)
|
||||
(package! ts-fold :pin "01d6485398a553a4fc4bbb3910edeb881c657f1f"
|
||||
:recipe (:host github :repo "jcs090218/ts-fold")))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue