1

Given that the variable x contains the numeric representation of the key "Control-Z", say

(setq x ?\C-z), 

one may graphically represent its contents by issuing the command

(char-to-string x), 

producing the usual representation of "Control-Z", namely "^Z". I would like to acheive a similar effect in case x contained the numeric representation of "Meta-Z", namely

(setq x ?\M-z).

However my system represents "Meta-Z" as the number 134217850, and (char-to-string x) now causes the error (wrong-type-argument characterp 134217850). I am aware that the graphical representation of "Meta-Z" is not as standard as for "Control-Z", since the latter is part of the ASCII code while the former isn't, but anything legible, such as "M-Z" would be better than the big number 134217850.

My question is thus: which standard elisp function should I use in order to transform numerical representations of Meta characters into a legible string?

2
  • 1
    You could try (key-description [?\M-z]) (but it has to be a vector, not a single number).
    – wvxvw
    Commented Nov 5, 2017 at 13:43
  • @wvxvw, thanks very much! Should you decide to turn your comment into an answer, I'd be glad to accept it!
    – Ruy
    Commented Nov 5, 2017 at 17:27

1 Answer 1

0

Properly speaking, ?\C-z is the read syntax of the character. Internally, the Lisp object is an integer. Nonetheless, characters in strings may have different character codes [2]. In other words, a similar read syntax does not necessarily produce the same Lisp object.

You can see in the following example that the character codes are different: 134217818 and 218.

ELISP> ?\M-Z
134217818
ELISP> "\M-Z"
"\332"
ELISP> ?\332
218

Characters inserted in text must be in the range of 0 to 4194303. Extra characters, typed using modifier keys, are used to represent keyboard inputs. [1]

In summary, you cannot use a string (read syntax) to represent a meta character. For a conversion function, look at [3].

(single-key-description ?\M-z)

References

1
  • Thanks a lot! Based on your answered, specifically [3], I found exactly what I was looking for: (single-key-description 134217850)
    – Ruy
    Commented Mar 9, 2020 at 0:28

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.