* From menu button, how run more than one command?
@ 2006-02-25 3:07 RD
2006-02-27 13:35 ` Mathias Dahl
2006-03-01 4:47 ` Eli Zaretskii
0 siblings, 2 replies; 7+ messages in thread
From: RD @ 2006-02-25 3:07 UTC (permalink / raw)
I want to have a menu whose buttons each executes more than one command,
something like this:
(cd "c:/blah/")
(call-interactively 'find-file) ;open the Find File window.
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?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: From menu button, how run more than one command?
2006-02-25 3:07 From menu button, how run more than one command? RD
@ 2006-02-27 13:35 ` Mathias Dahl
2006-03-01 18:51 ` Kevin Rodgers
[not found] ` <mailman.166.1141291544.2835.help-gnu-emacs@gnu.org>
2006-03-01 4:47 ` Eli Zaretskii
1 sibling, 2 replies; 7+ messages in thread
From: Mathias Dahl @ 2006-02-27 13:35 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: From menu button, how run more than one command?
2006-02-27 13:35 ` Mathias Dahl
@ 2006-03-01 18:51 ` Kevin Rodgers
[not found] ` <mailman.166.1141291544.2835.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2006-03-01 18:51 UTC (permalink / raw)
Mathias Dahl wrote:
> 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)
(lambda ...) is a self-evaluating form, so the backquote/comma syntax is
completely extraneous and can be replaced with a simple quote:
'(menu-item ...)
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <mailman.166.1141291544.2835.help-gnu-emacs@gnu.org>]
* Re: From menu button, how run more than one command?
[not found] ` <mailman.166.1141291544.2835.help-gnu-emacs@gnu.org>
@ 2006-03-02 10:50 ` Mathias Dahl
2006-03-02 16:01 ` Johan Bockgård
1 sibling, 0 replies; 7+ messages in thread
From: Mathias Dahl @ 2006-03-02 10:50 UTC (permalink / raw)
Kevin Rodgers <ihs_4664@yahoo.com> writes:
> > (define-key my-menu [rmx2]
> > `(menu-item "Find file on h:/"
> > ,(lambda ()
> > (interactive)
> > (abc "h:/"))))
> (lambda ...) is a self-evaluating form, so the backquote/comma syntax is
> completely extraneous and can be replaced with a simple quote:
> '(menu-item ...)
I played a lot with that and the above worked so... :) My elisp is a
bit shaky and sometimes you don't know what you do wrong and what
changes that fixed the problem, so I probably changed some other thing
while adding those "`" and "," which solved the problem.
Anyway, thanks for pointing it out, I will play some more with it.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: From menu button, how run more than one command?
[not found] ` <mailman.166.1141291544.2835.help-gnu-emacs@gnu.org>
2006-03-02 10:50 ` Mathias Dahl
@ 2006-03-02 16:01 ` Johan Bockgård
1 sibling, 0 replies; 7+ messages in thread
From: Johan Bockgård @ 2006-03-02 16:01 UTC (permalink / raw)
Kevin Rodgers <ihs_4664@yahoo.com> writes:
> Mathias Dahl wrote:
>> (defvar my-menu (make-sparse-keymap))
>>
>> (define-key my-menu [rmx1]
>> `(menu-item "Find file on c:/"
>> ,(lambda ()
>> (interactive)
>> (abc "c:/"))))
[...]
> (lambda ...) is a self-evaluating form, so the backquote/comma
> syntax is completely extraneous and can be replaced with a simple
> quote: '(menu-item ...)
Having `lambda' in a non-quoted context has the advantage that the
byte-compiler can process it.
--
Johan Bockgård
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: From menu button, how run more than one command?
2006-02-25 3:07 From menu button, how run more than one command? RD
2006-02-27 13:35 ` Mathias Dahl
@ 2006-03-01 4:47 ` Eli Zaretskii
1 sibling, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2006-03-01 4:47 UTC (permalink / raw)
> From: RD <rjjd@localnet.com>
> Date: Fri, 24 Feb 2006 22:07:21 -0500
>
> (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?
Yes, use `lambda' (a.k.a. anonymous functions).
^ permalink raw reply [flat|nested] 7+ messages in thread
* From menu button, how run more than one command?
@ 2006-02-24 22:53 DiGrazia
0 siblings, 0 replies; 7+ messages in thread
From: DiGrazia @ 2006-02-24 22:53 UTC (permalink / raw)
I want to have a menu whose buttons each executes something like this:
(cd "c:/blah/")
(find-file) ;Do not specify file; instead, open the Find File window.
That is, I want each button to run "cd" and then "find-file" interactively.
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 a function?
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-03-02 16:01 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-25 3:07 From menu button, how run more than one command? RD
2006-02-27 13:35 ` Mathias Dahl
2006-03-01 18:51 ` Kevin Rodgers
[not found] ` <mailman.166.1141291544.2835.help-gnu-emacs@gnu.org>
2006-03-02 10:50 ` Mathias Dahl
2006-03-02 16:01 ` Johan Bockgård
2006-03-01 4:47 ` Eli Zaretskii
-- strict thread matches above, loose matches on Subject: below --
2006-02-24 22:53 DiGrazia
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).