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