branch: master
commit 035d663ab412c0e3f3df22581a5f864b2df30b59
Author: York Zhao <[email protected]>
Commit: Oleh Krehel <[email protected]>
Add `avy-translate-char-function' to translate user input key
This can be useful for adding mirror key. For example, one can make SPACE an
alternative of 'a', by adding:
(setq avy-translate-char-function
(lambda (c) (if (= c 32) ?a c)))
to allow typing SPACE instead of character 'a' to jump to the location
highlighted by 'a'.
Fixes #59
---
avy.el | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/avy.el b/avy.el
index 427378d..9b7e00b 100644
--- a/avy.el
+++ b/avy.el
@@ -134,6 +134,17 @@ When nil, punctuation chars will not be matched.
"List of modes to ignore when searching for candidates.
Typically, these modes don't use the text representation.")
+(defvar avy-translate-char-function #'identity
+ "Function to translate user input key. This can be useful for
+adding mirror key. E.g. one can make SPACE an alternative of 'a',
+by adding:
+
+\(setq avy-translate-char-function
+ (lambda (c) (if (= c 32) ?a c)))
+
+to allow typing SPACE instead of character 'a' to jump to the location
+highlighted by 'a'.")
+
(defface avy-lead-face-0
'((t (:foreground "white" :background "#4f57f9")))
"Face used for first non-terminating leading chars.")
@@ -319,7 +330,7 @@ multiple DISPLAY-FN invokations."
(push (cons path leaf) avy--leafs)))
(dolist (x avy--leafs)
(funcall display-fn (car x) (cdr x))))
- (let ((char (read-char))
+ (let ((char (funcall avy-translate-char-function (read-char)))
branch)
(funcall cleanup-fn)
(if (setq branch (assoc char tree))
@@ -348,7 +359,7 @@ multiple DISPLAY-FN invokations."
(while (< i len)
(dolist (x (reverse alist))
(avy--overlay-at-full (reverse (car x)) (cdr x)))
- (let ((char (read-char)))
+ (let ((char (funcall avy-translate-char-function (read-char))))
(avy--remove-leading-chars)
(setq alist
(delq nil