From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: [ELISP] How do you turn an array of chars into a string? Date: Sun, 01 Aug 2010 23:52:12 +0200 Organization: Informatimago Message-ID: <87aap6f1bn.fsf@kuiper.lan.informatimago.com> References: <87wrsae07o.fsf@kzsu.stanford.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1291856223 29896 80.91.229.12 (9 Dec 2010 00:57:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 00:57:03 +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:56:59 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 1PQUob-0008Ng-QT for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 01:56:57 +0100 Original-Received: from localhost ([127.0.0.1]:52857 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQUob-0003Yz-BY for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 19:56:57 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 60 Original-X-Trace: individual.net pCDn5OdhA8VLLqeJT372QwDu9JJ33STZIQc1dO56rQk8ncX890 Cancel-Lock: sha1:MDBiZjYwYTk4NWZlODRiYTRjYzkyNDVmMDY1MWNiNDBmMzY3OGE5MA== sha1:8UIY3sJDW9e1wZfrZCu6Roqs+Js= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:180262 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:76336 Archived-At: 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. 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/