aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1999-08-10 16:54:00 +0000
committerKarl Heuer1999-08-10 16:54:00 +0000
commitfd43ede0606d1f762a3b09a04cf09477a9649579 (patch)
tree2089f786ac769abcdc57a41d3cea8f15579ec374
parentbbf6f18c1ec1b7fae1fc95114591ae0a3e425c58 (diff)
downloademacs-fd43ede0606d1f762a3b09a04cf09477a9649579.tar.gz
emacs-fd43ede0606d1f762a3b09a04cf09477a9649579.zip
(easy-menu-get-map-look-for-name): New fn.
(easy-menu-get-map): New arg TO-MODIFY helps choose between local and global maps. (easy-menu-add-item): Pass TO-MODIFY arg to easy-menu-get-map. (easy-menu-change): Doc fix.
-rw-r--r--lisp/emacs-lisp/easymenu.el62
1 files changed, 43 insertions, 19 deletions
diff --git a/lisp/emacs-lisp/easymenu.el b/lisp/emacs-lisp/easymenu.el
index 361834a47b1..bab2ce75dff 100644
--- a/lisp/emacs-lisp/easymenu.el
+++ b/lisp/emacs-lisp/easymenu.el
@@ -368,12 +368,14 @@ possibly preceded by keyword pairs as described in `easy-menu-define'."
368;;;###autoload 368;;;###autoload
369(defun easy-menu-change (path name items &optional before) 369(defun easy-menu-change (path name items &optional before)
370 "Change menu found at PATH as item NAME to contain ITEMS. 370 "Change menu found at PATH as item NAME to contain ITEMS.
371PATH is a list of strings for locating the menu containing NAME in the 371PATH is a list of strings for locating the menu that
372menu bar. ITEMS is a list of menu items, as in `easy-menu-define'. 372should contain a submenu named NAME.
373These items entirely replace the previous items in that map. 373ITEMS is a list of menu items, as in `easy-menu-define'.
374If NAME is not present in the menu located by PATH, then add item NAME to 374These items entirely replace the previous items in that submenu.
375that menu. If the optional argument BEFORE is present add NAME in menu 375
376just before BEFORE, otherwise add at end of menu. 376If the menu located by PATH has no submenu named NAME, add one.
377If the optional argument BEFORE is present, add it just before
378the submenu named BEFORE, otherwise add it at the end of the menu.
377 379
378Either call this from `menu-bar-update-hook' or use a menu filter, 380Either call this from `menu-bar-update-hook' or use a menu filter,
379to implement dynamic menus." 381to implement dynamic menus."
@@ -396,10 +398,12 @@ Do it if `easy-menu-precalculate-equivalent-keybindings' is on,"
396 398
397(defun easy-menu-add-item (map path item &optional before) 399(defun easy-menu-add-item (map path item &optional before)
398 "To the submenu of MAP with path PATH, add ITEM. 400 "To the submenu of MAP with path PATH, add ITEM.
399If ITEM is already present in this submenu, then this item will be changed. 401
400otherwise ITEM will be added at the end of the submenu, unless the optional 402If an item with the same name is already present in this submenu,
401argument BEFORE is present, in which case ITEM will instead be added 403then ITEM replaces it. Otherwise, ITEM is added to this submenu.
402before the item named BEFORE. 404In the latter case, ITEM is normally added at the end of the submenu.
405However, if BEFORE is a string and there is an item in the submenu
406with that name, then ITEM is added before that item.
403 407
404MAP should normally be a keymap; nil stands for the global menu-bar keymap. 408MAP should normally be a keymap; nil stands for the global menu-bar keymap.
405It can also be a symbol, which has earlier been used as the first 409It can also be a symbol, which has earlier been used as the first
@@ -413,7 +417,10 @@ submenu is then traversed recursively with the remaining elements of PATH.
413ITEM is either defined as in `easy-menu-define' or a non-nil value returned 417ITEM is either defined as in `easy-menu-define' or a non-nil value returned
414by `easy-menu-item-present-p' or `easy-menu-remove-item' or a menu defined 418by `easy-menu-item-present-p' or `easy-menu-remove-item' or a menu defined
415earlier by `easy-menu-define' or `easy-menu-create-menu'." 419earlier by `easy-menu-define' or `easy-menu-create-menu'."
416 (setq map (easy-menu-get-map map path)) 420 (setq map (easy-menu-get-map map path
421 (and (null map) (null path)
422 (stringp (car-safe item))
423 (car item))))
417 (if (and (consp item) (consp (cdr item)) (eq (cadr item) 'menu-item)) 424 (if (and (consp item) (consp (cdr item)) (eq (cadr item) 'menu-item))
418 ;; This is a value returned by `easy-menu-item-present-p' or 425 ;; This is a value returned by `easy-menu-item-present-p' or
419 ;; `easy-menu-remove-item'. 426 ;; `easy-menu-remove-item'.
@@ -469,22 +476,39 @@ NAME should be a string, the name of the element to be removed."
469 (if cache (setq ret (cons cache ret))) 476 (if cache (setq ret (cons cache ret)))
470 (cons name (cons 'menu-enable (cons label (cons item ret)))))))) 477 (cons name (cons 'menu-enable (cons label (cons item ret))))))))
471 478
472(defun easy-menu-get-map (map path) 479(defun easy-menu-get-map-look-for-name (name submap)
480 (while (and submap (not (or (equal (car-safe (cdr-safe (car submap))) name)
481 (equal (car-safe (cdr-safe (cdr-safe (car submap)))) name))))
482 (setq submap (cdr submap)))
483 submap)
484
485(defun easy-menu-get-map (map path &optional to-modify)
473 ;; Return a sparse keymap in which to add or remove an item. 486 ;; Return a sparse keymap in which to add or remove an item.
474 ;; MAP and PATH are as defined in `easy-menu-add-item'. 487 ;; MAP and PATH are as defined in `easy-menu-add-item'.
488
489 ;; TO-MODIFY, if non-nil, is the name of the item the caller
490 ;; wants to modify in the map that we return.
491 ;; In some cases we use that to select between the local and global maps.
475 (if (null map) 492 (if (null map)
476 (let ((local (and (current-local-map) 493 (let ((local (and (current-local-map)
477 (lookup-key (current-local-map) 494 (lookup-key (current-local-map)
478 (vconcat '(menu-bar) (mapcar 'intern path))))) 495 (vconcat '(menu-bar) (mapcar 'intern path)))))
479 (global (lookup-key global-map 496 (global (lookup-key global-map
480 (vconcat '(menu-bar) (mapcar 'intern path))))) 497 (vconcat '(menu-bar) (mapcar 'intern path)))))
481 (if (and local (not (integerp local))) 498 (cond ((and to-modify local (not (integerp local))
482 (setq map local) 499 (easy-menu-get-map-look-for-name to-modify local))
483 (if (and global (not (integerp global))) 500 (setq map local))
484 (setq map global) 501 ((and to-modify global (not (integerp global))
485 (setq map (make-sparse-keymap)) 502 (easy-menu-get-map-look-for-name to-modify global))
486 (define-key (current-local-map) 503 (setq map global))
487 (vconcat '(menu-bar) (mapcar 'intern path)) map)))) 504 ((and local local (not (integerp local)))
505 (setq map local))
506 ((and global (not (integerp global)))
507 (setq map global))
508 (t
509 (setq map (make-sparse-keymap))
510 (define-key (current-local-map)
511 (vconcat '(menu-bar) (mapcar 'intern path)) map))))
488 (if (and (symbolp map) (not (keymapp map))) 512 (if (and (symbolp map) (not (keymapp map)))
489 (setq map (symbol-value map))) 513 (setq map (symbol-value map)))
490 (if path (setq map (lookup-key map (vconcat (mapcar 'intern path)))))) 514 (if path (setq map (lookup-key map (vconcat (mapcar 'intern path))))))