(setf (alist-get ?w avy-dispatch-alist) | |
#'my/avy-evil-delete) | |
(setf (alist-get ?y avy-dispatch-alist) | |
#'my/avy-evil-copy) | |
(setf (alist-get ?c avy-dispatch-alist) | |
#'my/avy-evil-change) | |
(setf (alist-get ?a avy-dispatch-alist) | |
#'my/avy-embark-act) | |
(defun my/avy-embark-act (pt) | |
(unwind-protect | |
(save-excursion | |
(goto-char pt) | |
(embark-act)) | |
(select-window | |
(cdr | |
(ring-ref avy-ring 0)))) | |
t) | |
(defvar my/evil-extract-count-keys nil) | |
(defun my/evil-extract-count (orig-fn keys) | |
"When an evil operation is called from avy `evil-extract-count' | |
will get the last key given to avy as input. In order to behave | |
normally we wrap the function so that we can give the input | |
manually using a let-binding." | |
(funcall orig-fn | |
(or my/evil-extract-count-keys keys))) | |
(advice-add #'evil-extract-count | |
:around #'my/evil-extract-count) | |
(defun my/avy-evil-delete (pt) | |
(interactive) | |
(save-excursion | |
(goto-char pt) | |
(let ((my/evil-extract-count-keys "d")) | |
(call-interactively #'evil-delete))) | |
(select-window | |
(cdr | |
(ring-ref avy-ring 0))) | |
t) | |
(defun my/avy-evil-copy (pt) | |
(interactive) | |
(save-excursion | |
(goto-char pt) | |
(let ((my/evil-extract-count-keys "y")) | |
(call-interactively #'evil-yank))) | |
(select-window | |
(cdr | |
(ring-ref avy-ring 0))) | |
t) | |
(defvar my/avy-evil-change-marker nil | |
"The place where the user called ivy from.") | |
(defun my/avy-evil-change (pt) | |
(interactive) | |
(setq my/avy-evil-change-marker (point-marker)) | |
(goto-char pt) | |
(add-hook 'evil-insert-state-exit-hook #'my/avy-evil-change-h) | |
(call-interactively #'evil-change) | |
t) | |
(defun my/avy-evil-change-h () | |
(remove-hook 'evil-insert-state-exit-hook #'my/avy-evil-change-h) | |
(select-window | |
(cdr | |
(ring-ref avy-ring 0))) | |
(goto-char (marker-position my/avy-evil-change-marker))) |
@agenbite I'm not quite sure what you mean. What avy command are you using this with? I'm using evil-avy-goto-char-timer
to do an evil operation from an arbitrary point on the screen.
I'm sorry. I believe I'm not understanding the difference between using evil and then avy or using avy and then evil.
In principle, I see two ways to use avy and evil together: a) call an evil action and then call avy to select the (end of) the motion to which the action is to be applied (starting at point); b) call avy to select a word elsewhere in the buffer and then select from the dispatcher one of the evil options you created, which will wait for a motion and will apply it as if the point was at the selected word, while staying where it first was.
In a), I would, for example, be wanting to delete some words ahead, but be too lazy to count them. Then avy would come to the rescue and help me tell evil the motion I want to perform the action on. In b), I'd want to copy N words from elsewhere in the frame, so I'd call avy to fix the start of my words and then use evil to yank those N words.
I guess the intended behaviour of your code is b), right?
Thank you!!
Yeah exactly, my code implements b) and has nothing to do with a). With that said, I tried (using Doom Emacs) to do a) which seems to work. It will delete up until the the character I selected with avy (similar to how t
works with vim).
Cool, thanks for the help! :) Your code works beautifully for b).
And regarding a), it bothers me that, in my case, it deletes not "up until" the caracter selected with avy, (as with t
), but more as with f
: it deletes up until that character and that character. It's not that important, in either case.
Cheers!
Thanks to your help, I've settled down with this config for myself.
It's confusing how avy calls "yank" to yank-and-put and "copy" to yank.
This is great, thank you!!
There's one thing that I don't get, though: when using avy with evil, for example to delete up to certain characters, the delete operation "bites" on the first of the hinted chars... Wouldn't it be better to stop just before these selected chars? I've tried to make sense of your code, but I'm still not that fluent in elisp... :)