0

I'd like to use avy by writing a command that does the following: first, it should ask for a key combination. Then it should call interactively, say, avy-goto-line to select a position, where it sets the mark. Then it should call avy-goto-line again to jump to another position, marking the interval between the mark and the new position of point. Then it should apply the command corresponding to the key sequence at the beginning to the selected region. So something like

(defun test (x)
  "Test function"
  (interactive (list (read-key-sequence-vector "Command: ")))
  ;; (call-interactively #'avy-goto-line)
  ;; (call-interactively #'set-mark-command)
  ;; (call-interactively #'avy-goto-line)
  (call-interactively (keymap-lookup global-map x)))

However, if I evaluate that function I get the error

keymap--check: [20] is not a valid key definition; see ‘key-valid-p’

I also tried using read-key-sequence and read-event but neither worked, even though read-event returned a string. I checked key-valid-p but it didn't say how to convert the output of those read-commands into a form that is valid for it, and the Emacs manual said all other keymap commands use keymap-lookup. Furthermore, a lot of my keys are only representable as vectors. Is there some way I can convert the data into a form suitable for keymap-lookup or similar?

1
  • 1
    Maybe an X-Y question? What are you really trying to do?
    – Drew
    Feb 3 at 4:48

1 Answer 1

1

Note that interactive provides options for entering a key sequence:

k -- Key sequence (downcase the last event if needed to get a definition).
K -- Key sequence to be redefined (do not downcase the last event).
(defun foo (x)
  (interactive "kCommand: ")
  (message "%S" x))

(defun bar (x)
  (interactive "KCommand: ")
  (message "%S" x))

;; These are all equivalent:

(lookup-key (current-global-map) [20])
(lookup-key (current-global-map) "^T") ;; type: C-q C-t
(keymap-lookup (current-global-map) "C-t")

keymap-lookup takes the same syntax as kbd.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.