Update copyright notices for 2013.
[emacs.git] / doc / misc / widget.texi
blob816ee6abf8b5040d4dc4be1322641f02683bde4c
1 \input texinfo.tex
2 @c %**start of header
3 @setfilename ../../info/widget
4 @settitle The Emacs Widget Library
5 @syncodeindex fn cp
6 @syncodeindex vr cp
7 @syncodeindex ky cp
8 @c %**end of header
10 @copying
11 Copyright @copyright{} 2000--2013 Free Software Foundation, Inc.
13 @quotation
14 Permission is granted to copy, distribute and/or modify this document
15 under the terms of the GNU Free Documentation License, Version 1.3 or
16 any later version published by the Free Software Foundation; with no
17 Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
18 and with the Back-Cover Texts as in (a) below.  A copy of the license
19 is included in the section entitled ``GNU Free Documentation License''.
21 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
22 modify this GNU manual.''
23 @end quotation
24 @end copying
26 @dircategory Emacs lisp libraries
27 @direntry
28 * Widget: (widget).             The "widget" package used by the Emacs
29                                   Customization facility.
30 @end direntry
32 @contents
34 @node Top, Introduction, (dir), (dir)
35 @comment  node-name,  next,  previous,  up
36 @top The Emacs Widget Library
38 @insertcopying
40 @menu
41 * Introduction::
42 * User Interface::
43 * Programming Example::
44 * Setting Up the Buffer::
45 * Basic Types::
46 * Sexp Types::
47 * Widget Properties::
48 * Defining New Widgets::
49 * Widget Browser::
50 * Widget Minor Mode::
51 * Utilities::
52 * Widget Wishlist::
53 * GNU Free Documentation License::
54 * Index::
55 @end menu
57 @node  Introduction, User Interface, Top, Top
58 @comment  node-name,  next,  previous,  up
59 @section Introduction
61 Most graphical user interface toolkits provide a number of standard
62 user interface controls (sometimes known as `widgets' or `gadgets').
63 Emacs doesn't really support anything like this, except for an
64 incredibly powerful text ``widget.''  On the other hand, Emacs does
65 provide the necessary primitives to implement many other widgets
66 within a text buffer.  The @code{widget} package simplifies this task.
68 @cindex basic widgets
69 @cindex widgets, basic types
70 The basic widgets are:
72 @table @code
73 @item link
74 Areas of text with an associated action.  Intended for hypertext links
75 embedded in text.
76 @item push-button
77 Like link, but intended for stand-alone buttons.
78 @item editable-field
79 An editable text field.  It can be either variable or fixed length.
80 @item menu-choice
81 Allows the user to choose one of multiple options from a menu, each
82 option is itself a widget.  Only the selected option will be visible in
83 the buffer.
84 @item radio-button-choice
85 Allows the user to choose one of multiple options by activating radio
86 buttons.  The options are implemented as widgets.  All options will be
87 visible in the buffer.
88 @item item
89 A simple constant widget intended to be used in the @code{menu-choice} and
90 @code{radio-button-choice} widgets.
91 @item choice-item
92 A button item only intended for use in choices.  When invoked, the user
93 will be asked to select another option from the choice widget.
94 @item toggle
95 A simple @samp{on}/@samp{off} switch.
96 @item checkbox
97 A checkbox (@samp{[ ]}/@samp{[X]}).
98 @item editable-list
99 Create an editable list.  The user can insert or delete items in the
100 list.  Each list item is itself a widget.
101 @end table
103 Now, of what possible use can support for widgets be in a text editor?
104 I'm glad you asked.  The answer is that widgets are useful for
105 implementing forms.  A @dfn{form} in Emacs is a buffer where the user is
106 supposed to fill out a number of fields, each of which has a specific
107 meaning.  The user is not supposed to change or delete any of the text
108 between the fields.  Examples of forms in Emacs are the @file{forms}
109 package (of course), the customize buffers, the mail and news compose
110 modes, and the @acronym{HTML} form support in the @file{w3} browser.
112 @cindex widget library, why use it
113 The advantages for a programmer of using the @code{widget} package to
114 implement forms are:
116 @enumerate
117 @item
118 More complex fields than just editable text are supported.
119 @item
120 You can give the users immediate feedback if they enter invalid data in a
121 text field, and sometimes prevent entering invalid data.
122 @item
123 You can have fixed sized fields, thus allowing multiple fields to be
124 lined up in columns.
125 @item
126 It is simple to query or set the value of a field.
127 @item
128 Editing happens in the buffer, not in the mini-buffer.
129 @item
130 Packages using the library get a uniform look, making them easier for
131 the user to learn.
132 @item
133 As support for embedded graphics improve, the widget library will be
134 extended to use the GUI features.  This means that your code using the
135 widget library will also use the new graphic features automatically.
136 @end enumerate
138 @node User Interface, Programming Example, Introduction, Top
139 @comment  node-name,  next,  previous,  up
140 @section User Interface
142 A form consists of read only text for documentation and some fields,
143 where each field contains two parts, a tag and a value.  The tags are
144 used to identify the fields, so the documentation can refer to the
145 @samp{foo field}, meaning the field tagged with @samp{Foo}. Here is an
146 example form:
148 @example
149 Here is some documentation.
151 Name: @i{My Name}     @strong{Choose}: This option
152 Address:  @i{Some Place
153 In some City
154 Some country.}
156 See also @b{_other work_} for more information.
158 Numbers: count to three below
159 @b{[INS]} @b{[DEL]} @i{One}
160 @b{[INS]} @b{[DEL]} @i{Eh, two?}
161 @b{[INS]} @b{[DEL]} @i{Five!}
162 @b{[INS]}
164 Select multiple:
166 @b{[X]} This
167 @b{[ ]} That
168 @b{[X]} Thus
170 Select one:
172 @b{(*)} One
173 @b{( )} Another One.
174 @b{( )} A Final One.
176 @b{[Apply Form]} @b{[Reset Form]}
177 @end example
179 The top level widgets in this example are tagged @samp{Name},
180 @samp{Choose}, @samp{Address}, @samp{_other work_}, @samp{Numbers},
181 @samp{Select multiple}, @samp{Select one}, @samp{[Apply Form]}, and
182 @samp{[Reset Form]}.  There are basically two things the user can do
183 within a form, namely editing the editable text fields and activating
184 the buttons.
186 @subsection Editable Text Fields
188 In the example, the value for the @samp{Name} is most likely displayed
189 in an editable text field, and so are values for each of the members of
190 the @samp{Numbers} list.  All the normal Emacs editing operations are
191 available for editing these fields.  The only restriction is that each
192 change you make must be contained within a single editable text field.
193 For example, capitalizing all text from the middle of one field to the
194 middle of another field is prohibited.
196 Editable text fields are created by the @code{editable-field} widget.
198 @strong{Warning:} In an @code{editable-field} widget, the editable
199 field must not be adjacent to another widget---that won't work.
200 You must put some text in between.  Either make this text part of
201 the @code{editable-field} widget itself, or insert it with
202 @code{widget-insert}.
204 The @code{:format} keyword is useful for generating the necessary
205 text; for instance, if you give it a value of @code{"Name: %v "},
206 the @samp{Name: } part will provide the necessary separating text
207 before the field and the trailing space will provide the
208 separating text after the field.  If you don't include the
209 @code{:size} keyword, the field will extend to the end of the
210 line, and the terminating newline will provide separation after.
212 @strong{Warning:} In an @code{editable-field} widget, the @samp{%v} escape
213 must be preceded by some other text in the @code{:format} string
214 (if specified).
216 The editing text fields are highlighted with the
217 @code{widget-field-face} face, making them easy to find.
219 @deffn Face widget-field-face
220 Face used for other editing fields.
221 @end deffn
223 @subsection Buttons
225 @cindex widget buttons
226 @cindex button widgets
227 Some portions of the buffer have an associated @dfn{action}, which can
228 be @dfn{invoked} by a standard key or mouse command.  These portions
229 are called @dfn{buttons}.  The default commands for activating a button
230 are:
232 @table @kbd
233 @item @key{RET}
234 @deffn Command widget-button-press @var{pos} &optional @var{event}
235 Invoke the button at @var{pos}, defaulting to point.
236 If point is not located on a button, invoke the binding in
237 @code{widget-global-map} (by default the global map).
238 @end deffn
240 @kindex Mouse-2 @r{(on button widgets})
241 @item Mouse-2
242 @deffn Command widget-button-click @var{event}
243 Invoke the button at the location of the mouse pointer.  If the mouse
244 pointer is located in an editable text field, invoke the binding in
245 @code{widget-global-map} (by default the global map).
246 @end deffn
247 @end table
249 There are several different kind of buttons, all of which are present in
250 the example:
252 @table @emph
253 @cindex option field tag
254 @item The Option Field Tags
255 When you invoke one of these buttons, you will be asked to choose
256 between a number of different options.  This is how you edit an option
257 field.  Option fields are created by the @code{menu-choice} widget.  In
258 the example, @samp{@b{Choose}} is an option field tag.
259 @item The @samp{@b{[INS]}} and @samp{@b{[DEL]}} buttons
260 Activating these will insert or delete elements from an editable list.
261 The list is created by the @code{editable-list} widget.
262 @cindex embedded buttons
263 @item Embedded Buttons
264 The @samp{@b{_other work_}} is an example of an embedded
265 button.  Embedded buttons are not associated with any fields, but can serve
266 any purpose, such as implementing hypertext references.  They are
267 usually created by the @code{link} widget.
268 @item The @samp{@b{[ ]}} and @samp{@b{[X]}} buttons
269 Activating one of these will convert it to the other.  This is useful
270 for implementing multiple-choice fields.  You can create them with the
271 @code{checkbox} widget.
272 @item The @samp{@b{( )}} and @samp{@b{(*)}} buttons
273 Only one radio button in a @code{radio-button-choice} widget can be
274 selected at any time.  When you invoke one of the unselected radio
275 buttons, it will be selected and the previous selected radio button will
276 become unselected.
277 @item The @samp{@b{[Apply Form]}} and @samp{@b{[Reset Form]}} buttons
278 These are explicit buttons made with the @code{push-button} widget.  The
279 main difference from the @code{link} widget is that the buttons will be
280 displayed as GUI buttons when possible.
281 @end table
283 To make them easier to locate, buttons are emphasized in the buffer.
285 @deffn Face widget-button-face
286 Face used for buttons.
287 @end deffn
289 @defopt widget-mouse-face
290 Face used for highlighting a button when the mouse pointer moves across
292 @end defopt
294 @subsection Navigation
296 You can use all the normal Emacs commands to move around in a form
297 buffer, plus you will have these additional commands:
299 @table @kbd
300 @item @key{TAB}
301 @deffn Command widget-forward &optional count
302 Move point @var{count} buttons or editing fields forward.
303 @end deffn
304 @item @kbd{M-@key{TAB}}
305 @itemx @kbd{S-@key{TAB}}
306 @deffn Command widget-backward &optional count
307 Move point @var{count} buttons or editing fields backward.
308 @end deffn
309 @end table
311 @node Programming Example, Setting Up the Buffer, User Interface, Top
312 @comment  node-name,  next,  previous,  up
313 @section Programming Example
315 @cindex widgets, programming example
316 @cindex example of using widgets
317 Here is the code to implement the user interface example (@pxref{User
318 Interface}).
320 @lisp
321 (require 'widget)
323 (eval-when-compile
324   (require 'wid-edit))
326 (defvar widget-example-repeat)
328 (defun widget-example ()
329   "Create the widgets from the Widget manual."
330   (interactive)
331   (switch-to-buffer "*Widget Example*")
332   (kill-all-local-variables)
333   (make-local-variable 'widget-example-repeat)
334   (let ((inhibit-read-only t))
335     (erase-buffer))
336   (remove-overlays)
337   (widget-insert "Here is some documentation.\n\n")
338   (widget-create 'editable-field
339                  :size 13
340                  :format "Name: %v " ; Text after the field!
341                  "My Name")
342   (widget-create 'menu-choice
343                  :tag "Choose"
344                  :value "This"
345                  :help-echo "Choose me, please!"
346                  :notify (lambda (widget &rest ignore)
347                            (message "%s is a good choice!"
348                                     (widget-value widget)))
349                  '(item :tag "This option" :value "This")
350                  '(choice-item "That option")
351                  '(editable-field :menu-tag "No option" "Thus option"))
352   (widget-create 'editable-field
353                  :format "Address: %v"
354                  "Some Place\nIn some City\nSome country.")
355   (widget-insert "\nSee also ")
356   (widget-create 'link
357                  :notify (lambda (&rest ignore)
358                            (widget-value-set widget-example-repeat
359                                              '("En" "To" "Tre"))
360                            (widget-setup))
361                  "other work")
362   (widget-insert
363     " for more information.\n\nNumbers: count to three below\n")
364   (setq widget-example-repeat
365         (widget-create 'editable-list
366                        :entry-format "%i %d %v"
367                        :notify
368                        (lambda (widget &rest ignore)
369                          (let ((old (widget-get widget
370                                                 ':example-length))
371                                (new (length (widget-value widget))))
372                            (unless (eq old new)
373                              (widget-put widget ':example-length new)
374                              (message "You can count to %d." new))))
375                        :value '("One" "Eh, two?" "Five!")
376                        '(editable-field :value "three")))
377   (widget-insert "\n\nSelect multiple:\n\n")
378   (widget-create 'checkbox t)
379   (widget-insert " This\n")
380   (widget-create 'checkbox nil)
381   (widget-insert " That\n")
382   (widget-create 'checkbox
383                  :notify (lambda (&rest ignore) (message "Tickle"))
384                  t)
385   (widget-insert " Thus\n\nSelect one:\n\n")
386   (widget-create 'radio-button-choice
387                  :value "One"
388                  :notify (lambda (widget &rest ignore)
389                            (message "You selected %s"
390                                     (widget-value widget)))
391                  '(item "One") '(item "Another One.")
392                  '(item "A Final One."))
393   (widget-insert "\n")
394   (widget-create 'push-button
395                  :notify (lambda (&rest ignore)
396                            (if (= (length
397                                    (widget-value widget-example-repeat))
398                                   3)
399                                (message "Congratulation!")
400                              (error "Three was the count!")))
401                  "Apply Form")
402   (widget-insert " ")
403   (widget-create 'push-button
404                  :notify (lambda (&rest ignore)
405                            (widget-example))
406                  "Reset Form")
407   (widget-insert "\n")
408   (use-local-map widget-keymap)
409   (widget-setup))
410 @end lisp
412 @node Setting Up the Buffer, Basic Types, Programming Example, Top
413 @comment  node-name,  next,  previous,  up
414 @section Setting Up the Buffer
416 Widgets are created with @code{widget-create}, which returns a
417 @dfn{widget} object.  This object can be queried and manipulated by
418 other widget functions, until it is deleted with @code{widget-delete}.
419 After the widgets have been created, @code{widget-setup} must be called
420 to enable them.
422 @defun widget-create type [ keyword argument ]@dots{}
423 Create and return a widget of type @var{type}.
424 The syntax for the @var{type} argument is described in @ref{Basic Types}.
426 The keyword arguments can be used to overwrite the keyword arguments
427 that are part of @var{type}.
428 @end defun
430 @defun widget-delete widget
431 Delete @var{widget} and remove it from the buffer.
432 @end defun
434 @defun widget-setup
435 Set up a buffer to support widgets.
437 This should be called after creating all the widgets and before allowing
438 the user to edit them.
439 @refill
440 @end defun
442 If you want to insert text outside the widgets in the form, the
443 recommended way to do that is with @code{widget-insert}.
445 @defun widget-insert
446 Insert the arguments, either strings or characters, at point.
447 The inserted text will be read-only.
448 @end defun
450 There is a standard widget keymap which you might find useful.
452 @findex widget-button-press
453 @findex widget-button-click
454 @defvr Const widget-keymap
455 @key{TAB} and @kbd{C-@key{TAB}} are bound to @code{widget-forward} and
456 @code{widget-backward}, respectively.  @key{RET} and @kbd{Mouse-2}
457 are bound to @code{widget-button-press} and
458 @code{widget-button-click}.@refill
459 @end defvr
461 @defvar widget-global-map
462 Keymap used by @code{widget-button-press} and @code{widget-button-click}
463 when not on a button.  By default this is @code{global-map}.
464 @end defvar
466 @node Basic Types, Sexp Types, Setting Up the Buffer, Top
467 @comment  node-name,  next,  previous,  up
468 @section Basic Types
470 This is the general syntax of a type specification:
472 @example
473 @var{name} ::= (@var{name} [@var{keyword} @var{argument}]... @var{args})
474      |   @var{name}
475 @end example
477 Where, @var{name} is a widget name, @var{keyword} is the name of a
478 property, @var{argument} is the value of the property, and @var{args}
479 are interpreted in a widget specific way.
481 @cindex keyword arguments
482 The following keyword arguments apply to all widgets:
484 @table @code
485 @vindex value@r{ keyword}
486 @item :value
487 The initial value for widgets of this type.
489 @vindex format@r{ keyword}
490 @item :format
491 This string will be inserted in the buffer when you create a widget.
492 The following @samp{%} escapes are available:
494 @table @samp
495 @item %[
496 @itemx %]
497 The text inside will be marked as a button.
499 By default, the text will be shown in @code{widget-button-face}, and
500 surrounded by brackets.
502 @defopt widget-button-prefix
503 String to prefix buttons.
504 @end defopt
506 @defopt widget-button-suffix
507 String to suffix buttons.
508 @end defopt
510 @item %@{
511 @itemx %@}
512 The text inside will be displayed with the face specified by
513 @code{:sample-face}.
515 @item %v
516 This will be replaced with the buffer representation of the widget's
517 value.  What this is depends on the widget type.
519 @strong{Warning:} In an @code{editable-field} widget, the @samp{%v} escape
520 must be preceded by some other text in the format string (if specified).
522 @item %d
523 Insert the string specified by @code{:doc} here.
525 @item %h
526 Like @samp{%d}, with the following modifications: If the documentation
527 string is more than one line, it will add a button which will toggle
528 between showing only the first line, and showing the full text.
529 Furthermore, if there is no @code{:doc} property in the widget, it will
530 instead examine the @code{:documentation-property} property.  If it is a
531 lambda expression, it will be called with the widget's value as an
532 argument, and the result will be used as the documentation text.
534 @item %t
535 Insert the string specified by @code{:tag} here, or the @code{princ}
536 representation of the value if there is no tag.
538 @item %%
539 Insert a literal @samp{%}.
540 @end table
542 @vindex button-face@r{ keyword}
543 @item :button-face
544 Face used to highlight text inside %[ %] in the format.
546 @vindex button-prefix@r{ keyword}
547 @vindex button-suffix@r{ keyword}
548 @item :button-prefix
549 @itemx :button-suffix
550 Text around %[ %] in the format.
552 These can be
553 @table @emph
554 @item nil
555 No text is inserted.
557 @item a string
558 The string is inserted literally.
560 @item a symbol
561 The value of the symbol is expanded according to this table.
562 @end table
564 @vindex doc@r{ keyword}
565 @item :doc
566 The string inserted by the @samp{%d} escape in the format
567 string.
569 @vindex tag@r{ keyword}
570 @item :tag
571 The string inserted by the @samp{%t} escape in the format
572 string.
574 @vindex tag-glyph@r{ keyword}
575 @item :tag-glyph
576 Name of image to use instead of the string specified by @code{:tag} on
577 Emacsen that supports it.
579 @vindex help-echo@r{ keyword}
580 @item :help-echo
581 Specifies how to display a message whenever you move to the widget with
582 either @code{widget-forward} or @code{widget-backward} or move the mouse
583 over it (using the standard @code{help-echo} mechanism).  The argument
584 is either a string to display, a function of one argument, the widget,
585 which should return a string to display, or a form that evaluates to
586 such a string.
588 @vindex follow-link@r{ keyword}
589 @item :follow-link
590 Specifies how to interpret a @key{mouse-1} click on the widget.
591 @xref{Clickable Text,, Defining Clickable Text, elisp, the Emacs Lisp Reference Manual}.
593 @vindex indent@r{ keyword}
594 @item :indent
595 An integer indicating the absolute number of spaces to indent children
596 of this widget.
598 @vindex offset@r{ keyword}
599 @item :offset
600 An integer indicating how many extra spaces to add to the widget's
601 grandchildren compared to this widget.
603 @vindex extra-offset@r{ keyword}
604 @item :extra-offset
605 An integer indicating how many extra spaces to add to the widget's
606 children compared to this widget.
608 @vindex notify@r{ keyword}
609 @item :notify
610 A function called each time the widget or a nested widget is changed.
611 The function is called with two or three arguments.  The first argument
612 is the widget itself, the second argument is the widget that was
613 changed, and the third argument is the event leading to the change, if
614 any.
616 @vindex menu-tag@r{ keyword}
617 @item :menu-tag
618 Tag used in the menu when the widget is used as an option in a
619 @code{menu-choice} widget.
621 @vindex menu-tag-get@r{ keyword}
622 @item :menu-tag-get
623 Function used for finding the tag when the widget is used as an option
624 in a @code{menu-choice} widget.  By default, the tag used will be either the
625 @code{:menu-tag} or @code{:tag} property if present, or the @code{princ}
626 representation of the @code{:value} property if not.
628 @vindex match@r{ keyword}
629 @item :match
630 Should be a function called with two arguments, the widget and a value,
631 and returning non-@code{nil} if the widget can represent the specified value.
633 @vindex validate@r{ keyword}
634 @item :validate
635 A function which takes a widget as an argument, and returns @code{nil}
636 if the widget's current value is valid for the widget.  Otherwise it
637 should return the widget containing the invalid data, and set that
638 widget's @code{:error} property to a string explaining the error.
640 The following predefined function can be used:
642 @defun widget-children-validate widget
643 All the @code{:children} of @var{widget} must be valid.
644 @end defun
646 @vindex tab-order@r{ keyword}
647 @item :tab-order
648 Specify the order in which widgets are traversed with
649 @code{widget-forward} or @code{widget-backward}.  This is only partially
650 implemented.
652 @enumerate a
653 @item
654 Widgets with tabbing order @code{-1} are ignored.
656 @item
657 (Unimplemented) When on a widget with tabbing order @var{n}, go to the
658 next widget in the buffer with tabbing order @var{n+1} or @code{nil},
659 whichever comes first.
661 @item
662 When on a widget with no tabbing order specified, go to the next widget
663 in the buffer with a positive tabbing order, or @code{nil}
664 @end enumerate
666 @vindex parent@r{ keyword}
667 @item :parent
668 The parent of a nested widget (e.g., a @code{menu-choice} item or an
669 element of a @code{editable-list} widget).
671 @vindex sibling-args@r{ keyword}
672 @item :sibling-args
673 This keyword is only used for members of a @code{radio-button-choice} or
674 @code{checklist}.  The value should be a list of extra keyword
675 arguments, which will be used when creating the @code{radio-button} or
676 @code{checkbox} associated with this item.
678 @end table
680 @deffn {User Option} widget-glyph-directory
681 Directory where glyphs are found.
682 Widget will look here for a file with the same name as specified for the
683 image, with either a @file{.xpm} (if supported) or @file{.xbm} extension.
684 @end deffn
686 @deffn{User Option} widget-glyph-enable
687 If non-@code{nil}, allow glyphs to appear on displays where they are supported.
688 @end deffn
691 @menu
692 * link::
693 * url-link::
694 * info-link::
695 * push-button::
696 * editable-field::
697 * text::
698 * menu-choice::
699 * radio-button-choice::
700 * item::
701 * choice-item::
702 * toggle::
703 * checkbox::
704 * checklist::
705 * editable-list::
706 * group::
707 @end menu
709 @node link, url-link, Basic Types, Basic Types
710 @comment  node-name,  next,  previous,  up
711 @subsection The @code{link} Widget
712 @findex link@r{ widget}
714 Syntax:
716 @example
717 @var{type} ::= (link [@var{keyword} @var{argument}]...  [ @var{value} ])
718 @end example
720 The @var{value}, if present, is used to initialize the @code{:value}
721 property.  The value should be a string, which will be inserted in the
722 buffer.
724 By default the link will be shown in brackets.
726 @defopt widget-link-prefix
727 String to prefix links.
728 @end defopt
730 @defopt widget-link-suffix
731 String to suffix links.
732 @end defopt
734 @node url-link, info-link, link, Basic Types
735 @comment  node-name,  next,  previous,  up
736 @subsection The @code{url-link} Widget
737 @findex url-link@r{ widget}
739 Syntax:
741 @example
742 @var{type} ::= (url-link [@var{keyword} @var{argument}]...  @var{url})
743 @end example
745 @findex browse-url-browser-function@r{, and @code{url-link} widget}
746 When this link is invoked, the @acronym{WWW} browser specified by
747 @code{browse-url-browser-function} will be called with @var{url}.
749 @node info-link, push-button, url-link, Basic Types
750 @comment  node-name,  next,  previous,  up
751 @subsection The @code{info-link} Widget
752 @findex info-link@r{ widget}
754 Syntax:
756 @example
757 @var{type} ::= (info-link [@var{keyword} @var{argument}]...  @var{address})
758 @end example
760 When this link is invoked, the built-in Info reader is started on
761 @var{address}.
763 @node  push-button, editable-field, info-link, Basic Types
764 @comment  node-name,  next,  previous,  up
765 @subsection The @code{push-button} Widget
766 @findex push-button@r{ widget}
768 Syntax:
770 @example
771 @var{type} ::= (push-button [@var{keyword} @var{argument}]...  [ @var{value} ])
772 @end example
774 The @var{value}, if present, is used to initialize the @code{:value}
775 property.  The value should be a string, which will be inserted in the
776 buffer.
778 By default the tag will be shown in brackets.
780 @defopt widget-push-button-prefix
781 String to prefix push buttons.
782 @end defopt
784 @defopt widget-push-button-suffix
785 String to suffix push buttons.
786 @end defopt
788 @node editable-field, text, push-button, Basic Types
789 @comment  node-name,  next,  previous,  up
790 @subsection The @code{editable-field} Widget
791 @findex editable-field@r{ widget}
793 Syntax:
795 @example
796 @var{type} ::= (editable-field [@var{keyword} @var{argument}]... [ @var{value} ])
797 @end example
799 The @var{value}, if present, is used to initialize the @code{:value}
800 property.  The value should be a string, which will be inserted in the
801 field.  This widget will match all string values.
803 The following extra properties are recognized:
805 @table @code
806 @vindex size@r{ keyword}
807 @item :size
808 The width of the editable field.@*
809 By default the field will reach to the end of the line.
811 @vindex value-face@r{ keyword}
812 @item :value-face
813 Face used for highlighting the editable field.  Default is
814 @code{widget-field-face}, see @ref{User Interface}.
816 @vindex secret@r{ keyword}
817 @item :secret
818 Character used to display the value.  You can set this to, e.g., @code{?*}
819 if the field contains a password or other secret information.  By
820 default, this is @code{nil}, and the value is not secret.
822 @vindex valid-regexp@r{ keyword}
823 @item :valid-regexp
824 By default the @code{:validate} function will match the content of the
825 field with the value of this attribute.  The default value is @code{""}
826 which matches everything.
828 @vindex keymap@r{ keyword}
829 @vindex widget-field-keymap
830 @item :keymap
831 Keymap used in the editable field.  The default value is
832 @code{widget-field-keymap}, which allows you to use all the normal
833 editing commands, even if the buffer's major mode suppresses some of
834 them.  Pressing @key{RET} invokes the function specified by
835 @code{:action}.
836 @end table
838 @node text, menu-choice, editable-field, Basic Types
839 @comment  node-name,  next,  previous,  up
840 @subsection The @code{text} Widget
841 @findex text@r{ widget}
843 @vindex widget-text-keymap
844 This is just like @code{editable-field}, but intended for multiline text
845 fields.  The default @code{:keymap} is @code{widget-text-keymap}, which
846 does not rebind the @key{RET} key.
848 @node menu-choice, radio-button-choice, text, Basic Types
849 @comment  node-name,  next,  previous,  up
850 @subsection The @code{menu-choice} Widget
851 @findex menu-choice@r{ widget}
853 Syntax:
855 @example
856 @var{type} ::= (menu-choice [@var{keyword} @var{argument}]... @var{type} ... )
857 @end example
859 The @var{type} argument represents each possible choice.  The widget's
860 value will be that of the chosen @var{type} argument.  This widget will
861 match any value matching at least one of the specified @var{type}
862 arguments.
864 @table @code
865 @vindex void@r{ keyword}
866 @item :void
867 Widget type used as a fallback when the value does not match any of the
868 specified @var{type} arguments.
870 @vindex case-fold@r{ keyword}
871 @item :case-fold
872 Set this to @code{nil} if you don't want to ignore case when prompting for a
873 choice through the minibuffer.
875 @vindex children@r{ keyword}
876 @item :children
877 A list whose @sc{car} is the widget representing the currently chosen
878 type in the buffer.
880 @vindex choice@r{ keyword}
881 @item :choice
882 The current chosen type.
884 @vindex args@r{ keyword}
885 @item :args
886 The list of types.
887 @end table
889 @node radio-button-choice, item, menu-choice, Basic Types
890 @comment  node-name,  next,  previous,  up
891 @subsection The @code{radio-button-choice} Widget
892 @findex radio-button-choice@r{ widget}
894 Syntax:
896 @example
897 @var{type} ::= (radio-button-choice [@var{keyword} @var{argument}]...  @var{type} ... )
898 @end example
900 The component types specify the choices, with one radio button for
901 each.  The widget's value will be that of the chosen @var{type}
902 argument.  This widget matches any value that matches at least one of
903 the specified @var{type} arguments.
905 The following extra properties are recognized.
907 @table @code
908 @vindex entry-format@r{ keyword}
909 @item :entry-format
910 This string will be inserted for each entry in the list.
911 The following @samp{%} escapes are available:
912 @table @samp
913 @item %v
914 Replace with the buffer representation of the @var{type} widget.
915 @item %b
916 Replace with the radio button.
917 @item %%
918 Insert a literal @samp{%}.
919 @end table
921 @vindex button-args@r{ keyword}
922 @item :button-args
923 A list of keywords to pass to the radio buttons.  Useful for setting,
924 e.g., the @samp{:help-echo} for each button.
926 @vindex buttons@r{ keyword}
927 @item :buttons
928 The widgets representing the radio buttons.
930 @vindex children@r{ keyword}
931 @item :children
932 The widgets representing each type.
934 @vindex choice@r{ keyword}
935 @item :choice
936 The current chosen type
938 @vindex args@r{ keyword}
939 @item :args
940 The list of types.
941 @end table
943 You can add extra radio button items to a @code{radio-button-choice}
944 widget after it has been created with the function
945 @code{widget-radio-add-item}.
947 @defun widget-radio-add-item widget type
948 Add to @code{radio-button-choice} widget @var{widget} a new radio button
949 item of type @var{type}.
950 @end defun
952 Please note that such items added after the @code{radio-button-choice}
953 widget has been created will @strong{not} be properly destructed when
954 you call @code{widget-delete}.
956 @node item, choice-item, radio-button-choice, Basic Types
957 @comment  node-name,  next,  previous,  up
958 @subsection The @code{item} Widget
959 @findex item@r{ widget}
961 Syntax:
963 @example
964 @var{item} ::= (item [@var{keyword} @var{argument}]... @var{value})
965 @end example
967 The @var{value}, if present, is used to initialize the @code{:value}
968 property.  The value should be a string, which will be inserted in the
969 buffer.  This widget will only match the specified value.
971 @node choice-item, toggle, item, Basic Types
972 @comment  node-name,  next,  previous,  up
973 @subsection The @code{choice-item} Widget
974 @findex choice-item@r{ widget}
976 Syntax:
978 @example
979 @var{item} ::= (choice-item [@var{keyword} @var{argument}]... @var{value})
980 @end example
982 The @var{value}, if present, is used to initialize the @code{:value}
983 property.  The value should be a string, which will be inserted in the
984 buffer as a button.  Activating the button of a @code{choice-item} is
985 equivalent to activating the parent widget.  This widget will only match
986 the specified value.
988 @node toggle, checkbox, choice-item, Basic Types
989 @comment  node-name,  next,  previous,  up
990 @subsection The @code{toggle} Widget
991 @findex toggle@r{ widget}
993 Syntax:
995 @example
996 @var{type} ::= (toggle [@var{keyword} @var{argument}]...)
997 @end example
999 The widget has two possible states, @samp{on} and @samp{off}, which
1000 correspond to a @code{t} or @code{nil} value, respectively.
1002 The following extra properties are recognized:
1004 @table @code
1005 @item :on
1006 A string representing the @samp{on} state.  By default the string
1007 @samp{on}.
1008 @item :off
1009 A string representing the @samp{off} state.  By default the string
1010 @samp{off}.
1011 @vindex on-glyph@r{ keyword}
1012 @item :on-glyph
1013 Name of a glyph to be used instead of the @samp{:on} text string, on
1014 emacsen that supports this.
1015 @vindex off-glyph@r{ keyword}
1016 @item :off-glyph
1017 Name of a glyph to be used instead of the @samp{:off} text string, on
1018 emacsen that supports this.
1019 @end table
1021 @node checkbox, checklist, toggle, Basic Types
1022 @comment  node-name,  next,  previous,  up
1023 @subsection The @code{checkbox} Widget
1024 @findex checkbox@r{ widget}
1026 This widget has two possible states, @samp{selected} and
1027 @samp{unselected}, which corresponds to a @code{t} or @code{nil} value.
1029 Syntax:
1031 @example
1032 @var{type} ::= (checkbox [@var{keyword} @var{argument}]...)
1033 @end example
1035 @node checklist, editable-list, checkbox, Basic Types
1036 @comment  node-name,  next,  previous,  up
1037 @subsection The @code{checklist} Widget
1038 @findex checklist@r{ widget}
1040 Syntax:
1042 @example
1043 @var{type} ::= (checklist [@var{keyword} @var{argument}]...  @var{type} ... )
1044 @end example
1046 The @var{type} arguments represent each checklist item.  The widget's
1047 value will be a list containing the values of all checked @var{type}
1048 arguments.  The checklist widget will match a list whose elements all
1049 match at least one of the specified @var{type} arguments.
1051 The following extra properties are recognized:
1053 @table @code
1054 @vindex entry-format@r{ keyword}
1055 @item :entry-format
1056 This string will be inserted for each entry in the list.
1057 The following @samp{%} escapes are available:
1058 @table @samp
1059 @item %v
1060 Replaced with the buffer representation of the @var{type} widget.
1061 @item %b
1062 Replace with the checkbox.
1063 @item %%
1064 Insert a literal @samp{%}.
1065 @end table
1067 @vindex greedy@r{ keyword}
1068 @item :greedy
1069 Usually a checklist will only match if the items are in the exact
1070 sequence given in the specification.  By setting @code{:greedy} to
1071 non-@code{nil}, it will allow the items to come in any sequence.
1072 However, if you extract the value they will be in the sequence given
1073 in the checklist, i.e., the original sequence is forgotten.
1075 @vindex button-args@r{ keyword}
1076 @item :button-args
1077 A list of keywords to pass to the checkboxes.  Useful for setting,
1078 e.g., the @samp{:help-echo} for each checkbox.
1080 @vindex buttons@r{ keyword}
1081 @item :buttons
1082 The widgets representing the checkboxes.
1084 @vindex children@r{ keyword}
1085 @item :children
1086 The widgets representing each type.
1088 @vindex args@r{ keyword}
1089 @item :args
1090 The list of types.
1091 @end table
1093 @node editable-list, group, checklist, Basic Types
1094 @comment  node-name,  next,  previous,  up
1095 @subsection The @code{editable-list} Widget
1096 @findex editable-list@r{ widget}
1098 Syntax:
1100 @example
1101 @var{type} ::= (editable-list [@var{keyword} @var{argument}]... @var{type})
1102 @end example
1104 The value is a list, where each member represents one widget of type
1105 @var{type}.
1107 The following extra properties are recognized:
1109 @table @code
1110 @vindex entry-format@r{ keyword}
1111 @item :entry-format
1112 This string will be inserted for each entry in the list.
1113 The following @samp{%} escapes are available:
1114 @table @samp
1115 @item %v
1116 This will be replaced with the buffer representation of the @var{type}
1117 widget.
1118 @item %i
1119 Insert the @b{[INS]} button.
1120 @item %d
1121 Insert the @b{[DEL]} button.
1122 @item %%
1123 Insert a literal @samp{%}.
1124 @end table
1126 @vindex insert-button-args@r{ keyword}
1127 @item :insert-button-args
1128 A list of keyword arguments to pass to the insert buttons.
1130 @vindex delete-button-args@r{ keyword}
1131 @item :delete-button-args
1132 A list of keyword arguments to pass to the delete buttons.
1134 @vindex append-button-args@r{ keyword}
1135 @item :append-button-args
1136 A list of keyword arguments to pass to the trailing insert button.
1138 @vindex buttons@r{ keyword}
1139 @item :buttons
1140 The widgets representing the insert and delete buttons.
1142 @vindex children@r{ keyword}
1143 @item :children
1144 The widgets representing the elements of the list.
1146 @vindex args@r{ keyword}
1147 @item :args
1148 List whose @sc{car} is the type of the list elements.
1149 @end table
1151 @node group,  , editable-list, Basic Types
1152 @comment  node-name,  next,  previous,  up
1153 @subsection The @code{group} Widget
1154 @findex group@r{ widget}
1156 This widget simply group other widgets together.
1158 Syntax:
1160 @example
1161 @var{type} ::= (group [@var{keyword} @var{argument}]... @var{type}...)
1162 @end example
1164 The value is a list, with one member for each @var{type}.
1166 @node Sexp Types, Widget Properties, Basic Types, Top
1167 @comment
1168 @section Sexp Types
1169 @cindex sexp types
1171 A number of widgets for editing @dfn{s-expressions} (Lisp types), sexp
1172 for short, are also available.  These basically fall in several
1173 categories described in this section.
1175 @menu
1176 * constants::
1177 * generic::
1178 * atoms::
1179 * composite::
1180 @end menu
1182 @node constants, generic, Sexp Types, Sexp Types
1183 @comment  node-name,  next,  previous,  up
1184 @subsection The Constant Widgets
1185 @cindex constant widgets
1187 The @code{const} widget can contain any Lisp expression, but the user is
1188 prohibited from editing it, which is mainly useful as a component of one
1189 of the composite widgets.
1191 The syntax for the @code{const} widget is:
1193 @example
1194 @var{type} ::= (const [@var{keyword} @var{argument}]...  [ @var{value} ])
1195 @end example
1197 The @var{value}, if present, is used to initialize the @code{:value}
1198 property and can be any s-expression.
1200 @deffn Widget const
1201 This will display any valid s-expression in an immutable part of the
1202 buffer.
1203 @end deffn
1205 There are two variations of the @code{const} widget, namely
1206 @code{variable-item} and @code{function-item}.  These should contain a
1207 symbol with a variable or function binding.  The major difference from
1208 the @code{const} widget is that they will allow the user to see the
1209 variable or function documentation for the symbol.
1211 @deffn Widget variable-item
1212 An immutable symbol that is bound as a variable.
1213 @end deffn
1215 @deffn Widget function-item
1216 An immutable symbol that is bound as a function.
1217 @end deffn
1219 @node generic, atoms, constants, Sexp Types
1220 @comment  node-name,  next,  previous,  up
1221 @subsection Generic Sexp Widget
1222 @cindex generic sexp widget
1224 The @code{sexp} widget can contain any Lisp expression, and allows the
1225 user to edit it inline in the buffer.
1227 The syntax for the @code{sexp} widget is:
1229 @example
1230 @var{type} ::= (sexp [@var{keyword} @var{argument}]...  [ @var{value} ])
1231 @end example
1233 @deffn Widget sexp
1234 This will allow you to edit any valid s-expression in an editable buffer
1235 field.
1237 The @code{sexp} widget takes the same keyword arguments as the
1238 @code{editable-field} widget.  @xref{editable-field}.
1239 @end deffn
1241 @node atoms, composite, generic, Sexp Types
1242 @comment  node-name,  next,  previous,  up
1243 @subsection Atomic Sexp Widgets
1244 @cindex atomic sexp widget
1246 The atoms are s-expressions that do not consist of other s-expressions.
1247 For example, a string, a file name, or a symbol are atoms, while a list
1248 is a composite type.  You can edit the value of an atom with the
1249 following widgets.
1251 The syntax for all the atoms are:
1253 @example
1254 @var{type} ::= (@var{construct} [@var{keyword} @var{argument}]...  [ @var{value} ])
1255 @end example
1257 The @var{value}, if present, is used to initialize the @code{:value}
1258 property and must be an expression of the same type as the widget.
1259 That is, the string widget can only be initialized with a string.
1261 All the atom widgets take the same keyword arguments as the
1262 @code{editable-field} widget.  @xref{editable-field}.
1264 @deffn Widget string
1265 Allows you to edit a string in an editable field.
1266 @end deffn
1268 @deffn Widget regexp
1269 Allows you to edit a regular expression in an editable field.
1270 @end deffn
1272 @deffn Widget character
1273 Allows you to enter a character in an editable field.
1274 @end deffn
1276 @deffn Widget file
1277 Allows you to edit a file name in an editable field.
1279 Keywords:
1280 @table @code
1281 @vindex must-match@r{ keyword}
1282 @item :must-match
1283 If this is set to non-@code{nil}, only existing file names will be
1284 allowed in the minibuffer.
1285 @end table
1286 @end deffn
1288 @deffn Widget directory
1289 Allows you to edit a directory name in an editable field.
1290 Similar to the @code{file} widget.
1291 @end deffn
1293 @deffn Widget symbol
1294 Allows you to edit a Lisp symbol in an editable field.
1295 @end deffn
1297 @deffn Widget function
1298 Allows you to edit a lambda expression, or a function name with completion.
1299 @end deffn
1301 @deffn Widget variable
1302 Allows you to edit a variable name, with completion.
1303 @end deffn
1305 @deffn Widget integer
1306 Allows you to edit an integer in an editable field.
1307 @end deffn
1309 @deffn Widget number
1310 Allows you to edit a number in an editable field.
1311 @end deffn
1313 @deffn Widget boolean
1314 Allows you to edit a boolean.  In Lisp this means a variable which is
1315 either @code{nil} meaning false, or non-@code{nil} meaning true.
1316 @end deffn
1319 @node composite,  , atoms, Sexp Types
1320 @comment  node-name,  next,  previous,  up
1321 @subsection Composite Sexp Widgets
1322 @cindex composite sexp widgets
1324 The syntax for the composite widget construct is:
1326 @example
1327 @var{type} ::= (@var{construct} [@var{keyword} @var{argument}]...  @var{component}...)
1328 @end example
1330 @noindent
1331 where each @var{component} must be a widget type.  Each component widget
1332 will be displayed in the buffer, and will be editable by the user.
1334 @deffn Widget cons
1335 The value of a @code{cons} widget must be a cons-cell whose @sc{car}
1336 and @sc{cdr} have two specified types.  It uses this syntax:
1338 @example
1339 @var{type} ::= (cons [@var{keyword} @var{argument}]...  @var{car-type} @var{cdr-type})
1340 @end example
1341 @end deffn
1343 @deffn Widget choice
1344 The value matched by a @code{choice} widget must have one of a fixed
1345 set of types.  The widget's syntax is as follows:
1347 @example
1348 @var{type} ::= (choice [@var{keyword} @var{argument}]...  @var{type} ... )
1349 @end example
1351 The value of a @code{choice} widget can be anything that matches any of the
1352 @var{types}.
1353 @end deffn
1355 @deffn Widget list
1356 The value of a @code{list} widget must be a list whose element types
1357 match the specified component types:
1359 @example
1360 @var{type} ::= (list [@var{keyword} @var{argument}]...  @var{component-type}...)
1361 @end example
1363 Thus, @code{(list string number)} matches lists of two elements,
1364 the first being a string and the second being a number.
1365 @end deffn
1367 @deffn Widget vector
1368 The @code{vector} widget is like the @code{list} widget but matches
1369 vectors instead of lists.  Thus, @code{(vector string number)} matches
1370 vectors of two elements, the first being a string and the second being
1371 a number.
1372 @end deffn
1374 The above suffice for specifying fixed size lists and vectors.  To get
1375 variable length lists and vectors, you can use a @code{choice},
1376 @code{set}, or @code{repeat} widget together with the @code{:inline}
1377 keyword.  If any component of a composite widget has the
1378 @code{:inline} keyword set, its value must be a list which will then
1379 be spliced into the composite.  For example, to specify a list whose
1380 first element must be a file name, and whose remaining elements should
1381 either be the symbol @code{t} or two strings (file names), you can use
1382 the following widget specification:
1384 @example
1385 (list file
1386       (choice (const t)
1387               (list :inline t
1388                     :value ("foo" "bar")
1389                     string string)))
1390 @end example
1392 The value of a widget of this type will either have the form
1393 @code{(file t)} or @code{(file @var{string} @var{string})}.
1395 This concept of @code{:inline} may be hard to understand.  It was
1396 certainly hard to implement, so instead of confusing you more by
1397 trying to explain it here, I'll just suggest you meditate over it for
1398 a while.
1400 @deffn Widget set
1401 Specifies a type whose values are the lists whose elements all belong
1402 to a given set.  The order of elements of the list is not significant.
1403 Here's the syntax:
1405 @example
1406 @var{type} ::= (set [@var{keyword} @var{argument}]...  @var{permitted-element} ... )
1407 @end example
1409 Use @code{const} to specify each permitted element, like this:
1410 @code{(set (const a) (const b))}.
1411 @end deffn
1413 @deffn Widget repeat
1414 Specifies a list of any number of elements that fit a certain type.
1416 @example
1417 @var{type} ::= (repeat [@var{keyword} @var{argument}]...  @var{type})
1418 @end example
1419 @end deffn
1421 @node Widget Properties, Defining New Widgets, Sexp Types, Top
1422 @comment  node-name,  next,  previous,  up
1423 @section Properties
1424 @cindex properties of widgets
1425 @cindex widget properties
1427 You can examine or set the value of a widget by using the widget object
1428 that was returned by @code{widget-create}.
1430 @defun widget-value widget
1431 Return the current value contained in @var{widget}.
1432 It is an error to call this function on an uninitialized widget.
1433 @end defun
1435 @defun widget-value-set widget value
1436 Set the value contained in @var{widget} to @var{value}.
1437 It is an error to call this function with an invalid @var{value}.
1438 @end defun
1440 @strong{Important:} You @emph{must} call @code{widget-setup} after
1441 modifying the value of a widget before the user is allowed to edit the
1442 widget again.  It is enough to call @code{widget-setup} once if you
1443 modify multiple widgets.  This is currently only necessary if the widget
1444 contains an editing field, but may be necessary for other widgets in the
1445 future.
1447 If your application needs to associate some information with the widget
1448 objects, for example a reference to the item being edited, it can be
1449 done with @code{widget-put} and @code{widget-get}.  The property names
1450 must begin with a @samp{:}.
1452 @defun widget-put widget property value
1453 In @var{widget} set @var{property} to @var{value}.
1454 @var{property} should be a symbol, while @var{value} can be anything.
1455 @end defun
1457 @defun widget-get widget property
1458 In @var{widget} return the value for @var{property}.
1459 @var{property} should be a symbol, the value is what was last set by
1460 @code{widget-put} for @var{property}.
1461 @end defun
1463 @defun widget-member widget property
1464 Non-@code{nil} if @var{widget} has a value (even @code{nil}) for
1465 property @var{property}.
1466 @end defun
1468 Occasionally it can be useful to know which kind of widget you have,
1469 i.e., the name of the widget type you gave when the widget was created.
1471 @defun widget-type widget
1472 Return the name of @var{widget}, a symbol.
1473 @end defun
1475 @cindex active widget
1476 @cindex inactive widget
1477 @cindex activate a widget
1478 @cindex deactivate a widget
1479 Widgets can be in two states: active, which means they are modifiable by
1480 the user, or inactive, which means they cannot be modified by the user.
1481 You can query or set the state with the following code:
1483 @lisp
1484 ;; Examine if @var{widget} is active or not.
1485 (if (widget-apply @var{widget} :active)
1486     (message "Widget is active.")
1487   (message "Widget is inactive.")
1489 ;; Make @var{widget} inactive.
1490 (widget-apply @var{widget} :deactivate)
1492 ;; Make @var{widget} active.
1493 (widget-apply @var{widget} :activate)
1494 @end lisp
1496 A widget is inactive if it, or any of its ancestors (found by
1497 following the @code{:parent} link), have been deactivated.  To make sure
1498 a widget is really active, you must therefore activate both it and
1499 all its ancestors.
1501 @lisp
1502 (while widget
1503   (widget-apply widget :activate)
1504   (setq widget (widget-get widget :parent)))
1505 @end lisp
1507 You can check if a widget has been made inactive by examining the value
1508 of the @code{:inactive} keyword.  If this is non-@code{nil}, the widget itself
1509 has been deactivated.  This is different from using the @code{:active}
1510 keyword, in that the latter tells you if the widget @strong{or} any of
1511 its ancestors have been deactivated.  Do not attempt to set the
1512 @code{:inactive} keyword directly.  Use the @code{:activate}
1513 @code{:deactivate} keywords instead.
1516 @node Defining New Widgets, Widget Browser, Widget Properties, Top
1517 @comment  node-name,  next,  previous,  up
1518 @section Defining New Widgets
1519 @cindex new widgets
1520 @cindex defining new widgets
1522 You can define specialized widgets with @code{define-widget}.  It allows
1523 you to create a shorthand for more complex widgets, including specifying
1524 component widgets and new default values for the keyword
1525 arguments.
1527 @defun define-widget name class doc &rest args
1528 Define a new widget type named @var{name} from @code{class}.
1530 @var{name} and class should both be symbols, @code{class} should be one
1531 of the existing widget types.
1533 The third argument @var{doc} is a documentation string for the widget.
1535 After the new widget has been defined, the following two calls will
1536 create identical widgets:
1538 @itemize @bullet
1539 @item
1540 @lisp
1541 (widget-create @var{name})
1542 @end lisp
1544 @item
1545 @lisp
1546 (apply widget-create @var{class} @var{args})
1547 @end lisp
1548 @end itemize
1550 @end defun
1552 Using @code{define-widget} just stores the definition of the widget type
1553 in the @code{widget-type} property of @var{name}, which is what
1554 @code{widget-create} uses.
1556 If you only want to specify defaults for keywords with no complex
1557 conversions, you can use @code{identity} as your conversion function.
1559 The following additional keyword arguments are useful when defining new
1560 widgets:
1561 @table @code
1562 @vindex convert-widget@r{ keyword}
1563 @item :convert-widget
1564 Function to convert a widget type before creating a widget of that
1565 type.  It takes a widget type as an argument, and returns the converted
1566 widget type.  When a widget is created, this function is called for the
1567 widget type and all the widget's parent types, most derived first.
1569 The following predefined functions can be used here:
1571 @defun widget-types-convert-widget widget
1572 Convert @code{:args} as widget types in @var{widget}.
1573 @end defun
1575 @defun widget-value-convert-widget widget
1576 Initialize @code{:value} from @code{:args} in @var{widget}.
1577 @end defun
1579 @vindex copy@r{ keyword}
1580 @item :copy
1581 Function to deep copy a widget type.  It takes a shallow copy of the
1582 widget type as an argument (made by @code{copy-sequence}), and returns a
1583 deep copy.  The purpose of this is to avoid having different instances
1584 of combined widgets share nested attributes.
1586 The following predefined functions can be used here:
1588 @defun widget-types-copy widget
1589 Copy @code{:args} as widget types in @var{widget}.
1590 @end defun
1592 @vindex value-to-internal@r{ keyword}
1593 @item :value-to-internal
1594 Function to convert the value to the internal format.  The function
1595 takes two arguments, a widget and an external value, and returns the
1596 internal value.  The function is called on the present @code{:value}
1597 when the widget is created, and on any value set later with
1598 @code{widget-value-set}.
1600 @vindex value-to-external@r{ keyword}
1601 @item :value-to-external
1602 Function to convert the value to the external format.  The function
1603 takes two arguments, a widget and an internal value, and returns the
1604 external value.  The function is called on the present @code{:value}
1605 when the widget is created, and on any value set later with
1606 @code{widget-value-set}.
1608 @vindex create@r{ keyword}
1609 @item :create
1610 Function to create a widget from scratch.  The function takes one
1611 argument, a widget type, and creates a widget of that type, inserts it
1612 in the buffer, and returns a widget object.
1614 @vindex delete@r{ keyword}
1615 @item :delete
1616 Function to delete a widget.  The function takes one argument, a widget,
1617 and should remove all traces of the widget from the buffer.
1619 The default value is:
1621 @defun widget-default-delete widget
1622 Remove @var{widget} from the buffer.
1623 Delete all @code{:children} and @code{:buttons} in @var{widget}.
1624 @end defun
1626 In most cases you should not change this value, but instead use
1627 @code{:value-delete} to make any additional cleanup.
1629 @vindex value-create@r{ keyword}
1630 @item :value-create
1631 Function to expand the @samp{%v} escape in the format string.  It will
1632 be called with the widget as its argument and should insert a
1633 representation of the widget's value in the buffer.
1635 Nested widgets should be listed in @code{:children} or @code{:buttons}
1636 to make sure they are automatically deleted.
1638 @vindex value-delete@r{ keyword}
1639 @item :value-delete
1640 Should remove the representation of the widget's value from the buffer.
1641 It will be called with the widget as its argument.  It doesn't have to
1642 remove the text, but it should release markers and delete nested widgets
1643 if these are not listed in @code{:children} or @code{:buttons}.
1645 @vindex value-get@r{ keyword}
1646 @item :value-get
1647 Function to extract the value of a widget, as it is displayed in the
1648 buffer.
1650 The following predefined function can be used here:
1652 @defun widget-value-value-get widget
1653 Return the @code{:value} property of @var{widget}.
1654 @end defun
1656 @vindex format-handler@r{ keyword}
1657 @item :format-handler
1658 Function to handle unknown @samp{%} escapes in the format string.  It
1659 will be called with the widget and the character that follows the
1660 @samp{%} as arguments.  You can set this to allow your widget to handle
1661 non-standard escapes.
1663 @findex widget-default-format-handler
1664 You should end up calling @code{widget-default-format-handler} to handle
1665 unknown escape sequences, which will handle the @samp{%h} and any future
1666 escape sequences, as well as give an error for unknown escapes.
1668 @vindex action@r{ keyword}
1669 @item :action
1670 Function to handle user initiated events.  By default, @code{:notify}
1671 the parent.
1673 The following predefined function can be used here:
1675 @defun widget-parent-action widget &optional event
1676 Tell @code{:parent} of @var{widget} to handle the @code{:action}.
1677 Optional @var{event} is the event that triggered the action.
1678 @end defun
1680 @vindex prompt-value@r{ keyword}
1681 @item :prompt-value
1682 Function to prompt for a value in the minibuffer.  The function should
1683 take four arguments, @var{widget}, @var{prompt}, @var{value}, and
1684 @var{unbound} and should return a value for widget entered by the user.
1685 @var{prompt} is the prompt to use.  @var{value} is the default value to
1686 use, unless @var{unbound} is non-@code{nil}, in which case there is no default
1687 value.  The function should read the value using the method most natural
1688 for this widget, and does not have to check that it matches.
1689 @end table
1691 If you want to define a new widget from scratch, use the @code{default}
1692 widget as its base.
1694 @deffn Widget default
1695 Widget used as a base for other widgets.
1697 It provides most of the functionality that is referred to as ``by
1698 default'' in this text.
1699 @end deffn
1701 @node Widget Browser, Widget Minor Mode, Defining New Widgets, Top
1702 @comment  node-name,  next,  previous,  up
1703 @section Widget Browser
1704 @cindex widget browser
1706 There is a separate package to browse widgets.  This is intended to help
1707 programmers who want to examine the content of a widget.  The browser
1708 shows the value of each keyword, but uses links for certain keywords
1709 such as @samp{:parent}, which avoids printing cyclic structures.
1711 @deffn Command widget-browse @var{widget}
1712 Create a widget browser for @var{widget}.
1713 When called interactively, prompt for @var{widget}.
1714 @end deffn
1716 @deffn Command widget-browse-other-window @var{widget}
1717 Create a widget browser for @var{widget} and show it in another window.
1718 When called interactively, prompt for @var{widget}.
1719 @end deffn
1721 @deffn Command widget-browse-at @var{pos}
1722 Create a widget browser for the widget at @var{pos}.
1723 When called interactively, use the position of point.
1724 @end deffn
1726 @node  Widget Minor Mode, Utilities, Widget Browser, Top
1727 @comment  node-name,  next,  previous,  up
1728 @section Widget Minor Mode
1729 @cindex widget minor mode
1731 There is a minor mode for manipulating widgets in major modes that
1732 don't provide any support for widgets themselves.  This is mostly
1733 intended to be useful for programmers doing experiments.
1735 @deffn Command widget-minor-mode
1736 Toggle minor mode for traversing widgets.
1737 With arg, turn widget mode on if and only if arg is positive.
1738 @end deffn
1740 @defvar widget-minor-mode-keymap
1741 Keymap used in @code{widget-minor-mode}.
1742 @end defvar
1744 @node  Utilities, Widget Wishlist, Widget Minor Mode, Top
1745 @comment  node-name,  next,  previous,  up
1746 @section Utilities.
1747 @cindex utility functions for widgets
1749 @defun widget-prompt-value widget prompt [ value unbound ]
1750 Prompt for a value matching @var{widget}, using @var{prompt}.
1751 The current value is assumed to be @var{value}, unless @var{unbound} is
1752 non-@code{nil}.@refill
1753 @end defun
1755 @defun widget-get-sibling widget
1756 Get the item which @var{widget} is assumed to toggle.
1757 This is only meaningful for radio buttons or checkboxes in a list.
1758 @end defun
1760 @node  Widget Wishlist, GNU Free Documentation License, Utilities, Top
1761 @comment  node-name,  next,  previous,  up
1762 @section Wishlist
1763 @cindex todo
1765 @itemize @bullet
1766 @item
1767 It should be possible to add or remove items from a list with @kbd{C-k}
1768 and @kbd{C-o} (suggested by @sc{rms}).
1770 @item
1771 The @samp{[INS]} and @samp{[DEL]} buttons should be replaced by a single
1772 dash (@samp{-}).  The dash should be a button that, when invoked, asks
1773 whether you want to add or delete an item (@sc{rms} wanted to git rid of
1774 the ugly buttons, the dash is my idea).
1776 @item
1777 The @code{menu-choice} tag should be prettier, something like the abbreviated
1778 menus in Open Look.
1780 @item
1781 Finish @code{:tab-order}.
1783 @item
1784 Make indentation work with glyphs and proportional fonts.
1786 @item
1787 Add commands to show overview of object and class hierarchies to the
1788 browser.
1790 @item
1791 Find a way to disable mouse highlight for inactive widgets.
1793 @item
1794 Find a way to make glyphs look inactive.
1796 @item
1797 Add @code{property-list} widget.
1799 @item
1800 Add @code{association-list} widget.
1802 @item
1803 Add @code{key-binding} widget.
1805 @item
1806 Add @code{widget} widget for editing widget specifications.
1808 @item
1809 Find clean way to implement variable length list.
1810 See @code{TeX-printer-list} for an explanation.
1812 @item
1813 @kbd{C-h} in @code{widget-prompt-value} should give type specific help.
1815 @item
1816 Add a @code{mailto} widget.
1817 @end itemize
1819 @node GNU Free Documentation License, Index, Widget Wishlist, Top
1820 @appendix GNU Free Documentation License
1821 @include doclicense.texi
1823 @node Index, , GNU Free Documentation License, Top
1824 @comment  node-name,  next,  previous,  up
1825 @unnumbered Index
1827 This is an alphabetical listing of all concepts, functions, commands,
1828 variables, and widgets described in this manual.
1829 @printindex cp
1831 @bye