aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2001-12-13 19:03:12 +0000
committerStefan Monnier2001-12-13 19:03:12 +0000
commit0847e165c48029af3ec0abce38e4c63e1d0431dd (patch)
treec949a2ef9ee9071f75a9046def5b904c4cafe235
parent5dc2e846a72bedd00655befb685b905ce4c5b3dd (diff)
downloademacs-0847e165c48029af3ec0abce38e4c63e1d0431dd.tar.gz
emacs-0847e165c48029af3ec0abce38e4c63e1d0431dd.zip
(easy-menu-intern): New fun.
(easy-menu-do-define, easy-menu-convert-item-1) (easy-menu-define-key-intern, easy-menu-get-map): Use it. (easy-menu-return-item): Only return nil if there is no binding.
-rw-r--r--lisp/emacs-lisp/easymenu.el23
1 files changed, 14 insertions, 9 deletions
diff --git a/lisp/emacs-lisp/easymenu.el b/lisp/emacs-lisp/easymenu.el
index 245feb78983..fe4a44e833d 100644
--- a/lisp/emacs-lisp/easymenu.el
+++ b/lisp/emacs-lisp/easymenu.el
@@ -41,6 +41,9 @@ menus, turn this variable off, otherwise it is probably better to keep it on."
41 :group 'menu 41 :group 'menu
42 :version "20.3") 42 :version "20.3")
43 43
44(defsubst easy-menu-intern (s)
45 (if (stringp s) (intern s) s))
46
44;;;###autoload 47;;;###autoload
45(put 'easy-menu-define 'lisp-indent-function 'defun) 48(put 'easy-menu-define 'lisp-indent-function 'defun)
46;;;###autoload 49;;;###autoload
@@ -167,7 +170,7 @@ A menu item can be a list with the same format as MENU. This is a submenu."
167 (symbol-function ,symbol))) 170 (symbol-function ,symbol)))
168 ,symbol)))) 171 ,symbol))))
169 (mapcar (lambda (map) 172 (mapcar (lambda (map)
170 (define-key map (vector 'menu-bar (intern (car menu))) 173 (define-key map (vector 'menu-bar (easy-menu-intern (car menu)))
171 (cons 'menu-item 174 (cons 'menu-item
172 (cons (car menu) 175 (cons (car menu)
173 (if (not (symbolp keymap)) 176 (if (not (symbolp keymap))
@@ -356,7 +359,7 @@ MENU, just change it, otherwise put it last in MENU."
356 ;; `intern' the name so as to merge multiple entries with the same name. 359 ;; `intern' the name so as to merge multiple entries with the same name.
357 ;; It also makes it easier/possible to lookup/change menu bindings 360 ;; It also makes it easier/possible to lookup/change menu bindings
358 ;; via keymap functions. 361 ;; via keymap functions.
359 (cons (if (stringp name) (intern name) name) 362 (cons (easy-menu-intern name)
360 (and (not remove) 363 (and (not remove)
361 (cons 'menu-item 364 (cons 'menu-item
362 (cons label 365 (cons label
@@ -365,8 +368,8 @@ MENU, just change it, otherwise put it last in MENU."
365 368
366(defun easy-menu-define-key-intern (menu key item &optional before) 369(defun easy-menu-define-key-intern (menu key item &optional before)
367 "Like easy-menu-define-key, but interns KEY and BEFORE if they are strings." 370 "Like easy-menu-define-key, but interns KEY and BEFORE if they are strings."
368 (easy-menu-define-key menu (if (stringp key) (intern key) key) item 371 (easy-menu-define-key menu (easy-menu-intern key) item
369 (if (stringp before) (intern before) before))) 372 (easy-menu-intern before)))
370 373
371(defun easy-menu-define-key (menu key item &optional before) 374(defun easy-menu-define-key (menu key item &optional before)
372 "Add binding in MENU for KEY => ITEM. Similar to `define-key-after'. 375 "Add binding in MENU for KEY => ITEM. Similar to `define-key-after'.
@@ -514,11 +517,9 @@ NAME should be a string, the name of the element to be removed."
514 "In menu MENU try to look for menu item with name NAME. 517 "In menu MENU try to look for menu item with name NAME.
515If a menu item is found, return (NAME . item), otherwise return nil. 518If a menu item is found, return (NAME . item), otherwise return nil.
516If item is an old format item, a new format item is returned." 519If item is an old format item, a new format item is returned."
517 (let ((item (lookup-key menu (vector (intern name)))) 520 (let ((item (lookup-key menu (vector (easy-menu-intern name))))
518 ret enable cache label) 521 ret enable cache label)
519 (cond 522 (cond
520 ((or (keymapp item) (eq (car-safe item) 'menu-item))
521 (cons name item)) ; Keymap or new menu format
522 ((stringp (car-safe item)) 523 ((stringp (car-safe item))
523 ;; This is the old menu format. Convert it to new format. 524 ;; This is the old menu format. Convert it to new format.
524 (setq label (car item)) 525 (setq label (car item))
@@ -532,7 +533,10 @@ If item is an old format item, a new format item is returned."
532 (and (symbolp item) (setq enable (get item 'menu-enable)) ; Got enable 533 (and (symbolp item) (setq enable (get item 'menu-enable)) ; Got enable
533 (setq ret (cons :enable (cons enable ret)))) 534 (setq ret (cons :enable (cons enable ret))))
534 (if cache (setq ret (cons cache ret))) 535 (if cache (setq ret (cons cache ret)))
535 (cons name (cons 'menu-enable (cons label (cons item ret)))))))) 536 (cons name (cons 'menu-enable (cons label (cons item ret)))))
537 (item ; (or (symbolp item) (keymapp item) (eq (car-safe item) 'menu-item))
538 (cons name item)) ; Keymap or new menu format
539 )))
536 540
537(defun easy-menu-get-map-look-for-name (name submap) 541(defun easy-menu-get-map-look-for-name (name submap)
538 (while (and submap (not (or (equal (car-safe (cdr-safe (car submap))) name) 542 (while (and submap (not (or (equal (car-safe (cdr-safe (car submap))) name)
@@ -558,7 +562,8 @@ wants to modify in the map that we return.
558In some cases we use that to select between the local and global maps." 562In some cases we use that to select between the local and global maps."
559 (setq map 563 (setq map
560 (catch 'found 564 (catch 'found
561 (let* ((key (vconcat (unless map '(menu-bar)) (mapcar 'intern path))) 565 (let* ((key (vconcat (unless map '(menu-bar))
566 (mapcar 'easy-menu-intern path)))
562 (maps (mapcar (lambda (map) 567 (maps (mapcar (lambda (map)
563 (setq map (lookup-key map key)) 568 (setq map (lookup-key map key))
564 (while (and (symbolp map) (keymapp map)) 569 (while (and (symbolp map) (keymapp map))