feat(fold): define ts-fold movement logic

As ts-fold does not provide fold movement logic I made my own. This can
and probably should be upstreamed but the details for that are not clear
This commit is contained in:
Jeetaditya Chatterjee 2021-11-08 02:30:25 +00:00
parent f39fb3afc1
commit c16e16e92b
No known key found for this signature in database
GPG key ID: 09D54CECD2132B91

View file

@ -154,7 +154,25 @@ Targets `vimmish-fold', `hideshow', `ts-fold' and `outline' folds."
(if (> count 0) (if (> count 0)
(evil-vimish-fold/next-fold count) (evil-vimish-fold/next-fold count)
(evil-vimish-fold/previous-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 (seq-filter
(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 (eval `(overlays-in ,@arg-list))
(lambda (ov1 ov2)
(funcall comp-fun (overlay-start ov1) (overlay-start ov2)))))))
(if ovs (goto-char (overlay-start (nth (- (abs count) 1) ovs))))))))
if (save-excursion (funcall fn)) if (save-excursion (funcall fn))
collect it into points collect it into points
finally do finally do