Function: widget-default-create
widget-default-create is a byte-compiled function defined in
wid-edit.el.gz.
Signature
(widget-default-create WIDGET)
Documentation
Create WIDGET at point in the current buffer.
Source Code
;; Defined in /usr/src/emacs/lisp/wid-edit.el.gz
(defun widget-default-create (widget)
"Create WIDGET at point in the current buffer."
(widget-specify-insert
(let ((str (widget-get widget :format))
(onext 0) (next 0)
button-begin button-end
sample-begin sample-end
doc-begin doc-end
value-pos
(markers (widget--prepare-markers-for-inside-insertion widget)))
;; Parse escapes in format.
(while (string-match "%\\(.\\)" str next)
(setq next (match-end 1))
;; If we skipped some literal text, insert it.
(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 ?\[)
(setq button-begin (point))
(insert (widget-get-indirect widget :button-prefix)))
((eq escape ?\])
(insert (widget-get-indirect widget :button-suffix))
(setq button-end (point)))
((eq escape ?\{)
(setq sample-begin (point)))
((eq escape ?\})
(setq sample-end (point)))
((eq escape ?n)
(when (widget-get widget :indent)
(insert ?\n)
(insert-char ?\s (widget-get widget :indent))))
((eq escape ?t)
(let ((image (widget-get widget :tag-glyph))
(tag (substitute-command-keys
(widget-get widget :tag))))
(cond (image
(widget-image-insert widget (or tag "image") image))
(tag
(insert tag))
(t
(princ (widget-get widget :value)
(current-buffer))))))
((eq escape ?d)
(let ((doc (widget-get widget :doc)))
(when doc
(setq doc-begin (point))
(insert (substitute-command-keys doc))
(while (eq (preceding-char) ?\n)
(delete-char -1))
(insert ?\n)
(setq doc-end (point)))))
((eq escape ?h)
(widget-add-documentation-string-button widget))
((eq escape ?v)
(if (and button-begin (not button-end))
(widget-apply widget :value-create)
(setq value-pos (point))))
(t
(widget-apply widget :format-handler escape))))
(setq onext next))
;; Insert remaining literal text, if any.
(when (> (length str) next)
(insert (substring str next)))
;; Specify button, sample, and doc, and insert value.
(and button-begin button-end
(widget-specify-button widget button-begin button-end))
(and sample-begin sample-end
(widget-specify-sample widget sample-begin sample-end))
(and doc-begin doc-end
(widget-specify-doc widget doc-begin doc-end))
(when value-pos
(goto-char value-pos)
(widget-apply widget :value-create))
(widget--revert-markers-for-outside-insertion markers))
(let ((from (point-min-marker))
(to (point-max-marker)))
(set-marker-insertion-type from t)
(set-marker-insertion-type to nil)
(widget-put widget :from from)
(widget-put widget :to to)))
(widget-clear-undo))