comparison lisp/emacs-lisp/easymenu.el @ 47169:bed718560d06

(easy-menu-filter-return): Handle the case where the filter returns a single menu entry. (easy-menu-add): Improve docstring. (easy-menu-current-active-maps): Remove. (easy-menu-get-map): Use current-active-maps.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 30 Aug 2002 21:55:07 +0000
parents 7384ea4d758d
children f66d837bdbff
comparison
equal deleted inserted replaced
47168:59fc9e6fd3e8 47169:bed718560d06
185 a symbol whose value is such a menu. 185 a symbol whose value is such a menu.
186 In Emacs a menu filter must return a menu (a keymap), in XEmacs a filter must 186 In Emacs a menu filter must return a menu (a keymap), in XEmacs a filter must
187 return a menu items list (without menu name and keywords). 187 return a menu items list (without menu name and keywords).
188 This function returns the right thing in the two cases. 188 This function returns the right thing in the two cases.
189 If NAME is provided, it is used for the keymap." 189 If NAME is provided, it is used for the keymap."
190 (when (and (not (keymapp menu)) (consp menu)) 190 (cond
191 ((and (not (keymapp menu)) (consp menu))
191 ;; If it's a cons but not a keymap, then it can't be right 192 ;; If it's a cons but not a keymap, then it can't be right
192 ;; unless it's an XEmacs menu. 193 ;; unless it's an XEmacs menu.
193 (setq menu (easy-menu-create-menu (or name "") menu))) 194 (setq menu (easy-menu-create-menu (or name "") menu)))
194 (easy-menu-get-map menu nil)) ; Get past indirections. 195 ((vectorp menu)
196 ;; It's just a menu entry.
197 (setq menu (cdr (easy-menu-convert-item menu)))))
198 menu)
195 199
196 ;;;###autoload 200 ;;;###autoload
197 (defun easy-menu-create-menu (menu-name menu-items) 201 (defun easy-menu-create-menu (menu-name menu-items)
198 "Create a menu called MENU-NAME with items described in MENU-ITEMS. 202 "Create a menu called MENU-NAME with items described in MENU-ITEMS.
199 MENU-NAME is a string, the name of the menu. MENU-ITEMS is a list of items 203 MENU-NAME is a string, the name of the menu. MENU-ITEMS is a list of items
460 ;; equivalent keybindings (if easy-menu-precalculate-equivalent-keybindings 464 ;; equivalent keybindings (if easy-menu-precalculate-equivalent-keybindings
461 ;; is on). 465 ;; is on).
462 (defalias 'easy-menu-remove 'ignore) 466 (defalias 'easy-menu-remove 'ignore)
463 467
464 (defun easy-menu-add (menu &optional map) 468 (defun easy-menu-add (menu &optional map)
465 "Maybe precalculate equivalent key bindings. 469 "Add the menu to the menubar.
470 This is a nop on Emacs since menus are automatically activated when the
471 corresponding keymap is activated. On XEmacs this is needed to actually
472 add the menu to the current menubar.
473 Maybe precalculate equivalent key bindings.
466 Do it only if `easy-menu-precalculate-equivalent-keybindings' is on." 474 Do it only if `easy-menu-precalculate-equivalent-keybindings' is on."
467 (when easy-menu-precalculate-equivalent-keybindings 475 (when easy-menu-precalculate-equivalent-keybindings
468 (if (and (symbolp menu) (not (keymapp menu)) (boundp menu)) 476 (if (and (symbolp menu) (not (keymapp menu)) (boundp menu))
469 (setq menu (symbol-value menu))) 477 (setq menu (symbol-value menu)))
470 (if (keymapp menu) (x-popup-menu nil menu)))) 478 (if (keymapp menu) (x-popup-menu nil menu))))
563 (defun easy-menu-get-map-look-for-name (name submap) 571 (defun easy-menu-get-map-look-for-name (name submap)
564 (while (and submap (not (easy-menu-name-match name (car submap)))) 572 (while (and submap (not (easy-menu-name-match name (car submap))))
565 (setq submap (cdr submap))) 573 (setq submap (cdr submap)))
566 submap) 574 submap)
567 575
568 ;; This should really be in keymap.c
569 (defun easy-menu-current-active-maps ()
570 (let ((maps (list (current-local-map) global-map)))
571 (dolist (minor minor-mode-map-alist)
572 (when (and (boundp (car minor))
573 (symbol-value (car minor)))
574 (push (cdr minor) maps)))
575 (delq nil maps)))
576
577 (defun easy-menu-get-map (map path &optional to-modify) 576 (defun easy-menu-get-map (map path &optional to-modify)
578 "Return a sparse keymap in which to add or remove an item. 577 "Return a sparse keymap in which to add or remove an item.
579 MAP and PATH are as defined in `easy-menu-add-item'. 578 MAP and PATH are as defined in `easy-menu-add-item'.
580 579
581 TO-MODIFY, if non-nil, is the name of the item the caller 580 TO-MODIFY, if non-nil, is the name of the item the caller
592 map) 591 map)
593 (if map 592 (if map
594 (list (if (and (symbolp map) 593 (list (if (and (symbolp map)
595 (not (keymapp map))) 594 (not (keymapp map)))
596 (symbol-value map) map)) 595 (symbol-value map) map))
597 (easy-menu-current-active-maps))))) 596 (current-active-maps)))))
598 ;; Prefer a map that already contains the to-be-modified entry. 597 ;; Prefer a map that already contains the to-be-modified entry.
599 (when to-modify 598 (when to-modify
600 (dolist (map maps) 599 (dolist (map maps)
601 (when (and map (not (integerp map)) 600 (when (and map (not (integerp map))
602 (easy-menu-get-map-look-for-name to-modify map)) 601 (easy-menu-get-map-look-for-name to-modify map))