*** empty log message ***
[gnus] / texi / widget.texi
1 \input texinfo.tex
2
3 @c $Id: widget.texi,v 1.1 1996/09/22 12:07:55 steve Exp $
4
5 @c %**start of header
6 @setfilename widget.info
7 @settitle The Emacs Widget Library
8 @iftex
9 @afourpaper
10 @headings double
11 @end iftex
12 @c %**end of header
13
14 @node Top, Introduction, (dir), (dir)
15 @comment  node-name,  next,  previous,  up
16 @top The Emacs Widget Library
17
18 Version: 0.9
19
20 @menu
21 * Introduction::                
22 * User Interface::              
23 * Programming Example::         
24 * Setting Up the Buffer::       
25 * Basic Types::                 
26 * Sexp Types::                  
27 * Widget Properties::           
28 * Defining New Widgets::        
29 * Widget Wishlist.::            
30 @end menu
31
32 @node  Introduction, User Interface, Top, Top
33 @comment  node-name,  next,  previous,  up
34 @section Introduction
35
36 Most graphical user interface toolkits, such as Motif and XView, provide
37 a number of standard user interface controls (sometimes known as
38 `widgets' or `gadgets').  Emacs doesn't really support anything like
39 this, except for an incredible powerful text ``widget''.  On the other
40 hand, Emacs does provide the necessary primitives to implement many
41 other widgets within a text buffer.  The @code{widget} package
42 simplifies this task.
43
44 The basic widgets are:
45
46 @table @code
47 @item link
48 Areas of text with an associated action.  Intended for hypertext links
49 embedded in text.
50 @item push 
51 Like link, but intended for stand-alone buttons.
52 @item field
53 An editable text field.  It can be either variable or fixed length.
54 @item choice
55 Allows the user to choose one of multiple options from a menu, each
56 option is itself a widget.  Only the selected option will be visible in
57 the buffer.
58 @item radio
59 Allows the user to choose one of multiple options by pushing radio
60 buttons.  The options are implemented as widgets.  All options will be
61 visible in the buffer.
62 @item item
63 A simple constant widget intended to be used in the @code{choice} and
64 @code{radio} widgets. 
65 @item choice-item
66 An button item only intended for use in choices.  When pushed, the user
67 will be asked to select another option from the choice widget.
68 @item toggle
69 A simple @samp{on}/@samp{off} switch.
70 @item checkbox
71 A checkbox (@samp{[ ]}/@samp{[X]}). 
72 @item repeat
73 Create an editable list.  The user can insert or delete items in the
74 list.  Each list item is itself a widget.
75 @end table
76
77 Now of what possible use can support for widgets be in a text editor?
78 I'm glad you asked.  The answer is that widgets are useful for
79 implementing forms.  A @dfn{form} in emacs is a buffer where the user is
80 supposed to fill out a number of fields, each of which has a specific
81 meaning.  The user is not supposed to change or delete any of the text
82 between the fields.  Examples of forms in Emacs are the @file{forms}
83 package (of course), the customize buffers, the mail and news compose
84 modes, and the @sc{html} form support in the @file{w3} browser.  
85
86 The advantages for a programmer of using the @code{widget} package to
87 implement forms are:
88
89 @enumerate
90 @item
91 More complex field than just editable text are supported. 
92 @item
93 You can give the user immediate feedback if he enters invalid data in a
94 text field, and sometimes prevent entering invalid data.
95 @item 
96 You can have fixed sized fields, thus allowing multiple field to be
97 lined up in columns.
98 @item
99 It is simple to query or set the value of a field. 
100 @item 
101 Editing happens in buffer, not in the mini-buffer.
102 @item 
103 Packages using the library get a uniform look, making them easier for
104 the user to learn.
105 @item 
106 As support for embedded graphics improve, the widget library will
107 extended to support it.  This means that your code using the widget
108 library will also use the new graphic features by automatic.
109 @end enumerate
110
111 In order to minimize the code that is loaded by users who does not
112 create any widgets, the code has been split in two files:
113
114 @table @file
115 @item widget.el
116 This will declare the user variables, define the function
117 @code{widget-define}, and autoload the function @code{widget-create}. 
118 @item widget-edit.el
119 Everything else is here, there is no reason to load it explicitly, as
120 it will be autoloaded when needed.
121 @end table
122
123 @node User Interface, Programming Example, Introduction, Top
124 @comment  node-name,  next,  previous,  up
125 @section User Interface
126
127 A form consist of read only text for documentation and some fields,
128 where each the fields contain two parts, as tag and a value.  The tags
129 are used to identify the fields, so the documentation can refer to the
130 foo field, meaning the field tagged with @samp{Foo}. Here is an example
131 form:
132
133 @example
134 Here is some documentation.
135
136 Name: @i{My Name}     @strong{Choose}: This option
137 Address:  @i{Some Place
138 In some City
139 Some country.}
140
141 See also @b{_other work_} for more information.
142
143 Numbers: count to three below
144 @b{[INS]} @b{[DEL]} @i{One}
145 @b{[INS]} @b{[DEL]} @i{Eh, two?}
146 @b{[INS]} @b{[DEL]} @i{Five!}
147 @b{[INS]} 
148
149 Select multiple:
150
151 @b{[X]} This
152 @b{[ ]} That
153 @b{[X]} Thus
154
155 Select one:
156
157 @b{(*)} One
158 @b{( )} Another One.
159 @b{( )} A Final One.
160
161 @b{[Apply Form]} @b{[Reset Form]}
162 @end example
163
164 The top level widgets in is example are tagged @samp{Name},
165 @samp{Choose}, @samp{Address}, @samp{_other work_}, @samp{Numbers},
166 @samp{Select multiple}, @samp{Select one}, @samp{[Apply Form]}, and
167 @samp{[Reset Form]}.  There are basically two thing the user can do within
168 a form, namely editing the editable text fields and activating the
169 buttons.
170
171 @subsection Editable Text Fields
172
173 In the example, the value for the @samp{Name} is most likely displayed
174 in an editable text field, and so are values for each of the members of
175 the @samp{Numbers} list.  All the normal Emacs editing operations are
176 available for editing these fields.  The only restriction is that each
177 change you make must be contained within a single editable text field.
178 For example, capitalizing all text from the middle of one field to the
179 middle of another field is prohibited.
180
181 Editing text fields are created by the @code{field} widget.
182
183 The editing text fields are highlighted with the
184 @code{widget-field-face} face, making them easy to find.
185
186 @defopt widget-field-face
187 Face used for other editing fields.
188 @end defopt
189
190 @subsection Buttons
191
192 Some portions of the buffer have an associated @dfn{action}, which can
193 be @dfn{activated} by a standard key or mouse command.  These portions
194 are called @dfn{buttons}.  The default commands for activating a button
195 are:
196
197 @table @kbd
198 @item @key{RET}
199 @deffn Command widget-button-press @var{pos} &optional @var{event}
200 Activate the button at @var{pos}, defaulting to point.
201 If point is not located on a button, activate the binding in
202 @code{widget-global-map} (by default the global map).
203 @end deffn
204
205 @item mouse-2
206 @deffn Command widget-button-click @var{event}
207 Activate the button at the location of the mouse pointer.  If the mouse
208 pointer is located in an editable text field, activate the binding in
209 @code{widget-global-map} (by default the global map).
210 @end deffn
211 @end table
212
213 There are several different kind of buttons, all of which are present in
214 the example:
215
216 @table @emph
217 @item The Option Field Tags.
218 When you activate one of these buttons, you will be asked to choose
219 between a number of different options.  This is how you edit an option
220 field.  Option fields are created by the @code{choice} widget.  In
221 the example, @samp{@b{Choose}} is an option field tag.
222 @item The @samp{@b{[INS]}} and @samp{@b{[DEL]}} buttons.
223 Activating these will insert or delete elements from a editable list.
224 The list is created by the @code{repeat} widget. 
225 @item Embedded Buttons.
226 The @samp{@b{_other work_}} is an example of an embedded
227 button. Embedded buttons are not associated with a fields, but can serve
228 any purpose, such as implementing hypertext references.  They are
229 usually created by the @code{link} widget.
230 @item The @samp{@b{[ ]}} and @samp{@b{[X]}} buttons.
231 Activating one of these will convert it to the other.  This is useful
232 for implementing multiple-choice fields.  You can create it wit
233 @item The @samp{@b{( )}} and @samp{@b{(*)}} buttons.
234 Only one radio button in a @code{radio} widget can be selected at any
235 time.  When you push one of the unselected radio buttons, it will be
236 selected and the previous selected radio button will become unselected. 
237 @item The @samp{@b{[Apply Form]}} @samp{@b{[Reset Form]}} buttons.
238 These are explicit buttons made with the @code{push} widget.  The main
239 difference from the @code{link} widget is that the buttons are intended
240 to be displayed more like buttons in a GUI, once Emacs grows powerful
241 enough. 
242 @end table
243
244 To make them easier to locate, buttons are emphasized in the buffer.  
245
246 @defopt widget-button-face
247 Face used for buttons.
248 @end defopt
249
250 @defopt widget-mouse-face
251 Face used for buttons when the mouse pointer is above it.
252 @end defopt
253
254 @subsection Navigation
255
256 You can use all the normal Emacs commands to move around in a form
257 buffer, plus you will have these additional commands:
258
259 @table @kbd
260 @item @key{TAB}
261 @deffn Command widget-forward &optional count
262 Move point @var{count} buttons or editing fields forward.
263 @end deffn
264 @item @key{M-TAB}
265 @deffn Command widget-backward &optional count
266 Move point @var{count} buttons or editing fields backward.
267 @end deffn
268 @end table
269
270 @node Programming Example, Setting Up the Buffer, User Interface, Top
271 @comment  node-name,  next,  previous,  up
272 @section Programming Example
273
274 Here is the code to implement the user interface example (see @ref{User
275 Interface}).
276
277 @lisp
278 (require 'widget)
279
280 (defvar widget-example-repeat)
281
282 (defun widget-example ()
283   "Create the widgets from the Widget manual."
284   (interactive)
285   (switch-to-buffer "*Widget Example*")
286   (kill-all-local-variables)
287   (make-local-variable 'widget-example-repeat)
288   (let ((inhibit-read-only t))
289     (erase-buffer))
290   (widget-insert "Here is some documentation.\n\nName: ")
291   (widget-create 'field
292                  :size 13
293                  "My Name")
294   (widget-create 'choice
295                  :tag "Choose"
296                  :value "This"
297                  :help-echo "Choose me, please!"
298                  :notify (lambda (widget &rest ignore)
299                            (message "%s is a good choice!"
300                                     (widget-value widget)))
301                  '(item :tag "This option" :value "This")
302                  '(choice-item "That option")
303                  '(field :menu-tag "No option" "Thus option"))
304   (widget-insert "Address: ")
305   (widget-create 'field
306                  "Some Place\nIn some City\nSome country.")
307   (widget-insert "\nSee also ")
308   (widget-create 'link
309                  :notify (lambda (&rest ignore)
310                            (widget-value-set widget-example-repeat 
311                                              '("En" "To" "Tre"))
312                            (widget-setup))
313                  "other work")
314   (widget-insert " for more information.\n\nNumbers: count to three below\n")
315   (setq widget-example-repeat
316         (widget-create 'repeat
317                        :entry-format "%i %d %v"
318                        :notify (lambda (widget &rest ignore)
319                                  (let ((old (widget-get widget
320                                                         ':example-length))
321                                        (new (length (widget-value widget))))
322                                    (unless (eq old new)
323                                      (widget-put widget ':example-length new)
324                                      (message "You can count to %d." new))))
325                        :value '("One" "Eh, two?" "Five!")
326                        '(field :value "three")))
327   (widget-insert "\n\nSelect multiple:\n\n")
328   (widget-create 'checkbox t)
329   (widget-insert " This\n")
330   (widget-create 'checkbox nil)
331   (widget-insert " That\n")
332   (widget-create 'checkbox
333                  :notify (lambda (&rest ignore) (message "Tickle"))
334                  t)
335   (widget-insert " Thus\n\nSelect one:\n\n")
336   (widget-create 'radio
337                  :value "One"
338                  :notify (lambda (widget &rest ignore)
339                            (message "You selected %s" (widget-value widget)))
340                  '(item "One") '(item "Anthor One.") '(item "A Final One."))
341   (widget-insert "\n")
342   (widget-create 'push
343                  :notify (lambda (&rest ignore) 
344                            (if (= (length (widget-value widget-example-repeat))
345                                   3)
346                                (message "Congratulation!")
347                              (error "Three was the count!")))
348                  "Apply Form")
349   (widget-insert " ")
350   (widget-create 'push
351                  :notify (lambda (&rest ignore)
352                            (widget-example))
353                  "Reset Form")
354   (widget-insert "\n")
355   (use-local-map widget-keymap)
356   (widget-setup))
357 @end lisp
358
359 @node Setting Up the Buffer, Basic Types, Programming Example, Top
360 @comment  node-name,  next,  previous,  up
361 @section Setting Up the Buffer
362
363 Widgets are created with @code{widget-create}, which returns a
364 @dfn{widget} object.  This object can be queried and manipulated by
365 other widget functions, until it is deleted with @code{widget-delete}.
366 After the widgets have been created, @code{widget-setup} must be called
367 to enable them.
368
369 @defun widget-create type [ keyword argument ]@dots{}
370 Create and return a widget of type @var{type}.
371 The syntax for the @var{type} argument is described in @ref{Basic Types}.
372
373 The keyword arguments can be used to overwrite the keyword arguments
374 that are part of @var{type}.
375 @end defun
376
377 @defun widget-delete widget
378 Delete @var{widget} and remove it from the buffer.
379 @end defun
380
381 @defun widget-setup 
382 Setup a buffer to support widgets. 
383
384 This should be called after creating all the widgets and before allowing
385 the user to edit them.
386 @refill
387 @end defun
388
389 If you want to insert text outside the widgets in the form, the
390 recommended way to do that is with @code{widget-insert}.
391
392 @defun widget-insert 
393 Insert the arguments, either strings or characters, at point.
394 The inserted text will be read only.
395 @end defun
396
397 There is a standard widget keymap which you might find useful.
398
399 @defvr Const widget-keymap
400 A keymap with the global keymap as its parent.@br
401 @key{TAB} and @kbd{C-@key{TAB}} are bound to @code{widget-forward} and
402 @code{widget-backward}, respectively.  @kbd{@key{RET}} and @kbd{mouse-2}
403 are bound to @code{widget-button-press} and
404 @code{widget-button-}.@refill
405 @end defvr
406
407 @defvar widget-global-map
408 Keymap used by @code{widget-button-press} and @code{widget-button-click}
409 when not on a button.  By default this is @code{global-map}.
410 @end defvar
411
412 @node Basic Types, Sexp Types, Setting Up the Buffer, Top
413 @comment  node-name,  next,  previous,  up
414 @section Basic Types
415
416 The syntax of a type specification is given below:
417
418 @example
419 NAME ::= (NAME [KEYWORD ARGUMENT]... ARGS)
420      |   NAME
421 @end example
422
423 Where, @var{name} is a widget name, @var{keyword} is the name of a
424 property, @var{argument} is the value of the property, and @var{args}
425 are interpreted in a widget specific way.
426
427 There following keyword arguments that apply to all widgets:
428
429 @table @code
430 @item :value
431 The initial value for widgets of this type.
432
433 @item :format
434 This string will be inserted in the buffer when you create a widget.
435 The following @samp{%} escapes are available:
436
437 @table @samp
438 @item %[
439 @itemx %]
440 The text inside will be marked as a button.
441
442 @item %v
443 This will be replaces with the buffer representation of the widgets
444 value.  What this is depends on the widget type.
445
446 @item %d
447 Insert the string specified by @code{:doc} here.
448
449 @item %t
450 Insert the string specified by @code{:tag} here, or the @code{princ}
451 representation of the value if there is no tag.
452
453 @item %%
454 Insert a literal @samp{%}. 
455 @end table
456
457 @item :button-face
458 Face used to highlight text inside %[ %] in the format.
459
460 @item :doc
461 The string inserted by the @samp{%d} escape in the format
462 string.  
463
464 @item :tag
465 The string inserted by the @samp{%t} escape in the format
466 string.  
467
468 @item :help-echo
469 Message displayed whenever you move to the widget with either
470 @code{widget-forward} or @code{widget-backward}.
471
472 @item :notify
473 A function called each time the widget or a nested widget is changed.
474 The function is called with two or three arguments.  The first argument
475 is the widget itself, the second argument is the widget that was
476 changed, and the third argument is the event leading to the change, if
477 any. 
478
479 @item :menu-tag
480 Tag used in the menu when the widget is used as an option in a
481 @code{choice} widget.
482
483 @item :menu-tag-get
484 Function used for finding the tag when the widget is used as an option
485 in a @code{choice} widget.  By default, the tag used will be either the
486 @code{:menu-tag} or @code{:tag} property if present, or the @code{princ}
487 representation of the @code{:value} property if not.
488
489 @item :match
490 Should be a function called with two arguments, the widget and a value,
491 and returning non-nil if the widget can represent the specified value.
492
493 @item :validate
494 A function which takes a widget as an argument, and return nil if the
495 widgets current value is valid for the widget.  Otherwise, it should
496 return the widget containing the invalid data, and set that widgets
497 @code{:error} property to a string explaining the error.
498
499 @item :parent
500 The parent of a nested widget (e.g. a @code{choice} item or an element of a
501 @code{repeat} widget). 
502 @end table
503
504 @menu
505 * link::                        
506 * push::                        
507 * field::                       
508 * text::                        
509 * choice::                      
510 * radio::                       
511 * item::                        
512 * choice-item::                 
513 * toggle::                      
514 * checkbox::                    
515 * checklist::                   
516 * repeat::                      
517 @end menu
518
519 @node link, push, Basic Types, Basic Types
520 @comment  node-name,  next,  previous,  up
521 @subsection The @code{link} Widget
522
523 Syntax:
524
525 @example
526 TYPE ::= (link [KEYWORD ARGUMENT]...  [ VALUE ])
527 @end example
528
529 The @var{value}, if present, is used to initialize the @code{:value}
530 property.  The value should be a string, which will be inserted in the
531 buffer. 
532
533 @node  push, field, link, Basic Types
534 @comment  node-name,  next,  previous,  up
535 @subsection The @code{push} Widget
536
537 Syntax:
538
539 @example
540 TYPE ::= (push [KEYWORD ARGUMENT]...  [ VALUE ])
541 @end example
542
543 The @var{value}, if present, is used to initialize the @code{:value}
544 property. The value should be a string, which will be inserted in the
545 buffer. 
546
547 @node field, text, push, Basic Types
548 @comment  node-name,  next,  previous,  up
549 @subsection The @code{field} Widget
550
551 Syntax:
552
553 @example
554 TYPE ::= (field [KEYWORD ARGUMENT]... [ VALUE ])
555 @end example
556
557 The @var{value}, if present, is used to initialize the @code{:value}
558 property.  The value should be a string, which will be inserted in
559 field.  This widget will match all string values.
560
561 The following extra properties are recognized.
562
563 @table @code
564 @item :size
565 The width of the editable field.@br
566 By default the field will reach to the end of the line.
567
568 @item :value-face
569 Face used for highlighting the editable field.  Default is
570 @code{widget-field-face}. 
571
572 @item :keymap
573 Keymap used in the editable field.  @code{widget-keymap} will allow you
574 to use normal editing commands, even if these has been supressed in the
575 current buffer.
576
577 @end table
578
579 @node text, choice, field, Basic Types
580 @comment  node-name,  next,  previous,  up
581 @subsection The @code{text} Widget
582
583 This is just like @code{field}, but intended for multiline text
584 fields. 
585
586 @node choice, radio, text, Basic Types
587 @comment  node-name,  next,  previous,  up
588 @subsection The @code{choice} Widget
589
590 Syntax:
591
592 @example
593 TYPE ::= (choice [KEYWORD ARGUMENT]... TYPE ... )
594 @end example
595
596 The @var{type} arguments represents each possible choice.  The widgets
597 value of will be the value of the chosen @var{type} argument.  This
598 widget will match any value that matches at least one of the specified
599 @var{type} arguments.
600
601 @table @code
602 @item :void 
603 Widget type used as a fallback when the value does not match any of the
604 specified @var{type} arguments.
605
606 @item :children
607 A list whose car is the widget representing the currently chosen type in
608 the buffer. 
609
610 @item :choice
611 The current chosen type
612
613 @item :args 
614 The list of types. 
615 @end table
616
617 @node radio, item, choice, Basic Types
618 @comment  node-name,  next,  previous,  up
619 @subsection The @code{radio} Widget
620
621 Syntax:
622
623 @example
624 TYPE ::= (radio [KEYWORD ARGUMENT]...  TYPE ... )
625 @end example
626
627 The @var{type} arguments represents each possible choice.  The widgets
628 value of will be the value of the chosen @var{type} argument.  This
629 widget will match any value that matches at least one of the specified
630 @var{type} arguments.
631
632 The following extra properties are recognized.
633
634 @table @code
635 @item :entry-format
636 This string will be inserted for each entry in the list.
637 The following @samp{%} escapes are available:
638 @table @samp
639 @item %v
640 Replaced with the buffer representation of the @var{type} widget.
641 @item %b
642 Replace with the radio button.
643 @item %%
644 Insert a literal @samp{%}. 
645 @end table
646
647 @item :buttons
648 The widgets representing the radio buttons.
649
650 @item :children
651 The widgets representing each type.
652
653 @item :choice
654 The current chosen type
655
656 @item :args 
657 The list of types. 
658 @end table
659
660 You can add extra radio button items to a radio widget after it has been
661 created with the function `widget-radio-add-item'.
662
663 @defun widget-radio-add-item widget type
664 Add to radio widget @var{widget} a new radio button item of type @var{type}.
665 @end defun
666
667 Please note that such items added after the radio widget has been
668 created will @strong{not} be properly destructed when you call
669 @code{widget-delete}. 
670
671 @node item, choice-item, radio, Basic Types
672 @comment  node-name,  next,  previous,  up
673 @subsection The @code{item} Widget
674
675 Syntax:
676
677 @example
678 ITEM ::= (item [KEYWORD ARGUMENT]... VALUE)
679 @end example
680
681 The @var{value}, if present, is used to initialize the @code{:value}
682 property.  The value should be a string, which will be inserted in the
683 buffer.  This widget will only match the specified value.
684
685 @node choice-item, toggle, item, Basic Types
686 @comment  node-name,  next,  previous,  up
687 @subsection The @code{choice-item} Widget
688
689 Syntax:
690
691 @example
692 ITEM ::= (choice-item [KEYWORD ARGUMENT]... VALUE)
693 @end example
694
695 The @var{value}, if present, is used to initialize the @code{:value}
696 property.  The value should be a string, which will be inserted in the
697 buffer as a button.  Activating the button of a @code{choice-item} is
698 equivalent to activating the parent widget.  This widget will only match
699 the specified value. 
700
701 @node toggle, checkbox, choice-item, Basic Types
702 @comment  node-name,  next,  previous,  up
703 @subsection The @code{toggle} Widget
704
705 Syntax:
706
707 @example
708 TYPE ::= (toggle [KEYWORD ARGUMENT]...)
709 @end example
710
711 The widget has two possible states, `on' and `off', which corresponds to
712 a @code{t} or @code{nil} value.
713
714 The following extra properties are recognized.
715
716 @table @code
717 @item :on
718 String representing the `on' state.  By default the string @samp{on}.
719 @item :off 
720 String representing the `off' state.  By default the string @samp{off}.
721 @item :on-type
722 Type representing the `on' state.  By default an `item' widget displaying
723 the string specified with the @code{:on} keyword.
724 @item :off-type
725 Type representing the `off' state.  By default an `item' widget
726 displaying the string specified with the @code{:off} keyword.
727 @end table
728
729 @node checkbox, checklist, toggle, Basic Types
730 @comment  node-name,  next,  previous,  up
731 @subsection The @code{checkbox} Widget
732
733 The widget has two possible states, `selected' and `unselected', which
734 corresponds to a @code{t} or @code{nil} value.
735
736 Syntax:
737
738 @example
739 TYPE ::= (checkbox [KEYWORD ARGUMENT]...)
740 @end example
741
742 @node checklist, repeat, checkbox, Basic Types
743 @comment  node-name,  next,  previous,  up
744 @subsection The @code{checklist} Widget
745
746 Syntax:
747
748 @example
749 TYPE ::= (checklist [KEYWORD ARGUMENT]...  TYPE ... )
750 @end example
751
752 The @var{type} arguments represents each checklist item.  The widgets
753 value of will be a list containing the value of each ticked @var{type}
754 argument.  The checklist widget will match a list whose elements all
755 matches at least one of the specified @var{type} arguments.
756
757 The following extra properties are recognized.
758
759 @table @code
760 @item :entry-format
761 This string will be inserted for each entry in the list.
762 The following @samp{%} escapes are available:
763 @table @samp
764 @item %v
765 Replaced with the buffer representation of the @var{type} widget.
766 @item %b
767 Replace with the checkbox.
768 @item %%
769 Insert a literal @samp{%}. 
770 @end table
771
772 @item :buttons
773 The widgets representing the checkboxes.
774
775 @item :children
776 The widgets representing each type.
777
778 @item :args 
779 The list of types. 
780 @end table
781
782 @node repeat,  , checklist, Basic Types
783 @comment  node-name,  next,  previous,  up
784 @subsection The @code{repeat} Widget
785
786 Syntax:
787
788 @example
789 TYPE ::= ([KEYWORD ARGUMENT]... TYPE)
790 @end example
791
792 The value is a list, where each member represent one widget of type
793 @var{type}. 
794
795 The following extra properties are recognized.
796
797 @table @code
798 @item :indent
799 Number of spaces inserted before each member of the list, except for the
800 first. 
801
802 @item :entry-format
803 This string will be inserted for each entry in the list.
804 The following @samp{%} escapes are available:
805 @table @samp
806 @item %v
807 This will be replaced with the buffer representation of the @var{type}
808 widget.
809 @item %i
810 Insert the @b{[INS]} button.
811 @item %d
812 Insert the @b{[DEL]} button.
813 @item %%
814 Insert a literal @samp{%}. 
815 @end table
816
817 @item :buttons
818 The widgets representing the insert and delete buttons.
819
820 @item :children
821 The widgets representing the elements of the list.
822
823 @item :args
824 List whose car is the type of the list elements.
825
826 @end table
827
828 @node Sexp Types, Widget Properties, Basic Types, Top
829 @comment
830 @section Sexp Types
831
832 A number of widgets for editing s-expressions (lisp types) are also
833 available.  These basically fall in three categories: @dfn{atoms},
834 @dfn{composite types}, and @dfn{generic}.
835
836 @menu
837 * generic::                     
838 * atoms::                       
839 * composite::                   
840 @end menu
841
842 @node generic, atoms, Sexp Types, Sexp Types
843 @comment  node-name,  next,  previous,  up
844 @subsection The Generic Widget.
845
846 The @code{const} and @code{sexp} widgets can contain any lisp
847 expression.  In the case of the @code{const} widget the user is
848 prohibited from editing edit it, which is mainly useful as a component
849 of one of the composite widgets.
850
851 The syntax for the generic widgets is
852
853 @example
854 TYPE ::= (const [KEYWORD ARGUMENT]...  [ VALUE ])
855 @end example
856
857 The @var{value}, if present, is used to initialize the @code{:value}
858 property and can be any s-expression.
859
860 @deffn Widget const
861 This will display any valid s-expression in an immutable part of the
862 buffer. 
863 @end deffn
864
865 @deffn Widget sexp
866 This will allow you to edit any valid s-expression in an editable buffer
867 field. 
868
869 The @code{sexp} widget takes the same keyword arguments as the
870 @code{field} widget.
871 @end deffn
872
873 @node atoms, composite, generic, Sexp Types
874 @comment  node-name,  next,  previous,  up
875 @subsection Atomic Sexp Widgets.
876
877 The atoms are s-expressions that does not consist of other
878 s-expressions.  A string is an atom, while a list is a composite type.
879 You can edit the value of an atom with the following widgets.  
880
881 The syntax for all the atoms are
882
883 @example
884 TYPE ::= (NAME [KEYWORD ARGUMENT]...  [ VALUE ])
885 @end example
886
887 The @var{value}, if present, is used to initialize the @code{:value}
888 property and must be an expression of the same type as the widget.
889 I.e. the string widget can only be initialized with a string.
890
891 All the atom widgets take the same keyword arguments as the @code{field}
892 widget.
893
894 @deffn Widget string
895 Allows you to edit a string in an editable field.
896 @end deffn
897
898 @deffn Widget file
899 Allows you to edit a file name in an editable field.  You you activate
900 the tag button, you can edit the file name in the mini-buffer with
901 completion. 
902
903 Keywords:
904 @table @code
905 @item :must-match
906 If this is set to non-nil, only existing file names will be allowed in
907 the minibuffer.
908 @end table
909 @end deffn
910
911 @deffn Widget directory
912 Allows you to edit a directory name in an editable field.
913 Similar to the @code{file} widget.
914 @end deffn
915
916 @deffn Widget symbol
917 Allows you to edit a lisp symbol in an editable field.
918 @end deffn
919
920 @deffn Widget integer
921 Allows you to edit an integer in an editable field.
922 @end deffn
923
924 @deffn Widget number
925 Allows you to edit a number in an editable field.
926 @end deffn
927
928 @node composite,  , atoms, Sexp Types
929 @comment  node-name,  next,  previous,  up
930 @subsection Composite Sexp Widgets.
931
932 The syntax for the composite are
933
934 @example
935 TYPE ::= (NAME [KEYWORD ARGUMENT]...  COMPONENT...)
936 @end example
937
938 Where each @var{component} must be a widget type.  Each component widget
939 will be displayed in the buffer, and be editable to the user.
940
941 @deffn Widget cons
942 The value of a @code{cons} widget is a cons-cell where the car is the
943 value of the first component and the cdr is the value of the second
944 coponent.  There must be exactly two components. 
945 @end deffn
946
947 @deffn Widget lisp
948 The value of a @code{cons} widget is a list containing the value of
949 each of its component.
950 @end deffn
951
952 @deffn Widget vector
953 The value of a @code{cons} widget is a vector containing the value of
954 each of its component.
955 @end deffn
956
957 The above suffice for specifying fixed size lists and vectors.  To get
958 variable length lists and vectors, you can use a @code{choice},
959 @code{radio}, @code{checklist} or @code{repeat} widget together with the
960 @code{:inline} keyword.  If any component of a composite widget has the
961 @code{:inline} keyword set, its value must be a list which will then be
962 spliced into the composite.  For example, to specify a list whose first
963 element must be a file name, and whose remaining arguments should either
964 by the symbol @code{t} or two files, you can use the following widget
965 specification: 
966
967 @example
968 (list file
969       (choice (const t)
970               (list :inline t
971                     :value ("foo" "bar")
972                     string string)))
973 @end example
974
975 The value of a widget of this type will either have the form 
976 @samp{(file t)} or @code{(file string string)}.
977
978 This concept of inline is probably hard to understand.  It was certainly
979 hard to implement so instead of confuse you more by trying to explain it
980 here, I'll just suggest you meditate over it for a while.
981
982 @node Widget Properties, Defining New Widgets, Sexp Types, Top
983 @comment  node-name,  next,  previous,  up
984 @section Properties
985
986 You can examine or set this value by using the widget object that was
987 returned by @code{widget-create}.  
988
989 @defun widget-value widget
990 Return the current value contained in @var{widget}.
991 It is an error to call this function on an uninitialized widget.
992 @end defun
993
994 @defun widget-value-set widget value
995 Set the value contained in @var{widget} to @var{value}.
996 It is an error to call this function with an invalid @var{value}.
997 @end defun
998
999 @strong{Important:} You @emph{must} call @code{widget-setup} after
1000 modifying the value of a widget before the user is allowed to edit the
1001 widget again.  It is enough to call @code{widget-setup} once if you
1002 modify multiple widgets.  This is currently only necessary if the widget
1003 contains an editing field, but may be necessary for other widgets in the
1004 future. 
1005
1006 If your application needs to associate some information with the widget
1007 objects, for example a reference to the item being edited, it can be
1008 done with @code{widget-put} and @code{widget-get}.  The property names
1009 must begin with a @samp{:}.
1010
1011 @defun widget-put widget property value
1012 In @var{widget} set @var{property} to @var{value}.
1013 @var{property} should be a symbol, while @var{value} can be anything.
1014 @end defun
1015
1016 @defun widget-get widget property
1017 In @var{widget} return the value for @var{property}.
1018 @var{property} should be a symbol, the value is what was last set by
1019 @code{widget-put} for @var{property}.
1020 @end defun
1021
1022 @defun widget-member widget property
1023 Non-nil if @var{widget} has a value (even nil) for property @var{property}.
1024 @end defun
1025
1026 @node Defining New Widgets, Widget Wishlist., Widget Properties, Top
1027 @comment  node-name,  next,  previous,  up
1028 @section Defining New Widgets
1029
1030 You can define specialized widgets with @code{define-widget}.  It allows
1031 you to create a shorthand for more complex widgets, including specifying
1032 component widgets and default new default values for the keyword
1033 arguments. 
1034
1035 @defun widget-define name class doc &rest args
1036 Define a new widget type named @var{name} from @code{class}.
1037
1038 @var{name} and class should both be symbols, @code{class} should be one
1039 of the existing widget types. 
1040
1041 The third argument @var{DOC} is a documentation string for the widget.
1042
1043 After the new widget has been defined, the following two calls will
1044 create identical widgets:
1045
1046 @itemize @bullet
1047 @item
1048 @lisp
1049 (widget-create @var{name})
1050 @end lisp
1051
1052 @item
1053 @lisp
1054 (apply widget-create @var{class} @var{args})
1055 @end lisp
1056 @end itemize
1057
1058 @end defun
1059
1060 Using @code{widget-define} does just store the definition of the widget
1061 type in the @code{widget-type} property of @var{name}, which is what
1062 @code{widget-create} uses.
1063
1064 If you just want to specify defaults for keywords with no complex
1065 conversions, you can use @code{identity} as your conversion function.
1066
1067 The following additional keyword arguments are useful when defining new
1068 widgets: 
1069 @table @code
1070 @item :convert-widget
1071 Function to convert a widget type before creating a widget of that
1072 type.  It takes a widget type as an argument, and returns the converted
1073 widget type.  When a widget is created, this function is called for the
1074 widget type and all the widgets parent types, most derived first. 
1075
1076 @item :value-to-internal
1077 Function to convert the value to the internal format.  The function
1078 takes two arguments, a widget and an external value, and returns the
1079 internal value.  The function is called on the present @code{:value}
1080 when the widget is created, and on any value set later with
1081 @code{widget-value-set}.
1082
1083 @item :value-to-external
1084 Function to convert the value to the external format.  The function
1085 takes two arguments, a widget and an internal value, and returns the
1086 internal value.  The function is called on the present @code{:value}
1087 when the widget is created, and on any value set later with
1088 @code{widget-value-set}.
1089
1090 @item :create
1091 Function to create a widget from scratch.  The function takes one
1092 argument, a widget type, and create a widget of that type, insert it in
1093 the buffer, and return a widget object.
1094
1095 @item :delete
1096 Function to delete a widget.  The function takes one argument, a widget,
1097 and should remove all traces of the widget from the buffer.
1098
1099 @item :value-create
1100 Function to expand the @samp{%v} escape in the format string.  It will
1101 be called with the widget as its argument.  Should
1102 insert a representation of the widgets value in the buffer.
1103
1104 @item :value-delete
1105 Should remove the representation of the widgets value from the buffer.
1106 It will be called with the widget as its argument.  It doesn't have to
1107 remove the text, but it should release markers and delete nested widgets
1108 if such has been used.
1109
1110 @item :format-handler
1111 Function to handle unknown @samp{%} escapes in the format string.  It
1112 will be called with the widget and the escape character as arguments.
1113 You can set this to allow your widget to handle non-standard escapes.
1114 @end table
1115
1116 If you want to define a new widget from scratch, use the @code{default}
1117 widget as its base.
1118
1119 @deffn Widget default [ keyword argument ]
1120 Widget used as a base for other widgets. 
1121
1122 It provides most of the functionality that is refered to as ``by
1123 default'' in this text. 
1124 @end deffn
1125
1126 @node  Widget Wishlist.,  , Defining New Widgets, Top
1127 @comment  node-name,  next,  previous,  up
1128 @section Wishlist.
1129
1130 @itemize @bullet
1131 @item 
1132 In general, we need @strong{much} better support for keyboard
1133 operations. 
1134
1135 @itemize -
1136 @item 
1137 It should be possible to add or remove items from a list with @kbd{C-k}
1138 and @kbd{C-o} (suggested by @sc{rms}).
1139
1140 @item
1141 @kbd{C-k} should kill to end of field or end of line, whatever come
1142 first. 
1143
1144 @item
1145 Commands to move to the beginning/end of a field.
1146
1147 @end itemize
1148
1149 @item 
1150 The @samp{[INS]} and @samp{[DEL]} buttons should be replaced by a single
1151 dash (@samp{-}).  The dash should be a button that, when activated, ask
1152 whether you want to add or delete an item (@sc{rms} wanted to git rid of
1153 the ugly buttons, the dash is my idea).
1154
1155 @item
1156 Use graphical versions of the widgets for emacsen that can do that.
1157 I.e. real radio buttons and checkmarks instead of their @sc{ascii}
1158 equivalents. 
1159
1160 @item
1161 There should be a way to probe a widget to see if the user has modified
1162 it. 
1163
1164 @item 
1165 The support for indentation of component widgets should be finished. 
1166
1167 @item
1168 There should be support for browsing the widget documentation.
1169
1170 @item
1171 There should be a way to specify that @key{RET} in a field will call the
1172 @code{:activate} function.  This should be used by widgets such as
1173 @code{file} and @code{symbol} prompt with completion.  This way, we
1174 could also get rid of the default tag for the @code{file} widget.
1175
1176 @item
1177 The @code{choice} tag should be prettier, something like the abbreviated
1178 menus in Open Look.
1179
1180 @item
1181 The functions used in many widgets, like
1182 @code{widget-item-convert-widget}, should not have names that are
1183 specific to the first widget where I used them.
1184
1185 @item 
1186 Unchecked items in a @code{radio} or @code{checklist} should be grayed
1187 out, and the subwidgets should somehow become inactive.  This could
1188 perhaps be implemented by binding @code{widget-inactive} to t when inserting
1189 the grayed out subwidget, and let the widget-specify functions check
1190 that variable.
1191
1192 @end itemize
1193
1194 @contents
1195 @bye