binding to "cp" without breaking "c"
Frank Fischer
frank-fischer at shadow-soft.de
Wed Jul 2 20:41:58 CEST 2014
Am 19.06.2014 04:12, schrieb Stefan Monnier:
> Not sure how ugly it would end up, indeed.
>
> But you could very well handle it with something like:
>
> (define-key map "c" operator-arg-map)
> (defvar operator-arg-map
> (let ((map (make-sparse-keymap)))
> (dotimes (i 10)
> (define-key map (vector (+ i ?0)) map))
> (define-key map [?w] 'my-command)
> map))
>
> (defun my-command (keys)
> (interactive (list (this-single-command-keys)))
> ... analyze keys to extract the count and the motion...
> ...)
>
> It would probably introduce other changes to the behavior that you
> didn't intend, and such "recursive maps" are sufficiently rare that you
> might bump into Emacs bugs, so yes... not necessarily a good idea.
Another idea would be to multiplex operators (they are defined via
`evil-define-operator` anyway, so this should not be a problem).
If an operator is called (interactively), it does not execute its body
but simply activates a new minor mode (i.e., operator-state) in which
other keymaps are active (and possibly some prefix specific ones, e.g.,
one that is only active if the invoking key-sequence has been "c"). If
some (motion) command is executed in that state, the operator's body is
finally called with the range defined by the motion. If the command to
be called in operator-state is one in the special keymap, then that
command is executed normally and the body of the operator is not.
(the special keymap could be built automatically if the bindings are
defined via `evil-define-key`).
But again, this requires some work and I'm not sure if it pays of.
Best regards,
Frank
More information about the implementations-list
mailing list