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