So when executing key chords , emacs waits indefinitely.
However i want to bind SPC y to copy current selection and SPC yy to copy current line, how would i go about binding the keys like this?
(map!
:leader
:nv
:desc "Copy line to system clipboard" "yy" #'copy-current-line-to-clipboard)
dosen’t work as y is not a prefix key
I don’t think there is a solution to this so im using SPC Y instead but if there is a way around this i would love to know
It’s not a general solution, and might not be correct code but it seems to work for me.
The core part is that we make a command that reads the next input with a timeout (0.5 seconds here),
and if that input is the y key it runs copy-current-line-to-clipboard (the function you try to bind in your post).
If there was no input, we copy the current selection, and if there was input other than “y”, we still copy the selection, but then set unread-command-events to tell Emacs to execute that input.
Problems:
this-command-keys may not be set when executing the next key (may be avoidable by setting unread-command-events to something like (t . next-key) but I didn’t feel certain how)
everything being called-interactively is a probably kludge
during the 0.5s timeout period timers won’t run (Emacs is considered non-idle)
out of curiosity, what’s the motivation for binding copying under leader anyway?
edit: I would also like to note that binding “SPC yy” actually involves binding “SPC y”, to a keymap. This is part of why you can’t bind a prefix to a function. So the only thing you can do is bind it to something that sets a keymap (and a timer for a delay), or kinda “emulates” a keymap like above.