mirror of
https://github.com/abo-abo/avy.git
synced 2025-10-13 13:33:03 +00:00
parent
aa35412375
commit
509471bad0
29
avy.el
29
avy.el
@ -2028,6 +2028,9 @@ 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'.")
|
||||
|
||||
(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
|
||||
@ -2041,8 +2044,8 @@ 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."
|
||||
(let ((str "")
|
||||
(re-builder (or re-builder #'regexp-quote))
|
||||
(setq avy-text "")
|
||||
(let ((re-builder (or re-builder #'regexp-quote))
|
||||
char break overlays regex)
|
||||
(unwind-protect
|
||||
(progn
|
||||
@ -2052,11 +2055,11 @@ Otherwise, the whole regex is highlighted."
|
||||
(setq char
|
||||
(read-char (format "%d char%s: "
|
||||
(length overlays)
|
||||
(if (string= str "")
|
||||
str
|
||||
(format " (%s)" str)))
|
||||
(if (string= avy-text "")
|
||||
avy-text
|
||||
(format " (%s)" avy-text)))
|
||||
t
|
||||
(and (not (string= str ""))
|
||||
(and (not (string= avy-text ""))
|
||||
avy-timeout-seconds))))
|
||||
;; Unhighlight
|
||||
(dolist (ov overlays)
|
||||
@ -2067,21 +2070,21 @@ Otherwise, the whole regex is highlighted."
|
||||
((= char 13)
|
||||
(if avy-enter-times-out
|
||||
(setq break t)
|
||||
(setq str (concat str (list ?\n)))))
|
||||
(setq avy-text (concat avy-text (list ?\n)))))
|
||||
;; Handle C-h, DEL
|
||||
((memq char avy-del-last-char-by)
|
||||
(let ((l (length str)))
|
||||
(let ((l (length avy-text)))
|
||||
(when (>= l 1)
|
||||
(setq str (substring str 0 (1- l))))))
|
||||
(setq avy-text (substring avy-text 0 (1- l))))))
|
||||
;; Handle ESC
|
||||
((= char 27)
|
||||
(keyboard-quit))
|
||||
(t
|
||||
(setq str (concat str (list char)))))
|
||||
(setq avy-text (concat avy-text (list char)))))
|
||||
;; Highlight
|
||||
(when (>= (length str) 1)
|
||||
(when (>= (length avy-text) 1)
|
||||
(let ((case-fold-search
|
||||
(or avy-case-fold-search (string= str (downcase str))))
|
||||
(or avy-case-fold-search (string= avy-text (downcase avy-text))))
|
||||
found)
|
||||
(avy-dowindows current-prefix-arg
|
||||
(dolist (pair (avy--find-visible-regions
|
||||
@ -2089,7 +2092,7 @@ Otherwise, the whole regex is highlighted."
|
||||
(window-end (selected-window) t)))
|
||||
(save-excursion
|
||||
(goto-char (car pair))
|
||||
(setq regex (funcall re-builder str))
|
||||
(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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user