Open nameiwillforget opened 5 months ago
I managed to simplify the functions a bit by using the local mark ring to remember the initial positions:
(defun avy-act-by-same-function (x y)
"This function asks for a command and an avy function as chosen
using the avy-function-map, then uses the chosen avy function twice to
select an interval and apply the input command to it. Through this
method, simple editing of areas on the screen can be done without
having to move point. If you delete an area surrounding point, have
the first selected position be before the second one."
(interactive "kCommand: \nkAvy function: ")
(call-interactively (lookup-key avy-function-map y))
(call-interactively #'set-mark-command)
(call-interactively (lookup-key avy-function-map y))
(call-interactively (lookup-key (make-composed-keymap (current-active-maps t)) x))
(call-interactively #'pop-to-mark-command)
(call-interactively #'pop-to-mark-command)
)
(defun avy-act-by-different-functions (x y z)
"This function asks for a command and two avy functions as chosen
using the avy-function-map, then uses the chosen avy functions to
select an interval and apply the input command to it. Through this
method, simple editing of areas on the screen can be done without
having to move point. If you delete an area surrounding point, have
the first selected position be before the second one."
(interactive "kCommand: \nkFirst avy function: \nkSecond avy function: ")
(call-interactively (lookup-key avy-function-map y))
(call-interactively #'set-mark-command)
(call-interactively (lookup-key avy-function-map z))
(call-interactively (lookup-key (make-composed-keymap (current-active-maps t)) x))
(call-interactively #'pop-to-mark-command)
(call-interactively #'pop-to-mark-command)
)
(defun avy-act-to-point (x y)
"This function asks for a command and an avy function as chosen
using the avy-function-map, then uses the chosen avy function to
select the interval between the current position of point and the
position chosen through avy, and then apply the input command to it.
Through this method, simple editing of areas before or after point can
be done without having to move point."
(interactive "kCommand: \nkAvy function: ")
(call-interactively #'set-mark-command)
(call-interactively (lookup-key avy-function-map y))
(call-interactively (lookup-key (make-composed-keymap (current-active-maps t)) x))
(call-interactively #'pop-to-mark-command)
)
Edit: I just simplified the names a bit.
I've written some functions that I think have the potential to be very useful and that I thought could be incorporated:
When I tested them they worked but seemed to stress the CPU to a surprising degree. I looked a bit into the internals of avy and thought the code could simplify by introducing variants of the avy command that use the
action
-argument ofavy-jump
to print out a position, likeHowever, when I tried to use this function in a simplification of
avy-select-by-same-function-and-apply
like thiswhere
(call-interactively (lookup-key avy-function-map y))
is used to chooseavy-position-by-word-1
in theavy-function-map
to define the position ofbgn
andend
, I receive the errorAnd at that point I'm not sure what to do anymore. In any case, the functions as I gave them above work and I think are extremely convenient: instead of jumping to a position, activating the mark, then jumping to another, applying some command to the selected region, just stay at the initial position, use avy to select an interval and apply a command to it through a keybind in your current keymaps! The many
if
s andlet
s in the commands I wrote are mostly to ensure point lands in the right position if some text is deleted before point.