Function: easy-menu-create-menu
easy-menu-create-menu is a byte-compiled function defined in
easymenu.el.gz.
Signature
(easy-menu-create-menu MENU-NAME MENU-ITEMS)
Documentation
Create a menu called MENU-NAME with items described in MENU-ITEMS.
MENU-NAME is a string, the name of the menu. MENU-ITEMS is a list of items
possibly preceded by keyword pairs as described in easy-menu-define.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/easymenu.el.gz
(defun easy-menu-create-menu (menu-name menu-items)
"Create a menu called MENU-NAME with items described in MENU-ITEMS.
MENU-NAME is a string, the name of the menu. MENU-ITEMS is a list of items
possibly preceded by keyword pairs as described in `easy-menu-define'."
(let ((menu (make-sparse-keymap menu-name))
(easy-menu-avoid-duplicate-keys nil)
prop keyword label enable filter visible help)
;; Look for keywords.
(while (and menu-items
(cdr menu-items)
(keywordp (setq keyword (car menu-items))))
(let ((arg (cadr menu-items)))
(setq menu-items (cddr menu-items))
(pcase keyword
(:filter
(setq filter (lambda (menu)
(easy-menu-filter-return (funcall arg menu)
menu-name))))
((or :enable :active) (setq enable (or arg ''nil)))
(:label (setq label arg))
(:help (setq help arg))
((or :included :visible) (setq visible (or arg ''nil))))))
(if (equal visible ''nil)
nil ; Invisible menu entry, return nil.
(if (and visible (not (easy-menu-always-true-p visible)))
(setq prop (cons :visible (cons visible prop))))
(if (and enable (not (easy-menu-always-true-p enable)))
(setq prop (cons :enable (cons enable prop))))
(if filter (setq prop (cons :filter (cons filter prop))))
(if help (setq prop (cons :help (cons help prop))))
(if label (setq prop (cons :label (cons label prop))))
(setq menu (if filter
;; The filter expects the menu in its XEmacs form and the
;; pre-filter form will only be passed to the filter
;; anyway, so we'd better not convert it at all (it will
;; be converted on the fly by easy-menu-filter-return).
menu-items
(append menu (mapcar #'easy-menu-convert-item menu-items))))
(when prop
(setq menu (easy-menu-make-symbol menu 'noexp))
(put menu 'menu-prop prop))
menu)))