Skip to content

Commit

Permalink
Change avy--process to accept cleanup function
Browse files Browse the repository at this point in the history
Renamed to `avy-process' to indicate that it is used from another packages.

Fixes #255
Fixes #266
  • Loading branch information
yyoncho authored and abo-abo committed Mar 19, 2019
1 parent e802510 commit 8db2759
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions avy.el
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ Set `avy-style' according to COMMMAND as well."
(select-frame-set-input-focus frame))
(select-window window))))

(defun avy--process-1 (candidates overlay-fn)
(defun avy--process-1 (candidates overlay-fn &optional cleanup-fn)
(let ((len (length candidates)))
(cond ((= len 0)
nil)
Expand All @@ -784,7 +784,7 @@ Set `avy-style' according to COMMMAND as well."
(t
(avy-read (avy-tree candidates avy-keys)
overlay-fn
#'avy--remove-leading-chars))))
(or cleanup-fn #'avy--remove-leading-chars)))))
(avy--done))))))

(defvar avy-last-candidates nil
Expand Down Expand Up @@ -821,24 +821,27 @@ Set `avy-style' according to COMMMAND as well."
(when (< pos (1- (length lst)))
(goto-char (caar (nth (1+ pos) lst)))))))

(defun avy--process (candidates &optional overlay-fn)
(defun avy-process (candidates &optional overlay-fn cleanup-fn)
"Select one of CANDIDATES using `avy-read'.
Use OVERLAY-FN to visualize the decision overlay."
Use OVERLAY-FN to visualize the decision overlay.
CLEANUP-FN should take no arguments and remove the effects of
multiple OVERLAY-FN invocations."
(setq overlay-fn (or overlay-fn (avy--style-fn avy-style)))
(setq cleanup-fn (or cleanup-fn #'avy--remove-leading-chars))
(unless (and (consp (car candidates))
(windowp (cdar candidates)))
(setq candidates
(mapcar (lambda (x) (cons x (selected-window)))
candidates)))
(setq avy-last-candidates (copy-sequence candidates))
(let ((original-cands (copy-sequence candidates))
(res (avy--process-1 candidates overlay-fn)))
(res (avy--process-1 candidates overlay-fn cleanup-fn)))
(cond
((null res)
(message "zero candidates")
t)
((eq res 'restart)
(avy--process original-cands overlay-fn))
(avy--process original-cands overlay-fn cleanup-fn))
;; ignore exit from `avy-handler-function'
((eq res 'exit))
(t
Expand All @@ -849,6 +852,9 @@ Use OVERLAY-FN to visualize the decision overlay."
(car res)
res))))))

(define-obsolete-function-alias 'avy--process 'avy-process
"0.4.0")

(defvar avy--overlays-back nil
"Hold overlays for when `avy-background' is t.")

Expand Down

0 comments on commit 8db2759

Please sign in to comment.