Function: easy-menu-define-key
easy-menu-define-key is a byte-compiled function defined in
easymenu.el.gz.
Signature
(easy-menu-define-key MENU KEY ITEM &optional BEFORE)
Documentation
Add binding in MENU for KEY => ITEM. Similar to define-key-after.
If KEY is not nil then delete any duplications. If ITEM is nil, then delete the definition of KEY.
Optional argument BEFORE is nil or a key in MENU. If BEFORE is not nil,
put binding before the item in MENU named BEFORE; otherwise,
if a binding for KEY is already present in MENU, just change it;
otherwise put the new binding last in MENU.
BEFORE can be either a string (menu item name) or a symbol
(the fake function key for the menu item).
KEY does not have to be a symbol, and comparison is done with equal.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/easymenu.el.gz
(defun easy-menu-define-key (menu key item &optional before)
"Add binding in MENU for KEY => ITEM. Similar to `define-key-after'.
If KEY is not nil then delete any duplications.
If ITEM is nil, then delete the definition of KEY.
Optional argument BEFORE is nil or a key in MENU. If BEFORE is not nil,
put binding before the item in MENU named BEFORE; otherwise,
if a binding for KEY is already present in MENU, just change it;
otherwise put the new binding last in MENU.
BEFORE can be either a string (menu item name) or a symbol
\(the fake function key for the menu item).
KEY does not have to be a symbol, and comparison is done with equal."
(if (symbolp menu) (setq menu (indirect-function menu)))
(let ((inserted (null item)) ; Fake already inserted.
tail done)
(while (not done)
(cond
((or (setq done (or (null (cdr menu)) (keymapp (cdr menu))))
(and before (easy-menu-name-match before (cadr menu))))
;; If key is nil, stop here, otherwise keep going past the
;; inserted element so we can delete any duplications that come
;; later.
(if (null key) (setq done t))
(unless inserted ; Don't insert more than once.
(setcdr menu (cons (cons key item) (cdr menu)))
(setq inserted t)
(setq menu (cdr menu)))
(setq menu (cdr menu)))
((and key (equal (car-safe (cadr menu)) key))
(if (or inserted ; Already inserted or
(and before ; wanted elsewhere and
(setq tail (cddr menu)) ; not last item and not
(not (keymapp tail))
(not (easy-menu-name-match
before (car tail))))) ; in position
(setcdr menu (cddr menu)) ; Remove item.
(setcdr (cadr menu) item) ; Change item.
(setq inserted t)
(setq menu (cdr menu))))
(t (setq menu (cdr menu)))))))