Function: widget--simplify-menu
widget--simplify-menu is a byte-compiled function defined in
wid-edit.el.gz.
Signature
(widget--simplify-menu EXTENDED)
Documentation
Convert the EXTENDED menu into a menu composed of simple menu items.
Each item in the simplified menu is of the form (ITEM-STRING . REAL-BINDING),
where both elements are taken from the EXTENDED MENU. ITEM-STRING is the
correspondent ITEM-NAME in the menu-item entry:
(menu-item ITEM-NAME REAL-BINDING . ITEM-PROPERTY-LIST), and REAL-BINDING is
the symbol in the key vector, as in define-key.
(See (elisp)Defining Menus for more information.)
Only visible, enabled and meaningful menu items make their way into the returned simplified menu. That is: For the menu item to be visible, it has to either lack a :visible form in its item-property-list, or the :visible form has to evaluate to a non-nil value. For the menu item to be enabled, it has to either lack a :enabled form in its item-property-list, or the :enable form has to evaluate to a non-nil value. Additionally, if the menu item is a radio button, then its selected form has to evaluate to nil for the menu item to be meaningful.
Source Code
;; Defined in /usr/src/emacs/lisp/wid-edit.el.gz
(defun widget--simplify-menu (extended)
"Convert the EXTENDED menu into a menu composed of simple menu items.
Each item in the simplified menu is of the form (ITEM-STRING . REAL-BINDING),
where both elements are taken from the EXTENDED MENU. ITEM-STRING is the
correspondent ITEM-NAME in the menu-item entry:
(menu-item ITEM-NAME REAL-BINDING . ITEM-PROPERTY-LIST), and REAL-BINDING is
the symbol in the key vector, as in `define-key'.
(See `(elisp)Defining Menus' for more information.)
Only visible, enabled and meaningful menu items make their way into
the returned simplified menu. That is:
For the menu item to be visible, it has to either lack a :visible form in its
item-property-list, or the :visible form has to evaluate to a non-nil value.
For the menu item to be enabled, it has to either lack a :enabled form in its
item-property-list, or the :enable form has to evaluate to a non-nil value.
Additionally, if the menu item is a radio button, then its selected form has
to evaluate to nil for the menu item to be meaningful."
(let (simplified)
(map-keymap (lambda (ev def)
(when (and (eq (nth 0 def) 'menu-item)
(nth 2 def)) ; Only menu-items with a real binding.
;; Loop through the item-property-list, looking for
;; :visible, :enable (or :active) and :button properties.
(let ((plist (nthcdr 3 def))
(enable t) ; Enabled by default.
(visible t) ; Visible by default.
selected keyword value)
(while (and plist (cdr plist)
(keywordp (setq keyword (car plist))))
(setq value (cadr plist))
(cond ((memq keyword '(:visible :included))
(setq visible value))
((memq keyword '(:enable :active))
(setq enable value))
((and (eq keyword :button)
(eq (car value) :radio))
(setq selected (cdr value))))
(setq plist (cddr plist)))
(when (and (eval visible t)
(eval enable t)
(or (not selected)
(not (eval selected t))))
(push (cons (nth 1 def) ev) simplified)))))
extended)
(reverse simplified)))