Function: avy--read-candidates
avy--read-candidates is a byte-compiled function defined in avy.el.
Signature
(avy--read-candidates &optional RE-BUILDER)
Documentation
Read as many chars as possible and return their occurrences.
At least one char must be read, and then repeatedly one next char
may be read if it is entered before avy-timeout-seconds. DEL
deletes the last char entered, and RET exits with the currently
read string immediately instead of waiting for another char for
avy-timeout-seconds.
The format of the result is the same as that of avy--regex-candidates.
This function obeys avy-all-windows setting.
RE-BUILDER is a function that takes a string and returns a regex.
When nil, regexp-quote is used.
If a group is captured, the first group is highlighted.
Otherwise, the whole regex is highlighted.
Source Code
;; Defined in ~/.emacs.d/elpa/avy-20241101.1357/avy.el
(defun avy--read-candidates (&optional re-builder)
"Read as many chars as possible and return their occurrences.
At least one char must be read, and then repeatedly one next char
may be read if it is entered before `avy-timeout-seconds'. DEL
deletes the last char entered, and RET exits with the currently
read string immediately instead of waiting for another char for
`avy-timeout-seconds'.
The format of the result is the same as that of `avy--regex-candidates'.
This function obeys `avy-all-windows' setting.
RE-BUILDER is a function that takes a string and returns a regex.
When nil, `regexp-quote' is used.
If a group is captured, the first group is highlighted.
Otherwise, the whole regex is highlighted."
(setq avy-text "")
(let ((re-builder (or re-builder #'regexp-quote))
char break overlays regex)
(unwind-protect
(progn
(avy--make-backgrounds
(avy-window-list))
(while (and (not break)
(setq char
(read-char (format "%d char%s: "
(length overlays)
(if (string= avy-text "")
avy-text
(format " (%s)" avy-text)))
t
(and (not (string= avy-text ""))
avy-timeout-seconds))))
;; Unhighlight
(dolist (ov overlays)
(delete-overlay ov))
(setq overlays nil)
(cond
;; Handle RET
((= char 13)
(if avy-enter-times-out
(setq break t)
(setq avy-text (concat avy-text (list ?\n)))))
;; Handle C-h, DEL
((memq char avy-del-last-char-by)
(let ((l (length avy-text)))
(when (>= l 1)
(setq avy-text (substring avy-text 0 (1- l))))))
;; Handle ESC
((= char 27)
(keyboard-quit))
(t
(setq avy-text (concat avy-text (list char)))))
;; Highlight
(when (>= (length avy-text) 1)
(let ((case-fold-search
(or avy-case-fold-search (string= avy-text (downcase avy-text))))
found)
(avy-dowindows current-prefix-arg
(dolist (pair (avy--find-visible-regions
(window-start)
(window-end (selected-window) t)))
(save-excursion
(goto-char (car pair))
(setq regex (funcall re-builder avy-text))
(while (re-search-forward regex (cdr pair) t)
(unless (not (avy--visible-p (1- (point))))
(let* ((idx (if (= (length (match-data)) 4) 1 0))
(ov (make-overlay
(match-beginning idx) (match-end idx))))
(setq found t)
(push ov overlays)
(overlay-put
ov 'window (selected-window))
(overlay-put
ov 'face 'avy-goto-char-timer-face)))))))
;; No matches at all, so there's surely a typo in the input.
(unless found (beep)))))
(nreverse (mapcar (lambda (ov)
(cons (cons (overlay-start ov)
(overlay-end ov))
(overlay-get ov 'window)))
overlays)))
(dolist (ov overlays)
(delete-overlay ov))
(avy--done))))