emacs-devel
[Top][All Lists]
Advanced

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

Re: Format av menu keymaps


From: Lennart Borgman
Subject: Re: Format av menu keymaps
Date: Mon, 09 Jan 2006 22:45:26 +0100
User-agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)

Stefan Monnier wrote:

I am loooking for the format of a menu keymap. There seem to be several
different formats that are possible for a submenu, but I can not find where
these are described.  Are there any functions to check if an entry in
a keymap list is a submenu?

Any keymap is potentially a menu. It depends on whether you use it like one
or not (e.g. if you pass it to x-popup-menu or bind it to some mouse event).
So I think the question is wrongly phrased.  Could you give us some context
and more concrete details of what you're trying to do?

I am trying to "reuse submenu keymaps".

Let us say I have defined a little minor mode that adds a submenu to the menu-bar. I may later want to use this submenu in another place, say in another submenu on the menu-bar. I may also want to use it in a popup menu.

Is this clear enough or does it just sound crazy? Maybe an example can help:


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

**** However now I decided I want to use that in another submenu in menu-bar. Then I do something like this:
     (when (featurep 'xhtml-help)
(let ((menu-bar-entry (cdr (assoc 'menu-bar xhtml-help-mode-keymap))))
         (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)
(define-key map [nxhtml-nxhtml-help-separator] (list 'menu-item "--"))

***** Where this little function tries to get the submenu:
(defun appmenu-get-submenu(menu-command)
 (let (subtitle submenumap)
   (if (eq 'menu-item (car menu-command))
       (progn (setq subtitle   (cadr  menu-command))
              (setq submenumap (caddr menu-command)))
     (setq subtitle   (car menu-command))
     (setq submenumap (cdr menu-command)))
   (unless (keymapp submenumap) (error "submenu not a keymap=%s" submenu))
   (cons subtitle submenumap)))


There are two things I do not really like, appmenu-get-submenu and the use of map-keymap. I do not know what to do instead. For appmenu-get-submenu I would like at least some documentation for how to write this. Even better would be defun in Emacs for something like it. Since we are close to a release (I hope) I really just wanted to say that it seems to me like documentation is missing.

And if the code looks wrong then of course I would like some hints.




reply via email to

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