avy.el (avy--read-candidates): Use avy-dowindows

Fixes #114
This commit is contained in:
Oleh Krehel 2015-11-11 13:50:04 +01:00
parent 1b78fb0d89
commit edf1259f25

103
avy.el
View File

@ -1147,58 +1147,57 @@ The format of the result is the same as that of `avy--regex-candidates'.
This function obeys `avy-all-windows' setting." This function obeys `avy-all-windows' setting."
(let ((str "") char break overlays regex) (let ((str "") char break overlays regex)
(unwind-protect (unwind-protect
(progn (progn
(while (and (not break) (while (and (not break)
(setq char (setq char
(read-char (format "char%s: " (read-char (format "char%s: "
(if (string= str "") (if (string= str "")
str str
(format " (%s)" str))) (format " (%s)" str)))
t t
(and (not (string= str "")) (and (not (string= str ""))
avy-timeout-seconds)))) avy-timeout-seconds))))
;; Unhighlight ;; Unhighlight
(dolist (ov overlays) (dolist (ov overlays)
(delete-overlay ov)) (delete-overlay ov))
(setq overlays nil) (setq overlays nil)
(cond (cond
;; Handle RET ;; Handle RET
((= char 13) ((= char 13)
(setq break t)) (setq break t))
;; Handle DEL ;; Handle DEL
((= char 127) ((= char 127)
(let ((l (length str))) (let ((l (length str)))
(when (>= l 1) (when (>= l 1)
(setq str (substring str 0 (1- l)))))) (setq str (substring str 0 (1- l))))))
(t (t
(setq str (concat str (list char))))) (setq str (concat str (list char)))))
;; Highlight ;; Highlight
(when (>= (length str) 1) (when (>= (length str) 1)
(let (found) (let (found)
(dolist (win (avy-window-list)) (avy-dowindows nil
(with-selected-window win (dolist (pair (avy--find-visible-regions
(dolist (pair (avy--find-visible-regions (window-start)
(window-start) (window-end (selected-window) t)))
(window-end (selected-window) t))) (save-excursion
(save-excursion (goto-char (car pair))
(goto-char (car pair)) (setq regex (regexp-quote str))
(setq regex (regexp-quote str)) (while (re-search-forward regex (cdr pair) t)
(while (re-search-forward regex (cdr pair) t) (unless (get-char-property (1- (point)) 'invisible)
(unless (get-char-property (1- (point)) 'invisible) (let ((ov (make-overlay
(let ((ov (make-overlay (match-beginning 0)
(match-beginning 0) (match-end 0))))
(match-end 0)))) (setq found t)
(setq found t) (push ov overlays)
(push ov overlays) (overlay-put ov 'window (selected-window))
(overlay-put ov 'window (selected-window)) (overlay-put ov 'face 'avy-goto-char-timer-face)))))))
(overlay-put ov 'face 'avy-goto-char-timer-face)))))))) ;; No matches at all, so there's surely a typo in the input.
;; No matches at all, so there's surely a typo in the input. (unless found (beep)))))
(unless found (beep))))) (nreverse (mapcar (lambda (ov)
(nreverse (mapcar (lambda (ov) (cons (cons (overlay-start ov)
(cons (cons (overlay-start ov) (overlay-end ov))
(overlay-end ov)) (overlay-get ov 'window)))
(overlay-get ov 'window))) overlays)))
overlays)))
(dolist (ov overlays) (dolist (ov overlays)
(delete-overlay ov))))) (delete-overlay ov)))))