unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Creating submenu
@ 2009-12-02 13:02 ken
  2009-12-02 18:49 ` Davis Herring
  0 siblings, 1 reply; 3+ messages in thread
From: ken @ 2009-12-02 13:02 UTC (permalink / raw)
  To: emacs-bug

I'm trying to create a submenu (under Edit) for inserting non-English
characters.  I'd like this submenu to show keybindings as well... to
serve as reminders so I don't have to go to the menu all the time.
Finally, I'm defining a new prefix key, "C-c g" for the items in this
submenu.  I'd like this submenu to be operative in all major modes that
I'd be editing in.

Actually, after reading a few chapters in the elisp manual and examining
existing elisp code, I have come up with code that is working, but it
has some undesirable side-effects.  Here's what I have:

------------------------------------------------------------------
;Make ^C-cg a key prefix for chars menu
(global-set-key [?\C-c ?g] ctl-x-map)

;;Need this definition, else the main "define-key ..." below it errors.
(defvar menu-bar-chars-menu (make-sparse-keymap "chars"))

;This puts the "European chars" item into the "Edit" menu.
;;Function definition: (define-key keymap key def)
(define-key menu-bar-edit-menu [chars]
  (list 'menu-item "Insert European chars" menu-bar-chars-menu))

;Menu item: list all UTF-8 chars
(fset 'list-all-chars [?\C-x ?8 f1])
(global-set-key [?\C-c ?g ?0] 'list-all-chars)
(define-key menu-bar-chars-menu [listall]
  '(menu-item "List all UTF-8 chars" list-all-chars))
------------------------------------------------------------------

The last stanza pretty much repeats for characters which are inserted.
And the above works fine except:

In the menu the keybinding displayed is not "C-x g 0", but rather "C-x
0" and...

While "C-x g 0" works as intended and does display the listing of UTF-8
characters, so does the displayed "C-x 0"... i.e., it has replaced the
former keybinding of "C-x 0"... not good.  So I'm guess there's some
error in the way I've established keybindings with the new prefix.


Thanks much for your cordial assistance.

-- 
Without music, life would be a mistake.
	--Friedrich Nietzsche







^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Creating submenu
  2009-12-02 13:02 Creating submenu ken
@ 2009-12-02 18:49 ` Davis Herring
  2009-12-03  2:03   ` ken
  0 siblings, 1 reply; 3+ messages in thread
From: Davis Herring @ 2009-12-02 18:49 UTC (permalink / raw)
  To: gebser; +Cc: emacs-bug

> ;Make ^C-cg a key prefix for chars menu
> (global-set-key [?\C-c ?g] ctl-x-map)

You're reusing the keymap that C-x is normally bound to, so now C-c g is
an alias for C-x in every respect.  Don't do that!  Make a new keymap:

(defvar chars-map (make-sparse-keymap)
  "Keymap for inserting special characters.")
(global-set-key [?\C-c ?g] chars-map)

You can omit "sparse-" if you're planning to bind lots of ASCII characters
(like, say, C-c g a, C-c g 0, etc.).

> (fset 'list-all-chars [?\C-x ?8 f1])

You can do this more idomatically with

(defun list-all-chars ()
  "Describe the C-x 8 keybindings."
  (interactive)
  (describe-bindings "\C-x8"))

(`describe-bindings' is what implements `f1' after a prefix key.)  But
there might be a better way: one that used the binding of C-x 8 directly
so that it would work even if the user had moved that binding elsewhere. 
I don't know what it would be, though.

Hope this helps,
Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Creating submenu
  2009-12-02 18:49 ` Davis Herring
@ 2009-12-03  2:03   ` ken
  0 siblings, 0 replies; 3+ messages in thread
From: ken @ 2009-12-03  2:03 UTC (permalink / raw)
  To: herring; +Cc: emacs-bug

On 12/02/2009 01:49 PM Davis Herring wrote:
>> ;Make ^C-cg a key prefix for chars menu
>> (global-set-key [?\C-c ?g] ctl-x-map)
> 
> You're reusing the keymap that C-x is normally bound to, so now C-c g is
> an alias for C-x in every respect.  Don't do that!  Make a new keymap:

That was beginning to dawn on me, but didn't know where/what to fix.


> ....
> 
> Hope this helps,
> Davis
> 

Worked perfectly.  Thanks much.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-12-03  2:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-02 13:02 Creating submenu ken
2009-12-02 18:49 ` Davis Herring
2009-12-03  2:03   ` ken

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).