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: How to convert a char to a property Date: Tue, 27 Jul 2010 19:59:28 +0200 Organization: Informatimago Message-ID: <87sk34iz5r.fsf@kuiper.lan.informatimago.com> References: <87sk358gzw.fsf@decebal.nl> <87fwz583m9.fsf@decebal.nl> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1291850674 7951 80.91.229.12 (8 Dec 2010 23:24:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Dec 2010 23:24:34 +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 00:24:30 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 1PQTN7-0000xc-Mp for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 00:24:30 +0100 Original-Received: from localhost ([127.0.0.1]:55779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQTLR-0000zu-2h for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 18:22:45 -0500 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 69 Original-X-Trace: individual.net bBh6/3JmxeSapX4kWDkSOgaNllsFudUFQzxj5LHBv1UeFB2If8 Cancel-Lock: sha1:YWVjZjUwN2JmY2VmNGQxOTVjZjUxODQzNDBmMjBlYWMyOWI2ODM0Mw== sha1:dd8LtG6iVapRGb50SHv9eu3LRUA= 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:180121 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:76208 Archived-At: Cecil Westerhof writes: > Op dinsdag 27 jul 2010 10:29 CEST schreef Cecil Westerhof: > >> I have the following property list: >> (defvar dcbl-bbdb-user-defined-fields (list :L "mail-alias" >> :M "mailer" >> :P "playlist" >> :s "subjects" >> :t "type" >> :w "website") >> "User defined fields in the bbdb with parameter to insert into buffer") >> >> With (getf dcbl-bbdb-user-defined-fields :M) I get "mailer". >> >> But I want to work parameter driven. So for example I have: >> (setq parameters "MLst") >> (setq current-char (string-to-char parameters)) >> >> The variable current-char now contains 77. How could I use >> current-char to retrieve "mailer"? > > At the moment I use another solution. > > I now have: > (defvar dcbl-bbdb-user-defined-fields '(("L" "mail-alias") > ("M" "mailer") > ("P" "playlist") > ("s" "subjects") > ("t" "type") > ("w" "website")) > "User defined fields in the bbdb with parameter to insert into buffer") > > and use the following code: > (setq field-name nil > parameters dcbl-bbdb-user-defined-fields > this-value nil) > (while parameters > (setq this-parameter (car parameters) > parameters (cdr parameters)) > (when (string= current-char (car this-parameter)) > (setq field-name (car (cdr this-parameter)) > parameters nil))) > > The variable current-char is the parameter (as a string) that I am > searching for. > > This does work, but I do not know if it is very efficient. Is this a > good solution, or should I code it differently? If you have characters and want to map them, why do you make a table mapping keywords or strings? Make a table mapping characters! (defvar dcbl-bbdb-user-defined-fields '((?L . "mail-alias") (?M . "mailer") (?P . "playlist") (?s . "subjects") (?t . "type") (?w . "website")) "An a-list of User defined fields in the bbdb with parameter to insert into buffer") (defun get-field-name-from-character (ch) (cdr (assoc ch dcbl-bbdb-user-defined-fields))) -- __Pascal Bourguignon__ http://www.informatimago.com/