hlissner/evil-snipe

How binding keys with evil-snipe

ReneFroger opened this issue · 4 comments

I would like to bind the keys f and <F9>, without affecting the other Evil operations.
So I have the following snippet in my configuration:

(define-key evil-normal-state-map (kbd "f <f9>") 'foobar)

So I press f and F9, then foobar will be called.
However, now I'm facing another problem. The f-key is not functioning anymore for other Evil operations. It works only for ff9 and not for finding character a with fa.
To circumvent this, I use the following workaround.

(defun my-evil-find-char (arg char)
    (interactive (list (prefix-numeric-value current-prefix-arg) (read-key)))
    (cond
    ((characterp char)
        (evil-find-char arg char))
    ((eq char 'f9)
        (foobar))
    (t
        (user-error "Unknown key combination"))))

(define-key evil-motion-state-map (kbd "f") 'my-evil-find-char)

So if there is no f9 key passed, he will pass the other characters to f.
This works so far. However, with Evil Snipe I'm facing an another issue. When pressing fF9, I got the following error:

evil-snipe--process-key: Wrong type argument: stringp, f9

Any suggestion to work around this?

This modified my-evil-find-char would do the trick:

(defun my-evil-find-char (arg char)
    (interactive (list (prefix-numeric-value current-prefix-arg) (read-key)))
    (cond
    ((characterp char)
        (evil-snipe-f arg (list (evil-snipe--process-key char)))
    ((eq char 'f9)
        (foobar))
    (t
        (user-error "Unknown key combination"))))

(define-key evil-motion-state-map (kbd "f") 'my-evil-find-char)

Unfortunately, there is no simple fix to this problem. It has several causes and evil-snipe is not one of them. To bind f and fF9 separately, you would have to do:

(defvar f-key-map (make-sparse-keymap))
(define-key evil-motion-state-map (kbd "f") 'f-key-map)
(define-key f-key-map (kbd "<F9>") 'foobar)
;; define all other keys and pass them to evil-snipe?

At least, that's all I could come up with.

Hmmz, when pasting both codes in my dot-emacs, I couldn't get it working. Are you sure it worked in your setup? Note that the function my-evil-find-char have unbalanced parentheses.

Agh, sorry, I completely missed your reply! I fixed the unbalanced parens and it works for me:

(defun my-evil-find-char (arg char)
    (interactive (list (prefix-numeric-value current-prefix-arg) (read-key)))
    (cond ((characterp char)
           (evil-snipe-f arg (list (evil-snipe--process-key char))))
           ((eq char 'f9)
            (foobar))
           (t
            (user-error "Unknown key combination"))))

(define-key evil-motion-state-map (kbd "f") 'my-evil-find-char)

If it still doesn't work, are you sure this code is running after evil-snipe is loaded?

I got it right after restarting Emacs, I forgot to mentioned it earlier. Thanks for your help!