Skip to content

Commit

Permalink
fix(avy-next/prev): Allow avy-next/prev to handle non-cons candidates.
Browse files Browse the repository at this point in the history
This commit fixes the `avy-last-candidates-cycle` / `avy-next`
/ `avy-pref` defun's so that they can handle candidates with non-cons
car elements (as are set up by `avy-goto-line`.)  Without this fix,
`avy-next` / `avy-prev` throw errors if the last `avy` commands was
`avy-goto-line`.
  • Loading branch information
Brian-Kavanagh committed Apr 20, 2023
1 parent d9634ef commit be61211
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions avy.el
Expand Up @@ -838,11 +838,11 @@ Set `avy-style' according to COMMAND as well."
avy-last-candidates))
(min-dist
(apply #'min
(mapcar (lambda (x) (abs (- (caar x) (point)))) avy-last-candidates)))
(mapcar (lambda (x) (abs (- (if (listp (car x)) (caar x) (car x)) (point)))) avy-last-candidates)))
(pos
(cl-position-if
(lambda (x)
(= (- (caar x) (point)) min-dist))
(= (- (if (listp (car x)) (caar x) (car x)) (point)) min-dist))
avy-last-candidates)))
(funcall advancer pos avy-last-candidates)))

Expand All @@ -852,15 +852,17 @@ Set `avy-style' according to COMMAND as well."
(avy--last-candidates-cycle
(lambda (pos lst)
(when (> pos 0)
(goto-char (caar (nth (1- pos) lst)))))))
(let ((candidate (nth (1- pos) lst)))
(goto-char (if (listp (car candidate)) (caar candidate) (car candidate))))))))

(defun avy-next ()
"Go to the next candidate of the last `avy-read'."
(interactive)
(avy--last-candidates-cycle
(lambda (pos lst)
(when (< pos (1- (length lst)))
(goto-char (caar (nth (1+ pos) lst)))))))
(let ((candidate (nth (1+ pos) lst)))
(goto-char (if (listp (car candidate)) (caar candidate) (car candidate))))))))

;;;###autoload
(defun avy-process (candidates &optional overlay-fn cleanup-fn)
Expand Down

0 comments on commit be61211

Please sign in to comment.