Function: easy-menu-return-item

easy-menu-return-item is a byte-compiled function defined in easymenu.el.gz.

Signature

(easy-menu-return-item MENU NAME)

Documentation

In menu MENU try to look for menu item with name NAME.

If a menu item is found, return (NAME . item), otherwise return nil. If item is an old format item, a new format item is returned.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/easymenu.el.gz
(defun easy-menu-return-item (menu name)
  "In menu MENU try to look for menu item with name NAME.
If a menu item is found, return (NAME . item), otherwise return nil.
If item is an old format item, a new format item is returned."
  ;; The call to `lookup-key' also calls the C function `get_keyelt' which
  ;; looks inside a menu-item to only return the actual command.  This is
  ;; not what we want here.  We should either add an arg to lookup-key to be
  ;; able to turn off this "feature", or else we could use map-keymap here.
  ;; In the mean time, I just use `assq' which is an OK approximation since
  ;; menus are rarely built from vectors or char-tables.
  (let ((item (or (cdr (assq name menu))
                  (lookup-key menu (vector (easy-menu-intern name)))))
	ret enable cache label)
    (cond
     ((stringp (car-safe item))
      ;; This is the old menu format. Convert it to new format.
      (setq label (car item))
      (when (stringp (car (setq item (cdr item)))) ; Got help string
	(setq ret (list :help (car item)))
	(setq item (cdr item)))
      (when (and (consp item) (consp (car item))
		 (or (null (caar item)) (numberp (caar item))))
	(setq cache (car item))		; Got cache
	(setq item (cdr item)))
      (and (symbolp item) (setq enable (get item 'menu-enable))	; Got enable
	   (setq ret (cons :enable (cons enable ret))))
      (if cache (setq ret (cons cache ret)))
      (cons name (cons 'menu-enable (cons label (cons item ret)))))
     (item ; (or (symbolp item) (keymapp item) (eq (car-safe item) 'menu-item))
      (cons name item))			; Keymap or new menu format
     )))