emacs-devel
[Top][All Lists]
Advanced

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

Re: Sensible menu bindings


From: Kim F. Storm
Subject: Re: Sensible menu bindings
Date: Tue, 29 Mar 2005 13:41:03 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

David Kastrup <address@hidden> 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 <address@hidden> http://www.cua.dk





reply via email to

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