Function: widget-editable-list-entry-create

widget-editable-list-entry-create is a byte-compiled function defined in wid-edit.el.gz.

Signature

(widget-editable-list-entry-create WIDGET VALUE CONV)

Source Code

;; Defined in /usr/src/emacs/lisp/wid-edit.el.gz
(defun widget-editable-list-entry-create (widget value conv)
  ;; Create a new entry to the list.
  (let ((type (nth 0 (widget-get widget :args)))
	;; (widget-push-button-gui widget-editable-list-gui)
        (str (widget-get widget :entry-format))
        (onext 0) (next 0)
	child delete insert)
    (widget-specify-insert
     (and (widget--should-indent-p)
          (widget-get widget :indent)
          (insert-char ?\s (widget-get widget :indent)))
     ;; Parse % escapes in format.
     (while (string-match "%\\(.\\)" 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 ?i)
		(setq insert (apply #'widget-create-child-and-convert
				    widget 'insert-button
				    (widget-get widget :insert-button-args))))
	       ((eq escape ?d)
		(setq delete (apply #'widget-create-child-and-convert
				    widget 'delete-button
				    (widget-get widget :delete-button-args))))
	       ((eq escape ?v)
		(setq child (widget-create-child-value
                             widget type
                             (if conv value (widget-default-get type)))))
	       (t
		(error "Unknown escape `%c'" escape))))
       (setq onext next))
     (when (> (length str) next)
       (insert (substring str next)))
     (let ((buttons (widget-get widget :buttons)))
       (if insert (push insert buttons))
       (if delete (push delete buttons))
       (widget-put widget :buttons buttons))
     ;; After creating the entry, we must check if we should indent the
     ;; following entry.  This is necessary, for example, to keep the correct
     ;; indentation of editable lists inside group widgets.
     (and (widget--should-indent-p t)
          (widget-get widget :indent)
          (insert-char ?\s (widget-get widget :indent)))
     (let ((entry-from (point-min-marker))
	   (entry-to (point-max-marker)))
       (set-marker-insertion-type entry-from t)
       (set-marker-insertion-type entry-to nil)
       (widget-put child :entry-from entry-from)
       (widget-put child :entry-to entry-to)))
    (if insert (widget-put insert :widget child))
    (if delete (widget-put delete :widget child))
    child))