mirror of
https://github.com/abo-abo/avy.git
synced 2025-10-13 21:33:05 +00:00
Make "C-g" and "ESC" fail silently when reading char
* avy.el (avy-ignored-modes): Add type. (avy-handler-default): Silence "C-g" and "ESC". (avy-goto-line): Call `avy-handler-function' instead of `avy-handler-default'. (avy-timeout-seconds): Add type. Fixes #137
This commit is contained in:
parent
5f76c9d16e
commit
3b75d9520d
26
avy.el
26
avy.el
@ -165,7 +165,8 @@ When nil, punctuation chars will not be matched.
|
||||
|
||||
(defcustom avy-ignored-modes '(image-mode doc-view-mode pdf-view-mode)
|
||||
"List of modes to ignore when searching for candidates.
|
||||
Typically, these modes don't use the text representation.")
|
||||
Typically, these modes don't use the text representation."
|
||||
:type 'list)
|
||||
|
||||
(defvar avy-ring (make-ring 20)
|
||||
"Hold the window and point history.")
|
||||
@ -352,12 +353,15 @@ KEYS is the path from the root of `avy-tree' to LEAF."
|
||||
(defun avy-handler-default (char)
|
||||
"The default handler for a bad CHAR."
|
||||
(let (dispatch)
|
||||
(if (setq dispatch (assoc char avy-dispatch-alist))
|
||||
(progn
|
||||
(setq avy-action (cdr dispatch))
|
||||
(throw 'done 'restart))
|
||||
(signal 'user-error (list "No such candidate" char))
|
||||
(throw 'done nil))))
|
||||
(cond ((setq dispatch (assoc char avy-dispatch-alist))
|
||||
(setq avy-action (cdr dispatch))
|
||||
(throw 'done 'restart))
|
||||
((memq char '(27 ?\C-g))
|
||||
;; exit silently
|
||||
(throw 'done 'exit))
|
||||
(t
|
||||
(signal 'user-error (list "No such candidate" char))
|
||||
(throw 'done nil)))))
|
||||
|
||||
(defvar avy-handler-function 'avy-handler-default
|
||||
"A function to call for a bad `read-key' in `avy-read'.")
|
||||
@ -1090,11 +1094,12 @@ Otherwise, forward to `goto-line' with ARG."
|
||||
(goto-char (point-min))
|
||||
(forward-line (1- arg)))
|
||||
(avy-with avy-goto-line
|
||||
(let* ((avy-handler-function
|
||||
(let* ((avy-handler-old avy-handler-function)
|
||||
(avy-handler-function
|
||||
(lambda (char)
|
||||
(if (or (< char ?0)
|
||||
(> char ?9))
|
||||
(avy-handler-default char)
|
||||
(funcall avy-handler-old char)
|
||||
(let ((line (read-from-minibuffer
|
||||
"Goto line: " (string char))))
|
||||
(when line
|
||||
@ -1223,7 +1228,8 @@ The window scope is determined by `avy-all-windows' or
|
||||
'(define-key isearch-mode-map (kbd "C-'") 'avy-isearch)))
|
||||
|
||||
(defcustom avy-timeout-seconds 0.5
|
||||
"How many seconds to wait for the second char.")
|
||||
"How many seconds to wait for the second char."
|
||||
:type 'float)
|
||||
|
||||
(defun avy--read-candidates ()
|
||||
"Read as many chars as possible and return their occurences.
|
||||
|
Loading…
x
Reference in New Issue
Block a user