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