[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to convert a char to a property
From: |
Pascal J. Bourguignon |
Subject: |
Re: How to convert a char to a property |
Date: |
Wed, 08 Dec 2010 15:21:21 -0000 |
User-agent: |
Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux) |
Cecil Westerhof <Cecil@decebal.nl> 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/