* Getting functions into define-key...
@ 2003-09-29 12:59 Norman Walsh
2003-09-29 22:21 ` Kevin Rodgers
0 siblings, 1 reply; 2+ messages in thread
From: Norman Walsh @ 2003-09-29 12:59 UTC (permalink / raw)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I'm guessing there must be some way to do this other than brute force.
I have an alist:
(defvar my-alist
'(("choice1" . "opt1")
("choice2" . 35)
("choice3" . "opt3")))
I want to make a menu-bar menu that contains choice1, choice2, choice3.
If choice1 is selected, I want to evaluate (my-function "opt1"),
If choice2 is selected, I want to evaluate (my-function 35), etc.
I can see a brute-force solution:
(defun my-function-opt1 ()
(interactive)
(my-function "opt1"))
(define-key menu-bar-my-menu [my-choice1]
'("choice1" . my-function-opt1))
But it seems to me that it should be possible to build the menu bar
from the alist. Alas, it's just beyond my elisp skills.
Clues, please?
Be seeing you,
norm
- --
Norman Walsh <ndw@nwalsh.com> | Design and programming are human
http://nwalsh.com/ | activities; forget that and all is
| lost.--B. Stroustrup
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
iD8DBQE/eCylOyltUcwYWjsRAuaLAKCE1rUhSBghvetIfOhSGMAgvrUjuACfR1MK
m4eG4w1CZC2jpPYB1kji4s0=
=pLtC
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Getting functions into define-key...
2003-09-29 12:59 Getting functions into define-key Norman Walsh
@ 2003-09-29 22:21 ` Kevin Rodgers
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Rodgers @ 2003-09-29 22:21 UTC (permalink / raw)
Norman Walsh wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I'm guessing there must be some way to do this other than brute force.
>
> I have an alist:
>
> (defvar my-alist
> '(("choice1" . "opt1")
> ("choice2" . 35)
> ("choice3" . "opt3")))
>
> I want to make a menu-bar menu that contains choice1, choice2, choice3.
> If choice1 is selected, I want to evaluate (my-function "opt1"),
> If choice2 is selected, I want to evaluate (my-function 35), etc.
>
> I can see a brute-force solution:
>
> (defun my-function-opt1 ()
> (interactive)
> (my-function "opt1"))
>
> (define-key menu-bar-my-menu [my-choice1]
> '("choice1" . my-function-opt1))
>
> But it seems to me that it should be possible to build the menu bar
> from the alist. Alas, it's just beyond my elisp skills.
Here's how to handle ("choice1" . "opt1"):
(define-key menu-bar-my-menu [my-choice1]
'("choice1" . (lambda () (interactive) (my-function "opt1"))))
So given my-alist:
(let ((alist my-alist)
choice
option)
(while alist
(setq choice (car (car alist)) ; string
option (cadr (car alist))) ; constant (self-evaluating)
(define-key menu-bar-my-menu (vector (intern choice))
`(,choice . (lambda () (interactive) (my-function ,option))))
(setq alist (cdr alist))))
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-09-29 22:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-29 12:59 Getting functions into define-key Norman Walsh
2003-09-29 22:21 ` Kevin Rodgers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).