emacs-devel
[Top][All Lists]
Advanced

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

Re: Format av menu keymaps


From: Stefan Monnier
Subject: Re: Format av menu keymaps
Date: Mon, 09 Jan 2006 18:10:44 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

> **** I have a menu keymap like this that can be used by itself (which is
>      a good thing):
> (defconst xhtml-help-mode-keymap
>   (let ((map (make-sparse-keymap "Xhtml-Help")))
>     (define-key map [menu-bar xh-help] (cons "Xhtml-Help"
>     (make-sparse-keymap "second")))
>     (define-key map [menu-bar xh-help css-help] '("CSS Help"
>     . xhtml-help-show-css-ref))
>     (define-key map [menu-bar xh-help tag-help] '("Xhtml Tag Help"
>     . xhtml-help-show-tag-ref))
>     map))

So far so good.

> **** However now I decided I want to use that in another submenu in
>      menu-bar. Then I do something like this:

I'm not sure what "use" means here.

>       (when (featurep 'xhtml-help)
>         (let ((menu-bar-entry (cdr (assoc 'menu-bar xhtml-help-mode-keymap))))

Rather than `assoc' you should probably use lookup-key.

>           (when menu-bar-entry
>             (map-keymap
>              (lambda(binding command)
>                (let* ((tit-map (appmenu-get-submenu command))
>                       (subtitle (car tit-map))
>                       (submenu  (cdr tit-map)))
>                  (define-key map
>                    [nxhtml-xhtml-help]
>                    (list 'menu-item
>                          subtitle submenu
>                          :help "XHTML help access"))))
>              menu-bar-entry)

There's something odd in this code snice for each iteration of map-keymap
you end up rebinding the same key with `define-key' so only ther last one
will have an effect.

I assume `map' is some arbitrary keymap to which you want to add the entries
found in xhtml-help-mode-keymap?

Why do you use `appmenu-get-submenu' to destructure the menu-item only to
rebuild it right after.

I'd just do

      (when (featurep 'xhtml-help)
        (let ((menu-bar-entry (lookup-key xhtml-help-mode-keymap [menu-bar])))
          (when menu-bar-entry
            (map-keymap
             (lambda (key command)
               (define-key map
                           (vector (intern (concat "nxhtml-" (symbol-name 
key))))
                           command))
             menu-bar-entry)
            (define-key map [nxhtml-nxhtml-help-separator] (list 'menu-item
            "--"))

but maybe that's not what you're trying to do.


        Stefan




reply via email to

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