all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lennart Borgman <lennart.borgman.073@student.lu.se>
Cc: Emacs Devel <emacs-devel@gnu.org>
Subject: Re: Format av menu keymaps
Date: Mon, 09 Jan 2006 22:45:26 +0100	[thread overview]
Message-ID: <43C2D976.5050302@student.lu.se> (raw)
In-Reply-To: <87r77ikuia.fsf-monnier+emacs@gnu.org>

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	other threads:[~2006-01-09 21:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-08 22:27 Format av menu keymaps Lennart Borgman
2006-01-09  2:27 ` Stefan Monnier
2006-01-09 21:45   ` Lennart Borgman [this message]
2006-01-09 23:10     ` Stefan Monnier
2006-01-09 23:57       ` Lennart Borgman
2006-01-10  4:21         ` Stefan Monnier
     [not found]           ` <43C36D10.1050003@student.lu.se>
     [not found]             ` <jwvmzi43xn9.fsf-monnier+emacs@gnu.org>
2006-01-10 17:00               ` Lennart Borgman
2006-01-10 17:40                 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43C2D976.5050302@student.lu.se \
    --to=lennart.borgman.073@student.lu.se \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.