aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-12-25 06:17:31 +0000
committerRichard M. Stallman1998-12-25 06:17:31 +0000
commit5e6656e0e6439e80801c331ce244e989ffa95930 (patch)
treeb74cad881d425f8b188a7ba42c97dec8df0cdaa9
parent2680029f0ac20eb0620f7b1b848fd9f9a521c99d (diff)
downloademacs-5e6656e0e6439e80801c331ce244e989ffa95930.tar.gz
emacs-5e6656e0e6439e80801c331ce244e989ffa95930.zip
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
(easy-menu-add-item, easy-menu-remove-item): Argument renamed. (easy-menu-item-present-p, easy-menu-get-map): Argument renamed.
-rw-r--r--lisp/emacs-lisp/easymenu.el59
1 files changed, 31 insertions, 28 deletions
diff --git a/lisp/emacs-lisp/easymenu.el b/lisp/emacs-lisp/easymenu.el
index 9f175340b9e..e88db0952cc 100644
--- a/lisp/emacs-lisp/easymenu.el
+++ b/lisp/emacs-lisp/easymenu.el
@@ -357,22 +357,24 @@ Do it if `easy-menu-precalculate-equivalent-keybindings' is on,"
357 (setq menu (symbol-value menu))) 357 (setq menu (symbol-value menu)))
358 (if (keymapp menu) (x-popup-menu nil menu)))) 358 (if (keymapp menu) (x-popup-menu nil menu))))
359 359
360(defun easy-menu-add-item (menu path item &optional before) 360(defun easy-menu-add-item (map path item &optional before)
361 "At the end of the submenu of MENU with path PATH add ITEM. 361 "At the end of the submenu of MAP with path PATH add ITEM.
362If ITEM is already present in this submenu, then this item will be changed. 362If ITEM is already present in this submenu, then this item will be changed.
363otherwise ITEM will be added at the end of the submenu, unless the optional 363otherwise ITEM will be added at the end of the submenu, unless the optional
364argument BEFORE is present, in which case ITEM will instead be added 364argument BEFORE is present, in which case ITEM will instead be added
365before the item named BEFORE. 365before the item named BEFORE.
366MENU is either a symbol, which have earlier been used as the first 366
367argument in a call to `easy-menu-define', or the value of such a symbol 367MAP should normally be a keymap; nil stands for the global menu-bar keymap.
368i.e. a menu, or nil which stands for the menu-bar itself. 368It can also be a symbol, which has earlier been used as the first
369argument in a call to `easy-menu-define', or the value of such a symbol.
370
369PATH is a list of strings for locating the submenu where ITEM is to be 371PATH is a list of strings for locating the submenu where ITEM is to be
370added. If PATH is nil, MENU itself is used. Otherwise, the first 372added. If PATH is nil, MAP itself is used. Otherwise, the first
371element should be the name of a submenu directly under MENU. This 373element should be the name of a submenu directly under MAP. This
372submenu is then traversed recursively with the remaining elements of PATH. 374submenu is then traversed recursively with the remaining elements of PATH.
373ITEM is either defined as in `easy-menu-define' or a menu defined earlier 375ITEM is either defined as in `easy-menu-define' or a menu defined earlier
374by `easy-menu-define' or `easy-menu-create-menu'." 376by `easy-menu-define' or `easy-menu-create-menu'."
375 (setq menu (easy-menu-get-map menu path)) 377 (setq map (easy-menu-get-map map path))
376 (if (or (keymapp item) 378 (if (or (keymapp item)
377 (and (symbolp item) (keymapp (symbol-value item)))) 379 (and (symbolp item) (keymapp (symbol-value item))))
378 ;; Item is a keymap, find the prompt string and use as item name. 380 ;; Item is a keymap, find the prompt string and use as item name.
@@ -383,32 +385,33 @@ by `easy-menu-define' or `easy-menu-create-menu'."
383 (if (stringp (car tail)) (setq name (car tail)) ; Got a name. 385 (if (stringp (car tail)) (setq name (car tail)) ; Got a name.
384 (setq tail (cdr tail)))) 386 (setq tail (cdr tail))))
385 (setq item (cons name item)))) 387 (setq item (cons name item))))
386 (easy-menu-do-add-item menu item before)) 388 (easy-menu-do-add-item map item before))
387 389
388(defun easy-menu-item-present-p (menu path name) 390(defun easy-menu-item-present-p (map path name)
389 "In submenu of MENU with path PATH, return true iff item NAME is present. 391 "In submenu of MAP with path PATH, return true iff item NAME is present.
390MENU and PATH are defined as in `easy-menu-add-item'. 392MAP and PATH are defined as in `easy-menu-add-item'.
391NAME should be a string, the name of the element to be looked for." 393NAME should be a string, the name of the element to be looked for."
392 (lookup-key (easy-menu-get-map menu path) (vector (intern name)))) 394 (lookup-key (easy-menu-get-map map path) (vector (intern name))))
393 395
394(defun easy-menu-remove-item (menu path name) 396(defun easy-menu-remove-item (map path name)
395 "From submenu of MENU with path PATH remove item NAME. 397 "From submenu of MAP with path PATH remove item NAME.
396MENU and PATH are defined as in `easy-menu-add-item'. 398MAP and PATH are defined as in `easy-menu-add-item'.
397NAME should be a string, the name of the element to be removed." 399NAME should be a string, the name of the element to be removed."
398 (easy-menu-define-key (easy-menu-get-map menu path) (intern name) nil)) 400 (easy-menu-define-key (easy-menu-get-map map path) (intern name) nil))
399 401
400(defun easy-menu-get-map (menu path) 402(defun easy-menu-get-map (map path)
401 ;; Return a sparse keymap in which to add or remove an item. 403 ;; Return a sparse keymap in which to add or remove an item.
402 ;; MENU and PATH are as defined in `easy-menu-add-item'. 404 ;; MAP and PATH are as defined in `easy-menu-add-item'.
403 (if (null menu) 405 (if (null map)
404 (setq menu (key-binding (vconcat '(menu-bar) (mapcar 'intern path)))) 406 (setq map (lookup-key global-map
405 (if (and (symbolp menu) (not (keymapp menu))) 407 (vconcat '(menu-bar) (mapcar 'intern path))))
406 (setq menu (symbol-value menu))) 408 (if (and (symbolp map) (not (keymapp map)))
407 (if path (setq menu (lookup-key menu (vconcat (mapcar 'intern path)))))) 409 (setq map (symbol-value map)))
408 (while (and (symbolp menu) (keymapp menu)) 410 (if path (setq map (lookup-key map (vconcat (mapcar 'intern path))))))
409 (setq menu (symbol-function menu))) 411 (while (and (symbolp map) (keymapp map))
410 (or (keymapp menu) (error "Malformed menu in easy-menu: (%s)" menu)) 412 (setq map (symbol-function map)))
411 menu) 413 (or (keymapp map) (error "Malformed menu in easy-menu: (%s)" map))
414 map)
412 415
413(provide 'easymenu) 416(provide 'easymenu)
414 417