Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting key-sequence vector into user readable string representation?

How can I convert an emacs keysequence vector (ie the result of read-key-sequence-vector) into a user readable string? I.e., given [7], return 'C-g'.

I need a reliable way of checking for equality among key sequences of arbitrary length, as well as of displaying the key sequences in a non-vector format (ie human-readable).

For detail, my function must do the following:

  • Define a hashmap of keysequences to values (strings). The keysequences have arbitrary lengths (for example, "q" "w" 3" "4"), and are not bounded by emacs' keymaps.
  • Display the mappings (keysequence --> string) to the user in a buffer. Therefore, the keysequences must be intelligible by the user, ie can not be in vector format.
  • Read a keysequence from the user, return the appropriate string.

There are two functions I can use, read-key-sequence and read-key-sequence-vector. The former returns sometimes as string, sometimes as vector, the user's typed keysequence. For example, sometimes it returns "1", but sometimes, [49], for the key 'one'. This unpredictable behavior does not allow me to test for equality.

The latter returns the keys as a vector, which as I mentioned is not useful to me because I need the user to see the possible keysequences.

I suppose I can manually create a hasmap of all keys on my current machine's keyboard. But I am afraid this is not portable to other machines.

like image 484
ealfonso Avatar asked Feb 26 '13 12:02

ealfonso


1 Answers

(key-description [7]) => "C-g"
like image 84
huaiyuan Avatar answered Nov 20 '22 21:11

huaiyuan