help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: From menu button, how run more than one command?


From: Mathias Dahl
Subject: Re: From menu button, how run more than one command?
Date: Mon, 27 Feb 2006 14:35:54 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt)

RD <rjjd@localnet.com> writes:

> The code below works, but note that the menu button calls function
> "abc".  If the menu contains many buttons, each button would need a
> dedicated function.
>
> (defvar my-menu (make-sparse-keymap))
>
> (define-key my-menu [rmx]
>    '(menu-item "FILE" abc))      ;executes function abc
>
> (defun abc ()
>    (interactive)
>    (cd "C:/emacs")
>    (call-interactively 'find-file)
> )
>
> Is there a way to write the "define-key" so that I don't need a separate
> function?
> Or, is there a way to pass an argument from "menu-item" to the function?

Luckily for you I struggled too with menus last week. Would something
like this work for you?

(defvar my-menu (make-sparse-keymap))

(define-key my-menu [rmx1]
   `(menu-item "Find file on c:/" 
               ,(lambda () 
                  (interactive) 
                  (abc "c:/"))))

(define-key my-menu [rmx2]
   `(menu-item "Find file on h:/" 
               ,(lambda () 
                  (interactive) 
                  (abc "h:/"))))

(defun abc (path)
   (cd path)
   (call-interactively 'find-file))

;; Test it

(popup-menu my-menu)

/Mathias


reply via email to

[Prev in Thread] Current Thread [Next in Thread]