* Assigning keymaps / menu shorts / changing menu items
@ 2005-04-09 18:11 David Reitter
0 siblings, 0 replies; 4+ messages in thread
From: David Reitter @ 2005-04-09 18:11 UTC (permalink / raw)
I would like to do a couple of global-set-keys for a few basic
functions that appear in the menu bar. However, the new shortcuts don't
appear in the menu items, since they are still assigned (and should
be).
I understand the menu item shortcuts show what's defined first. Is
there a command like global-set-key that would insert the new keymap at
the beginning of the list associated with the function? Here's what I
do:
(global-set-key [(alt v)] 'yank)
'yank has a menu entry in the Edit menu that currently says "Paste
(C-y)".
Also, I would like to change the way the keyboard shortcuts appear in
the menu. Can I redefine a function to do that? What would that be?
Lastly: how do I change a menu item?
I know how to add submenus to a menu with easychange.el, but I couldn't
figure out how to actually change the text of an arbitrary item. Is
that possible?
I've been looking for something like that in various places - maybe
someone here could give me a hint regarding any of these things, I'd be
very grateful.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Assigning keymaps / menu shorts / changing menu items
[not found] <mailman.935.1113068595.2895.help-gnu-emacs@gnu.org>
@ 2005-04-09 19:15 ` Stefan Monnier
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2005-04-09 19:15 UTC (permalink / raw)
> I understand the menu item shortcuts show what's defined first. Is there
> a command like global-set-key that would insert the new keymap at the
> beginning of the list associated with the function? Here's what I do:
> (global-set-key [(alt v)] 'yank)
> 'yank has a menu entry in the Edit menu that currently says "Paste (C-y)".
The shortcuts displayed in the menus try not only to only mention *key*
bindings, but also favor key sequences that can be generated on any
terminal, i.e. ascii chars (maybe combined with the meta modifier). C-y is
an ascii char so it is preferred over A-v.
So if you really want to see A-v in the menu, you need to either somehow
hide the C-y binding, or put the info up there explicitly (using
the :key-sequence parameter in the menu-item).
The first option can be done with something like
(defalias 'hidden-yank 'yank)
(global-set-key [(control y)] 'hidden-yank)
But the second option is preferable since it allows things like C-h f to
still list *all* the bindings.
> Also, I would like to change the way the keyboard shortcuts appear in the
> menu. Can I redefine a function to do that?
IIRC it's key-description and it's written in C. Also it's called directly
from C, so if you redefine it in elisp, Emacs will not everywhere use your
redefined version.
> Lastly: how do I change a menu item?
> I know how to add submenus to a menu with easychange.el, but I couldn't
> figure out how to actually change the text of an arbitrary item. Is
> that possible?
Find the key-sequence corresponding to it with C-h k, then
(define-key [theseysequence] '(menu-item ...)).
See the elisp manual's description of menus and `menu-item' for more info.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Assigning keymaps / menu shorts / changing menu items
@ 2005-04-10 19:40 David Reitter
2005-04-10 20:28 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: David Reitter @ 2005-04-10 19:40 UTC (permalink / raw)
Cc: Help-gnu-emacs
Many thanks for your hints.
> > Lastly: how do I change a menu item?
> > I know how to add submenus to a menu with easychange.el, but I
> couldn't
> > figure out how to actually change the text of an arbitrary item. Is
> > that possible?
>
> Find the key-sequence corresponding to it with C-h k, then
> (define-key [theseysequence] '(menu-item ...)).
> See the elisp manual's description of menus and `menu-item' for more
> info.
OK, but I wouldn't want to contruct a completely new menu-item, I would
just want to exchange the text. Now, when I do something like
(lookup-key global-map [menu-bar file open-file])
all I get is the pure command, 'find-file-existing, in this case - but
not the arguments :enable and :help that were defined in menu-bar.el:
(define-key menu-bar-file-menu [open-file]
'(menu-item "Open File..." find-file-existing
:enable (not (window-minibuffer-p
(frame-selected-window menu-updating-frame)))
:help "Read an existing file into an Emacs buffer"))
So in order to _change_ single elements of a menu-item, I need to read
out everything that define-key was called with in menu-bar.el.
Of course, I could tinker with menu-bar.el directly or copy stuff out
of it, but that would be no fun to keep up to date...
Thanks in advance
-- Dave
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Assigning keymaps / menu shorts / changing menu items
2005-04-10 19:40 David Reitter
@ 2005-04-10 20:28 ` Stefan Monnier
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2005-04-10 20:28 UTC (permalink / raw)
Cc: Help-gnu-emacs
>> Find the key-sequence corresponding to it with C-h k, then
>> (define-key [theseysequence] '(menu-item ...)).
>> See the elisp manual's description of menus and `menu-item' for more info.
> OK, but I wouldn't want to contruct a completely new menu-item, I would just
> want to exchange the text. Now, when I do something like
> (lookup-key global-map [menu-bar file open-file])
> all I get is the pure command, 'find-file-existing, in this case - but not
> the arguments :enable and :help that were defined in menu-bar.el:
Yes, that's a problem I'm familar with. It should be pretty easy to fix,
all we need is a way to tell lookup-key to return the "raw" binding.
Please send a feature request to gnu.emacs.bug about it.
As a workaround you can try
(cdr (assq 'open-file (lookup-key global-map [menu-bar file])))
which will probably work in most cases. Note that doing a `setcar' or
`setcdr' operation on the menu-item you found, tho appealing, should be
avoided since it may fail (this data is often located in pure-storage
which is readonly). Instead you'll have to reconstruct a new menu-item with
most of the content unchanged, using non-destructive operators like
`append', `cons', ...
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-04-10 20:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-09 18:11 Assigning keymaps / menu shorts / changing menu items David Reitter
[not found] <mailman.935.1113068595.2895.help-gnu-emacs@gnu.org>
2005-04-09 19:15 ` Stefan Monnier
-- strict thread matches above, loose matches on Subject: below --
2005-04-10 19:40 David Reitter
2005-04-10 20:28 ` Stefan Monnier
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).