Function: widget-checklist-add-item

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

Signature

(widget-checklist-add-item WIDGET TYPE CHOSEN)

Documentation

Create checklist item in WIDGET of type TYPE.

If the item is checked, CHOSEN is a cons whose cdr is the value.

Source Code

;; Defined in /usr/src/emacs/lisp/wid-edit.el.gz
(defun widget-checklist-add-item (widget type chosen)
  "Create checklist item in WIDGET of type TYPE.
If the item is checked, CHOSEN is a cons whose cdr is the value."
  (and (widget--should-indent-p)
       (widget-get widget :indent)
       (insert-char ?\s (widget-get widget :indent)))
  (widget-specify-insert
   (let* ((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)
	  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 'checkbox
				    :value (not (null chosen))
				    button-args)))
	       ((eq escape ?v)
		(setq child
		      (cond ((not chosen)
			     (let* ((child (widget-create-child widget type))
                                    (from (widget-get child :from))
                                    (to (widget-get child :to)))
                               (widget-specify-unselected child from to)
			       child))
                            ((widget-inline-p type t)
			     (widget-create-child-value
			      widget type (cdr chosen)))
			    (t
                             (widget-specify-selected child)
                             (widget-create-child-value
                              widget type (car (cdr chosen)))))))
	       (t
		(error "Unknown escape `%c'" escape))))
       (setq onext next))
     (when (> (length str) next)
       (insert (substring str next)))
     ;; Update properties.
     (and button child (widget-put child :button button))
     (and button (widget-put widget :buttons (cons button buttons)))
     (and child (widget-put widget :children (cons child children))))))