From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joseph Brenner Newsgroups: gmane.emacs.help Subject: Re: [ELISP] How do you turn an array of chars into a string? Date: Sun, 01 Aug 2010 16:07:32 -0700 Message-ID: <878w4qdj9n.fsf@kzsu.stanford.edu> References: <87wrsae07o.fsf@kzsu.stanford.edu> <87aap6f1bn.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1291856393 30464 80.91.229.12 (9 Dec 2010 00:59:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 00:59:53 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 09 01:59:49 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQUrM-0001JO-PW for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 01:59:48 +0100 Original-Received: from localhost ([127.0.0.1]:40778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQUrM-0004vp-2p for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 19:59:48 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.rawbandwidth!news.posted.rawbandwidth.POSTED!not-for-mail Original-NNTP-Posting-Date: Sun, 01 Aug 2010 18:06:19 -0500 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:RsnJlQcKEBZ5zDHsoeaorYW6Np8= Original-Lines: 70 X-Usenet-Provider: http://www.giganews.com Original-NNTP-Posting-Host: 198.144.208.84 Original-X-Trace: sv3-i5MdMqh0oZE+i5Nj2luXwWtpoMdKKP8fZ+HJTflqgoJqii+bZGSSeHbxcLHk1aQvnsF08NNeWdyKGXq!N4I0oTbjFqOGtz7r2RUVu6oYjWK5jfQ2BlWEZUIl4/L2ujVWwK9ReH1XfooP1M5WzzuLyXYwt4I= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Original-Xref: usenet.stanford.edu gnu.emacs.help:180264 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:76340 Archived-At: pjb@informatimago.com (Pascal J. Bourguignon) writes: > Joseph Brenner 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. Which is indeed, a kind of string, and from context, I would hope it's clear that that's the kind of string I was talking about. > 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." Yes, looks good, but then I'd figured out ways to do that sort of job... >> Things like this seem to work, but only for very simple chars: >> >> (mapconcat 'string [?c ?a ?t] "") ;; => "cat" > > What is a non-simple character??? Well, for example, it doesn't work for: (control ?c) But then it does work for: ?\C-c SO it could be I was wrong. > 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... Yes, thanks much. That does indeed look like the solution.