Skip to content

Commit

Permalink
vimish: add accessers for nested non folded folds
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Magalhaes authored and Monkeypac committed Dec 3, 2017
1 parent 46dbfdc commit 500f06c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions vimish-fold.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 500f06c

Please sign in to comment.