avy.el (avy-text): Store the avy-goto-char-timer text

Fixes #303
This commit is contained in:
Oleh Krehel
2020-04-22 13:53:20 +02:00
parent aa35412375
commit 509471bad0

29
avy.el
View File

@@ -2028,6 +2028,9 @@ newline."
(defcustom avy-enter-times-out t (defcustom avy-enter-times-out t
"Whether enter exits avy-goto-char-timer early. If nil it matches newline" "Whether enter exits avy-goto-char-timer early. If nil it matches newline"
:type 'boolean)
(defvar avy-text ""
"Store the input read by `avy--read-candidates'.") "Store the input read by `avy--read-candidates'.")
(defun avy--read-candidates (&optional re-builder) (defun avy--read-candidates (&optional re-builder)
@@ -2041,8 +2044,8 @@ RE-BUILDER is a function that takes a string and returns a regex.
This function obeys `avy-all-windows' setting. This function obeys `avy-all-windows' setting.
RE-BUILDER is a function that takes a string and returns a regex. RE-BUILDER is a function that takes a string and returns a regex.
When nil, `regexp-quote' is used. When nil, `regexp-quote' is used.
If a group is captured, the first group is highlighted. If a group is captured, the first group is highlighted.
Otherwise, the whole regex is highlighted." Otherwise, the whole regex is highlighted."
(setq avy-text "") (setq avy-text "")
(let ((re-builder (or re-builder #'regexp-quote)) (let ((re-builder (or re-builder #'regexp-quote))
char break overlays regex) char break overlays regex)
@@ -2052,11 +2055,11 @@ Otherwise, the whole regex is highlighted."
(avy-window-list)) (avy-window-list))
(while (and (not break) (while (and (not break)
(setq char (setq char
(read-char (format "%d char%s: " (read-char (format "%d char%s: "
(length overlays) (length overlays)
(if (string= str "") (if (string= avy-text "")
avy-text avy-text
(format " (%s)" str))) (format " (%s)" avy-text)))
t t
(and (not (string= avy-text "")) (and (not (string= avy-text ""))
avy-timeout-seconds)))) avy-timeout-seconds))))
@@ -2067,21 +2070,21 @@ Otherwise, the whole regex is highlighted."
(cond (cond
;; Handle RET ;; Handle RET
((= char 13) ((= char 13)
(if avy-enter-times-out (if avy-enter-times-out
(setq break t) (setq break t)
(setq avy-text (concat avy-text (list ?\n))))) (setq avy-text (concat avy-text (list ?\n)))))
;; Handle C-h, DEL ;; Handle C-h, DEL
((memq char avy-del-last-char-by) ((memq char avy-del-last-char-by)
(let ((l (length str))) (let ((l (length avy-text)))
(when (>= l 1) (when (>= l 1)
(setq avy-text (substring avy-text 0 (1- l)))))) (setq avy-text (substring avy-text 0 (1- l))))))
;; Handle ESC ;; Handle ESC
((= char 27) ((= char 27)
(keyboard-quit)) (keyboard-quit))
(t (t
(setq str (concat str (list char))))) (setq avy-text (concat avy-text (list char)))))
;; Highlight ;; Highlight
(when (>= (length str) 1) (when (>= (length avy-text) 1)
(let ((case-fold-search (let ((case-fold-search
(or avy-case-fold-search (string= avy-text (downcase avy-text)))) (or avy-case-fold-search (string= avy-text (downcase avy-text))))
found) found)
@@ -2089,7 +2092,7 @@ Otherwise, the whole regex is highlighted."
(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 (funcall re-builder avy-text)) (setq regex (funcall re-builder avy-text))
(while (re-search-forward regex (cdr pair) t) (while (re-search-forward regex (cdr pair) t)