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