From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: How to convert a char to a property
Date: Tue, 27 Jul 2010 19:59:28 +0200 [thread overview]
Message-ID: <87sk34iz5r.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: 87fwz583m9.fsf@decebal.nl
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/
next prev parent reply other threads:[~2010-07-27 17:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-27 8:29 How to convert a char to a property Cecil Westerhof
2010-07-27 12:12 ` TheFlyingDutchman
2010-07-27 22:06 ` Cecil Westerhof
2010-07-27 13:18 ` Cecil Westerhof
2010-07-27 17:59 ` Pascal J. Bourguignon [this message]
2010-07-27 22:11 ` Cecil Westerhof
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sk34iz5r.fsf@kuiper.lan.informatimago.com \
--to=pjb@informatimago.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.