3 @c $Id: widget.texi,v 1.1 1996/09/22 12:07:55 steve Exp $
6 @setfilename widget.info
7 @settitle The Emacs Widget Library
14 @node Top, Introduction, (dir), (dir)
15 @comment node-name, next, previous, up
16 @top The Emacs Widget Library
23 * Programming Example::
24 * Setting Up the Buffer::
28 * Defining New Widgets::
32 @node Introduction, User Interface, Top, Top
33 @comment node-name, next, previous, up
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
44 The basic widgets are:
48 Areas of text with an associated action. Intended for hypertext links
51 Like link, but intended for stand-alone buttons.
53 An editable text field. It can be either variable or fixed length.
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
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.
63 A simple constant widget intended to be used in the @code{choice} and
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.
69 A simple @samp{on}/@samp{off} switch.
71 A checkbox (@samp{[ ]}/@samp{[X]}).
73 Create an editable list. The user can insert or delete items in the
74 list. Each list item is itself a widget.
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.
86 The advantages for a programmer of using the @code{widget} package to
91 More complex field than just editable text are supported.
93 You can give the user immediate feedback if he enters invalid data in a
94 text field, and sometimes prevent entering invalid data.
96 You can have fixed sized fields, thus allowing multiple field to be
99 It is simple to query or set the value of a field.
101 Editing happens in buffer, not in the mini-buffer.
103 Packages using the library get a uniform look, making them easier for
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.
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:
116 This will declare the user variables, define the function
117 @code{widget-define}, and autoload the function @code{widget-create}.
119 Everything else is here, there is no reason to load it explicitly, as
120 it will be autoloaded when needed.
123 @node User Interface, Programming Example, Introduction, Top
124 @comment node-name, next, previous, up
125 @section User Interface
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
134 Here is some documentation.
136 Name: @i{My Name} @strong{Choose}: This option
137 Address: @i{Some Place
141 See also @b{_other work_} for more information.
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!}
161 @b{[Apply Form]} @b{[Reset Form]}
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
171 @subsection Editable Text Fields
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.
181 Editing text fields are created by the @code{field} widget.
183 The editing text fields are highlighted with the
184 @code{widget-field-face} face, making them easy to find.
186 @defopt widget-field-face
187 Face used for other editing fields.
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
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).
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).
213 There are several different kind of buttons, all of which are present in
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
244 To make them easier to locate, buttons are emphasized in the buffer.
246 @defopt widget-button-face
247 Face used for buttons.
250 @defopt widget-mouse-face
251 Face used for buttons when the mouse pointer is above it.
254 @subsection Navigation
256 You can use all the normal Emacs commands to move around in a form
257 buffer, plus you will have these additional commands:
261 @deffn Command widget-forward &optional count
262 Move point @var{count} buttons or editing fields forward.
265 @deffn Command widget-backward &optional count
266 Move point @var{count} buttons or editing fields backward.
270 @node Programming Example, Setting Up the Buffer, User Interface, Top
271 @comment node-name, next, previous, up
272 @section Programming Example
274 Here is the code to implement the user interface example (see @ref{User
280 (defvar widget-example-repeat)
282 (defun widget-example ()
283 "Create the widgets from the Widget manual."
285 (switch-to-buffer "*Widget Example*")
286 (kill-all-local-variables)
287 (make-local-variable 'widget-example-repeat)
288 (let ((inhibit-read-only t))
290 (widget-insert "Here is some documentation.\n\nName: ")
291 (widget-create 'field
294 (widget-create 'choice
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 ")
309 :notify (lambda (&rest ignore)
310 (widget-value-set widget-example-repeat
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
321 (new (length (widget-value widget))))
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"))
335 (widget-insert " Thus\n\nSelect one:\n\n")
336 (widget-create 'radio
338 :notify (lambda (widget &rest ignore)
339 (message "You selected %s" (widget-value widget)))
340 '(item "One") '(item "Anthor One.") '(item "A Final One."))
343 :notify (lambda (&rest ignore)
344 (if (= (length (widget-value widget-example-repeat))
346 (message "Congratulation!")
347 (error "Three was the count!")))
351 :notify (lambda (&rest ignore)
355 (use-local-map widget-keymap)
359 @node Setting Up the Buffer, Basic Types, Programming Example, Top
360 @comment node-name, next, previous, up
361 @section Setting Up the Buffer
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
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}.
373 The keyword arguments can be used to overwrite the keyword arguments
374 that are part of @var{type}.
377 @defun widget-delete widget
378 Delete @var{widget} and remove it from the buffer.
382 Setup a buffer to support widgets.
384 This should be called after creating all the widgets and before allowing
385 the user to edit them.
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}.
393 Insert the arguments, either strings or characters, at point.
394 The inserted text will be read only.
397 There is a standard widget keymap which you might find useful.
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
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}.
412 @node Basic Types, Sexp Types, Setting Up the Buffer, Top
413 @comment node-name, next, previous, up
416 The syntax of a type specification is given below:
419 NAME ::= (NAME [KEYWORD ARGUMENT]... ARGS)
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.
427 There following keyword arguments that apply to all widgets:
431 The initial value for widgets of this type.
434 This string will be inserted in the buffer when you create a widget.
435 The following @samp{%} escapes are available:
440 The text inside will be marked as a button.
443 This will be replaces with the buffer representation of the widgets
444 value. What this is depends on the widget type.
447 Insert the string specified by @code{:doc} here.
450 Insert the string specified by @code{:tag} here, or the @code{princ}
451 representation of the value if there is no tag.
454 Insert a literal @samp{%}.
458 Face used to highlight text inside %[ %] in the format.
461 The string inserted by the @samp{%d} escape in the format
465 The string inserted by the @samp{%t} escape in the format
469 Message displayed whenever you move to the widget with either
470 @code{widget-forward} or @code{widget-backward}.
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
480 Tag used in the menu when the widget is used as an option in a
481 @code{choice} widget.
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.
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.
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.
500 The parent of a nested widget (e.g. a @code{choice} item or an element of a
501 @code{repeat} widget).
519 @node link, push, Basic Types, Basic Types
520 @comment node-name, next, previous, up
521 @subsection The @code{link} Widget
526 TYPE ::= (link [KEYWORD ARGUMENT]... [ VALUE ])
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
533 @node push, field, link, Basic Types
534 @comment node-name, next, previous, up
535 @subsection The @code{push} Widget
540 TYPE ::= (push [KEYWORD ARGUMENT]... [ VALUE ])
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
547 @node field, text, push, Basic Types
548 @comment node-name, next, previous, up
549 @subsection The @code{field} Widget
554 TYPE ::= (field [KEYWORD ARGUMENT]... [ VALUE ])
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.
561 The following extra properties are recognized.
565 The width of the editable field.@br
566 By default the field will reach to the end of the line.
569 Face used for highlighting the editable field. Default is
570 @code{widget-field-face}.
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
579 @node text, choice, field, Basic Types
580 @comment node-name, next, previous, up
581 @subsection The @code{text} Widget
583 This is just like @code{field}, but intended for multiline text
586 @node choice, radio, text, Basic Types
587 @comment node-name, next, previous, up
588 @subsection The @code{choice} Widget
593 TYPE ::= (choice [KEYWORD ARGUMENT]... TYPE ... )
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.
603 Widget type used as a fallback when the value does not match any of the
604 specified @var{type} arguments.
607 A list whose car is the widget representing the currently chosen type in
611 The current chosen type
617 @node radio, item, choice, Basic Types
618 @comment node-name, next, previous, up
619 @subsection The @code{radio} Widget
624 TYPE ::= (radio [KEYWORD ARGUMENT]... TYPE ... )
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.
632 The following extra properties are recognized.
636 This string will be inserted for each entry in the list.
637 The following @samp{%} escapes are available:
640 Replaced with the buffer representation of the @var{type} widget.
642 Replace with the radio button.
644 Insert a literal @samp{%}.
648 The widgets representing the radio buttons.
651 The widgets representing each type.
654 The current chosen type
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'.
663 @defun widget-radio-add-item widget type
664 Add to radio widget @var{widget} a new radio button item of type @var{type}.
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}.
671 @node item, choice-item, radio, Basic Types
672 @comment node-name, next, previous, up
673 @subsection The @code{item} Widget
678 ITEM ::= (item [KEYWORD ARGUMENT]... VALUE)
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.
685 @node choice-item, toggle, item, Basic Types
686 @comment node-name, next, previous, up
687 @subsection The @code{choice-item} Widget
692 ITEM ::= (choice-item [KEYWORD ARGUMENT]... VALUE)
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
701 @node toggle, checkbox, choice-item, Basic Types
702 @comment node-name, next, previous, up
703 @subsection The @code{toggle} Widget
708 TYPE ::= (toggle [KEYWORD ARGUMENT]...)
711 The widget has two possible states, `on' and `off', which corresponds to
712 a @code{t} or @code{nil} value.
714 The following extra properties are recognized.
718 String representing the `on' state. By default the string @samp{on}.
720 String representing the `off' state. By default the string @samp{off}.
722 Type representing the `on' state. By default an `item' widget displaying
723 the string specified with the @code{:on} keyword.
725 Type representing the `off' state. By default an `item' widget
726 displaying the string specified with the @code{:off} keyword.
729 @node checkbox, checklist, toggle, Basic Types
730 @comment node-name, next, previous, up
731 @subsection The @code{checkbox} Widget
733 The widget has two possible states, `selected' and `unselected', which
734 corresponds to a @code{t} or @code{nil} value.
739 TYPE ::= (checkbox [KEYWORD ARGUMENT]...)
742 @node checklist, repeat, checkbox, Basic Types
743 @comment node-name, next, previous, up
744 @subsection The @code{checklist} Widget
749 TYPE ::= (checklist [KEYWORD ARGUMENT]... TYPE ... )
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.
757 The following extra properties are recognized.
761 This string will be inserted for each entry in the list.
762 The following @samp{%} escapes are available:
765 Replaced with the buffer representation of the @var{type} widget.
767 Replace with the checkbox.
769 Insert a literal @samp{%}.
773 The widgets representing the checkboxes.
776 The widgets representing each type.
782 @node repeat, , checklist, Basic Types
783 @comment node-name, next, previous, up
784 @subsection The @code{repeat} Widget
789 TYPE ::= ([KEYWORD ARGUMENT]... TYPE)
792 The value is a list, where each member represent one widget of type
795 The following extra properties are recognized.
799 Number of spaces inserted before each member of the list, except for the
803 This string will be inserted for each entry in the list.
804 The following @samp{%} escapes are available:
807 This will be replaced with the buffer representation of the @var{type}
810 Insert the @b{[INS]} button.
812 Insert the @b{[DEL]} button.
814 Insert a literal @samp{%}.
818 The widgets representing the insert and delete buttons.
821 The widgets representing the elements of the list.
824 List whose car is the type of the list elements.
828 @node Sexp Types, Widget Properties, Basic Types, Top
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}.
842 @node generic, atoms, Sexp Types, Sexp Types
843 @comment node-name, next, previous, up
844 @subsection The Generic Widget.
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.
851 The syntax for the generic widgets is
854 TYPE ::= (const [KEYWORD ARGUMENT]... [ VALUE ])
857 The @var{value}, if present, is used to initialize the @code{:value}
858 property and can be any s-expression.
861 This will display any valid s-expression in an immutable part of the
866 This will allow you to edit any valid s-expression in an editable buffer
869 The @code{sexp} widget takes the same keyword arguments as the
873 @node atoms, composite, generic, Sexp Types
874 @comment node-name, next, previous, up
875 @subsection Atomic Sexp Widgets.
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.
881 The syntax for all the atoms are
884 TYPE ::= (NAME [KEYWORD ARGUMENT]... [ VALUE ])
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.
891 All the atom widgets take the same keyword arguments as the @code{field}
895 Allows you to edit a string in an editable field.
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
906 If this is set to non-nil, only existing file names will be allowed in
911 @deffn Widget directory
912 Allows you to edit a directory name in an editable field.
913 Similar to the @code{file} widget.
917 Allows you to edit a lisp symbol in an editable field.
920 @deffn Widget integer
921 Allows you to edit an integer in an editable field.
925 Allows you to edit a number in an editable field.
928 @node composite, , atoms, Sexp Types
929 @comment node-name, next, previous, up
930 @subsection Composite Sexp Widgets.
932 The syntax for the composite are
935 TYPE ::= (NAME [KEYWORD ARGUMENT]... COMPONENT...)
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.
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.
948 The value of a @code{cons} widget is a list containing the value of
949 each of its component.
953 The value of a @code{cons} widget is a vector containing the value of
954 each of its component.
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
975 The value of a widget of this type will either have the form
976 @samp{(file t)} or @code{(file string string)}.
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.
982 @node Widget Properties, Defining New Widgets, Sexp Types, Top
983 @comment node-name, next, previous, up
986 You can examine or set this value by using the widget object that was
987 returned by @code{widget-create}.
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.
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}.
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
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{:}.
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.
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}.
1022 @defun widget-member widget property
1023 Non-nil if @var{widget} has a value (even nil) for property @var{property}.
1026 @node Defining New Widgets, Widget Wishlist., Widget Properties, Top
1027 @comment node-name, next, previous, up
1028 @section Defining New Widgets
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
1035 @defun widget-define name class doc &rest args
1036 Define a new widget type named @var{name} from @code{class}.
1038 @var{name} and class should both be symbols, @code{class} should be one
1039 of the existing widget types.
1041 The third argument @var{DOC} is a documentation string for the widget.
1043 After the new widget has been defined, the following two calls will
1044 create identical widgets:
1049 (widget-create @var{name})
1054 (apply widget-create @var{class} @var{args})
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.
1064 If you just want to specify defaults for keywords with no complex
1065 conversions, you can use @code{identity} as your conversion function.
1067 The following additional keyword arguments are useful when defining new
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.
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}.
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}.
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.
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.
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.
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.
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.
1116 If you want to define a new widget from scratch, use the @code{default}
1119 @deffn Widget default [ keyword argument ]
1120 Widget used as a base for other widgets.
1122 It provides most of the functionality that is refered to as ``by
1123 default'' in this text.
1126 @node Widget Wishlist., , Defining New Widgets, Top
1127 @comment node-name, next, previous, up
1132 In general, we need @strong{much} better support for keyboard
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}).
1141 @kbd{C-k} should kill to end of field or end of line, whatever come
1145 Commands to move to the beginning/end of a field.
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).
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}
1161 There should be a way to probe a widget to see if the user has modified
1165 The support for indentation of component widgets should be finished.
1168 There should be support for browsing the widget documentation.
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.
1177 The @code{choice} tag should be prettier, something like the abbreviated
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.
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