|
From: | Kevin Rodgers |
Subject: | Re: Getting functions into define-key... |
Date: | Mon, 29 Sep 2003 16:21:56 -0600 |
User-agent: | Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2 |
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
[Prev in Thread] | Current Thread | [Next in Thread] |