[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ELISP] How do you turn an array of chars into a string?
From: |
Pascal J. Bourguignon |
Subject: |
Re: [ELISP] How do you turn an array of chars into a string? |
Date: |
Wed, 08 Dec 2010 15:22:15 -0000 |
User-agent: |
Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux) |
Joseph Brenner <doom@kzsu.stanford.edu> writes:
> The elisp manual has this example, using "kbd" to convert a (relatively)
> readable string into the "internal Emacs key representation":
>
> (global-set-key (kbd "C-x C-\\") 'next-line)
>
> (global-set-key [?\C-x ?\C-\\] 'next-line)
>
> What's the inverse of kbd?
> What if you want to convert an array-of-chars
> into a string?
These are two radically different things.
The inverse of kbd doesn't convert an array of characters into a
string, it would produce a string containing a text describing in a
human readable form the keychoard sequence.
So what do you really want?
To convert a vector of characters to a string you could use:
(require 'cl) ; all the good stuff is always in there!
(coerce [?c ?a ?t] 'string) --> "cat"
(concatenate 'string "A " [?c ?a ?t] '(? ?e ?a ?t ?s) " a mouse.")
--> "A cat eats a mouse."
To convert a vector of key chords into a human readable description of
it, I don't know. But the command where-is seems to be knowing how to
do it, so let's read the source of where-is! Here, we find a:
(mapconcat 'key-description keys ", ") therefore key-description might
be the right function. Read the documentation. Yes! Notice how it
says nothing about converting vectors to string!!!
(key-description (kbd "C-x C-\\"))
--> "C-x C-\\"
(key-description (kbd "C-M-A-s-Z C-u 123 H-S-A-é"))
--> "A-C-M-s-z C-u 1 2 3 A-H-S-é"
Looks good...
> Things like this seem to work, but only for very simple chars:
>
> (mapconcat 'string [?c ?a ?t] "") ;; => "cat"
What is a non-simple character???
--
__Pascal Bourguignon__ http://www.informatimago.com/