diff --git a/vimish-fold.el b/vimish-fold.el index f80360a..356ef66 100644 --- a/vimish-fold.el +++ b/vimish-fold.el @@ -338,6 +338,16 @@ If OVERLAY does not represent a fold, it's ignored." #'vimish-fold--vimish-overlay-p (overlays-in beg end))) +(defun vimish-fold--folds-beginning-in (beg end) + "Returns all the folds beginning if BEG and END in current buffer." + (let ((list (vimish-fold--folds-in beg end)) tmp-ov) + (while (list) + (setq tmp-ov (car list)) + (unless (and (>= beg (overlay-start tmp-ov)) + (<= end (overlay-start tmp-ov))) + (delq tmp-ov list)) + (setq list (cdr list))))) + ;;;###autoload (defun vimish-fold-unfold-all () "Unfold all folds in current buffer." @@ -442,6 +452,26 @@ This feature needs `avy' package." folds-before-point))) (message "No more folds before point")))) +(defun vimish-fold-previous-existing-fold () + "Jump to previous vimish region in current buffer. + +The difference with vimish-fold-previous-fold is that here, the previous +folds can be englobing folds (see vimish-fold-allow-nested)" + (interactive) + (let ((folds-before-point + (cl-nset-difference + (vimish-fold--folds-in (point-min) (point)) + (vimish-fold--folds-beginning-in (point) (point-max)) + ))) + (if folds-before-point + (goto-char + (cl-reduce + #'max + (mapcar + #'overlay-start + folds-before-point))) + (message "No more folds before point")))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Persistence