Function: widget-radio-add-item

widget-radio-add-item is a byte-compiled function defined in wid-edit.el.gz.

Signature

(widget-radio-add-item WIDGET TYPE)

Documentation

Add to radio widget WIDGET a new radio button item of type TYPE.

Source Code

;; Defined in /usr/src/emacs/lisp/wid-edit.el.gz
(defun widget-radio-add-item (widget type)
  "Add to radio widget WIDGET a new radio button item of type TYPE."
  ;; (setq type (widget-convert type))
  (and (widget--should-indent-p)
       (widget-get widget :indent)
       (insert-char ?\s (widget-get widget :indent)))
  (widget-specify-insert
   (let* ((value (widget-get widget :value))
	  (children (widget-get widget :children))
	  (buttons (widget-get widget :buttons))
	  (button-args (or (widget-get type :sibling-args)
			   (widget-get widget :button-args)))
          (str (widget-get widget :entry-format))
          (onext 0) (next 0)
	  (chosen (and (null (widget-get widget :choice))
		       (widget-apply type :match value)))
	  child button)
     ;; Parse % escapes in format.
     (while (string-match "%\\([bv%]\\)" str next)
       (setq next (match-end 1))
       (when (/= (- next onext) 2)
         (insert (substring str onext (- next 2))))
       (let ((escape (string-to-char (match-string 1 str))))
	 (cond ((eq escape ?%)
		(insert ?%))
	       ((eq escape ?b)
		(setq button (apply #'widget-create-child-and-convert
				    widget 'radio-button
				    :value (not (null chosen))
				    button-args)))
	       ((eq escape ?v)
		(setq child (if chosen
				(widget-create-child-value
				 widget type value)
			      (widget-create-child widget type)))
                (if chosen
                    (widget-specify-selected child)
                  (let ((from (widget-get child :from))
			(to (widget-get child :to)))
                    (widget-specify-unselected child from to))))
	       (t
		(error "Unknown escape `%c'" escape))))
       (setq onext next))
     (when (> (length str) next)
       (insert (substring str next)))
     ;; Update properties.
     (when chosen
       (widget-put widget :choice type))
     (when button
       (widget-put child :button button)
       (widget-put widget :buttons (nconc buttons (list button))))
     (when child
       (widget-put widget :children (nconc children (list child))))
     child)))