+2000-12-13 Stefan Monnier <monnier@cs.yale.edu>
+
+ * emacs-lisp/easymenu.el (easy-menu-define): Setup indentation.
+ (easy-menu-current-active-maps): New function.
+ (easy-menu-get-map): Use it.
+ Make a proper menu entry when creating a new keymap.
+
2000-12-13 Kenichi Handa <handa@etl.go.jp>
* international/characters.el: Fix cases and syntaxes for
* term/mac-win.el: Remove load for ls-lisp.
- * loadup.el: Load ls-lisp for system-type macos.
+ * loadup.el: Load ls-lisp for system-type macros.
2000-12-12 Miles Bader <miles@gnu.org>
:group 'menu
:version "20.3")
+;;;###autoload
+(put 'easy-menu-define 'lisp-indent-function 'defun)
;;;###autoload
(defmacro easy-menu-define (symbol maps doc menu)
"Define a menu bar submenu in maps MAPS, according to MENU.
(setq submap (cdr submap)))
submap)
+;; This should really be in keymap.c
+(defun easy-menu-current-active-maps ()
+ (let ((maps (list (current-local-map) global-map)))
+ (dolist (minor minor-mode-map-alist)
+ (if (symbol-value (car minor)) (push (cdr minor) maps)))
+ (delq nil maps)))
+
(defun easy-menu-get-map (map path &optional to-modify)
"Return a sparse keymap in which to add or remove an item.
MAP and PATH are as defined in `easy-menu-add-item'.
TO-MODIFY, if non-nil, is the name of the item the caller
wants to modify in the map that we return.
In some cases we use that to select between the local and global maps."
- (if (null map)
- (let ((local (and (current-local-map)
- (lookup-key (current-local-map)
- (vconcat '(menu-bar) (mapcar 'intern path)))))
- (global (lookup-key global-map
- (vconcat '(menu-bar) (mapcar 'intern path)))))
- (cond ((and to-modify local (not (integerp local))
- (easy-menu-get-map-look-for-name to-modify local))
- (setq map local))
- ((and to-modify global (not (integerp global))
- (easy-menu-get-map-look-for-name to-modify global))
- (setq map global))
- ((and local local (not (integerp local)))
- (setq map local))
- ((and global (not (integerp global)))
- (setq map global))
- (t
- (setq map (make-sparse-keymap))
- (define-key (current-local-map)
- (vconcat '(menu-bar) (mapcar 'intern path)) map))))
- (if (and (symbolp map) (not (keymapp map)))
- (setq map (symbol-value map)))
- (if path (setq map (lookup-key map (vconcat (mapcar 'intern path))))))
- (while (and (symbolp map) (keymapp map))
- (setq map (symbol-function map)))
- (unless map
- (error "Menu specified in easy-menu is not defined"))
+ (setq map
+ (catch 'found
+ (let* ((key (vconcat (unless map '(menu-bar)) (mapcar 'intern path)))
+ (maps (mapcar (lambda (map)
+ (setq map (lookup-key map key))
+ (while (and (symbolp map) (keymapp map))
+ (setq map (symbol-function map)))
+ map)
+ (if map
+ (list (if (and (symbolp map)
+ (not (keymapp map)))
+ (symbol-value map) map))
+ (easy-menu-current-active-maps)))))
+ ;; Prefer a map that already contains the to-be-modified entry.
+ (when to-modify
+ (dolist (map maps)
+ (when (and map (not (integerp map))
+ (easy-menu-get-map-look-for-name to-modify map))
+ (throw 'found map))))
+ ;; Use the first valid map.
+ (dolist (map maps)
+ (when (and map (not (integerp map)))
+ (throw 'found map)))
+ ;; Otherwise, make one up.
+ ;; Hardcoding current-local-map is lame, but it's difficult
+ ;; to know what the caller intended for us to do ;-(
+ (let* ((name (if path (format "%s" (car (reverse path)))))
+ (newmap (make-sparse-keymap name)))
+ (define-key (or map (current-local-map)) key
+ (if name (cons name newmap) newmap))
+ newmap))))
(or (keymapp map) (error "Malformed menu in easy-menu: (%s)" map))
map)