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