unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: storm@cua.dk (Kim F. Storm)
Cc: Peter Dyballa <Peter_Dyballa@Web.DE>,
	emacs-pretest-bug@gnu.org, emacs-devel@gnu.org
Subject: Re: Sensible menu bindings
Date: Tue, 29 Mar 2005 13:41:03 +0200	[thread overview]
Message-ID: <m3zmwmwugg.fsf@kfs-l.imdomain.dk> (raw)
In-Reply-To: <x5y8c6wxp7.fsf@lola.goethe.zz> (David Kastrup's message of "Tue, 29 Mar 2005 12:31:00 +0200")

David Kastrup <dak@gnu.org> writes:

> how feasible would it be to
> make kbd accept File=>Print=>Print With Faces strings?  Then there
> would be no necessity to report a different form.

Does kbd really generate proper menu bindings in its current form?
Does it make sense at all to use kbd for that purpose?

(kbd "<menu-bar> <file> <new-file>")
=> [menu-bar file new-file]


In any case, the main problem is that parsing the new form must go
through the active keymaps to find the relevant menu bindings.
However, this is doable if we limit it to the global map:

(defun kbd-menu-binding (menu-binding)
  (let ((items (split-string menu-binding "=>"))
	(map (lookup-key global-map [menu-bar]))
	m keys)
    (while (and items map)
      (setq m (car map)
	    map (cdr map))
      (when (consp m)
	(if (eq (nth 1 m) 'menu-item)
	    (if (equal (car items) (nth 2 m))
		(setq map (and (keymapp (nth 3 m)) (nth 3 m))
		      items (cdr items)
		      keys (cons (car m) keys)))
	  (if (equal (car items) (nth 1 m))
	      (setq map (if (and (symbolp (nthcdr 2 m))
				 (boundp (nthcdr 2 m))
				 (keymapp (symbol-value (nthcdr 2 m))))
			    (cdr (symbol-value (nthcdr 2 m)))
			  (nthcdr 2 m))
		    items (cdr items)
		    keys (cons (car m) keys))))))
    (if items
	(error "No menu binding for %s" menu-binding)
      (apply 'vector 'menu-bar (reverse keys)))))


(kbd-menu-binding "File=>New File...")
=> [menu-bar file new-file]

(kbd-menu-binding "Options=>Mule (Multilingual Environment)=>Set Language Environment=>European=>Brazilian Portuguese")
=> [menu-bar options mule set-language-environment European Brazilian\ Portuguese]

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

  reply	other threads:[~2005-03-29 11:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <91a0b1e20a73068697a422453a2dcb7e@Web.DE>
     [not found] ` <01c53211$Blat.v2.4$99a09d00@zahav.net.il>
     [not found]   ` <m34qevh0ag.fsf@kfs-l.imdomain.dk>
     [not found]     ` <m1u0mvnxlj.fsf-monnier+emacs@gnu.org>
2005-03-29  9:43       ` Sensible menu bindings (was Re: A doc typo?) Kim F. Storm
2005-03-29 10:31         ` Sensible menu bindings David Kastrup
2005-03-29 11:41           ` Kim F. Storm [this message]
2005-03-29 13:45         ` Stefan Monnier
2005-03-29 14:58           ` Kim F. Storm

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=m3zmwmwugg.fsf@kfs-l.imdomain.dk \
    --to=storm@cua.dk \
    --cc=Peter_Dyballa@Web.DE \
    --cc=emacs-devel@gnu.org \
    --cc=emacs-pretest-bug@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 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).