mirror of
https://github.com/abo-abo/avy.git
synced 2025-10-13 13:33:03 +00:00
Improve avy-goto-char-timer.
1. Handle DEL in order to fix typos. 2. Handle RET in order to use the current input string immediately without waiting for another char for avy-timeout-seconds. 3. Highlight matches while reading chars.
This commit is contained in:
parent
3f53a2a15e
commit
f9d7a76cd4
43
avy.el
43
avy.el
@ -1039,17 +1039,48 @@ ARG lines can be used."
|
|||||||
(defun avy--read-string-timer ()
|
(defun avy--read-string-timer ()
|
||||||
"Read as many chars as possible and return them as string.
|
"Read as many chars as possible and return them as string.
|
||||||
At least one char must be read, and then repeatedly one next char
|
At least one char must be read, and then repeatedly one next char
|
||||||
may be read if it is entered before `avy-timeout-seconds'."
|
may be read if it is entered before `avy-timeout-seconds'. `DEL'
|
||||||
(let ((str "") char)
|
deletes the last char entered, and `RET' exits with the currently
|
||||||
(while (setq char (read-char (format "char%s: "
|
read string immediately instead of waiting for another char for
|
||||||
|
`avy-timeout-seconds'."
|
||||||
|
(let ((str "") char break overlays)
|
||||||
|
(unwind-protect
|
||||||
|
(progn
|
||||||
|
(while (and (not break)
|
||||||
|
(setq char (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))))
|
||||||
(setq str (concat str (list char))))
|
;; Unhighlight
|
||||||
str))
|
(dolist (ov overlays)
|
||||||
|
(delete-overlay ov))
|
||||||
|
(setq overlays nil)
|
||||||
|
(cond
|
||||||
|
;; Handle RET
|
||||||
|
((= char 13)
|
||||||
|
(setq break t))
|
||||||
|
;; Handle DEL
|
||||||
|
((= char 127)
|
||||||
|
(let ((l (length str)))
|
||||||
|
(when (>= l 1)
|
||||||
|
(setq str (substring str 0 (1- l))))))
|
||||||
|
(t
|
||||||
|
(setq str (concat str (list char)))))
|
||||||
|
;; Highlight
|
||||||
|
(when (>= (length str) 1)
|
||||||
|
(save-excursion
|
||||||
|
(goto-char (window-start))
|
||||||
|
(while (re-search-forward (regexp-quote str) (window-end) t)
|
||||||
|
(let ((ov (make-overlay (match-beginning 0) (match-end 0))))
|
||||||
|
(push ov overlays)
|
||||||
|
(overlay-put ov 'window (selected-window))
|
||||||
|
(overlay-put ov 'face 'avy-lead-face))))))
|
||||||
|
str)
|
||||||
|
(dolist (ov overlays)
|
||||||
|
(delete-overlay ov)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun avy-goto-char-timer (&optional arg)
|
(defun avy-goto-char-timer (&optional arg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user