4 @setfilename ../info/widget.info
5 @settitle The Emacs Widget Library
13 @dircategory XEmacs Editor
15 * Widgets: (widget). The Emacs Widget Library.
19 @node Top, Introduction, (dir), (dir)
20 @comment node-name, next, previous, up
21 @top The Emacs Widget Library
26 * Programming Example::
27 * Setting Up the Buffer::
31 * Defining New Widgets::
38 @node Introduction, User Interface, Top, Top
39 @comment node-name, next, previous, up
42 Most graphical user interface toolkits, such as Motif and XView, provide
43 a number of standard user interface controls (sometimes known as
44 `widgets' or `gadgets'). Emacs doesn't really support anything like
45 this, except for an incredible powerful text ``widget''. On the other
46 hand, Emacs does provide the necessary primitives to implement many
47 other widgets within a text buffer. The @code{widget} package
50 The basic widgets are:
54 Areas of text with an associated action. Intended for hypertext links
57 Like link, but intended for stand-alone buttons.
59 An editable text field. It can be either variable or fixed length.
61 Allows the user to choose one of multiple options from a menu, each
62 option is itself a widget. Only the selected option will be visible in
64 @item radio-button-choice
65 Allows the user to choose one of multiple options by activating radio
66 buttons. The options are implemented as widgets. All options will be
67 visible in the buffer.
69 A simple constant widget intended to be used in the @code{menu-choice} and
70 @code{radio-button-choice} widgets.
72 A button item only intended for use in choices. When invoked, the user
73 will be asked to select another option from the choice widget.
75 A simple @samp{on}/@samp{off} switch.
77 A checkbox (@samp{[ ]}/@samp{[X]}).
79 Create an editable list. The user can insert or delete items in the
80 list. Each list item is itself a widget.
83 Now of what possible use can support for widgets be in a text editor?
84 I'm glad you asked. The answer is that widgets are useful for
85 implementing forms. A @dfn{form} in emacs is a buffer where the user is
86 supposed to fill out a number of fields, each of which has a specific
87 meaning. The user is not supposed to change or delete any of the text
88 between the fields. Examples of forms in Emacs are the @file{forms}
89 package (of course), the customize buffers, the mail and news compose
90 modes, and the @sc{html} form support in the @file{w3} browser.
92 The advantages for a programmer of using the @code{widget} package to
97 More complex fields than just editable text are supported.
99 You can give the user immediate feedback if he enters invalid data in a
100 text field, and sometimes prevent entering invalid data.
102 You can have fixed sized fields, thus allowing multiple field to be
105 It is simple to query or set the value of a field.
107 Editing happens in buffer, not in the mini-buffer.
109 Packages using the library get a uniform look, making them easier for
112 As support for embedded graphics improve, the widget library will
113 extended to support it. This means that your code using the widget
114 library will also use the new graphic features by automatic.
117 In order to minimize the code that is loaded by users who does not
118 create any widgets, the code has been split in two files:
122 This will declare the user variables, define the function
123 @code{widget-define}, and autoload the function @code{widget-create}.
125 Everything else is here, there is no reason to load it explicitly, as
126 it will be autoloaded when needed.
129 @node User Interface, Programming Example, Introduction, Top
130 @comment node-name, next, previous, up
131 @section User Interface
133 A form consists of read only text for documentation and some fields,
134 where each of the fields contains two parts, a tag and a value. The
135 tags are used to identify the fields, so the documentation can refer to
136 the foo field, meaning the field tagged with @samp{Foo}. Here is an
140 Here is some documentation.
142 Name: @i{My Name} @strong{Choose}: This option
143 Address: @i{Some Place
147 See also @b{_other work_} for more information.
149 Numbers: count to three below
150 @b{[INS]} @b{[DEL]} @i{One}
151 @b{[INS]} @b{[DEL]} @i{Eh, two?}
152 @b{[INS]} @b{[DEL]} @i{Five!}
167 @b{[Apply Form]} @b{[Reset Form]}
170 The top level widgets in is example are tagged @samp{Name},
171 @samp{Choose}, @samp{Address}, @samp{_other work_}, @samp{Numbers},
172 @samp{Select multiple}, @samp{Select one}, @samp{[Apply Form]}, and
173 @samp{[Reset Form]}. There are basically two thing the user can do within
174 a form, namely editing the editable text fields and activating the
177 @subsection Editable Text Fields
179 In the example, the value for the @samp{Name} is most likely displayed
180 in an editable text field, and so are values for each of the members of
181 the @samp{Numbers} list. All the normal Emacs editing operations are
182 available for editing these fields. The only restriction is that each
183 change you make must be contained within a single editable text field.
184 For example, capitalizing all text from the middle of one field to the
185 middle of another field is prohibited.
187 Editing text fields are created by the @code{editable-field} widget.
189 The editing text fields are highlighted with the
190 @code{widget-field-face} face, making them easy to find.
192 @deffn Face widget-field-face
193 Face used for other editing fields.
198 Some portions of the buffer have an associated @dfn{action}, which can
199 be @dfn{invoked} by a standard key or mouse command. These portions
200 are called @dfn{buttons}. The default commands for activating a button
205 @deffn Command widget-button-press @var{pos} &optional @var{event}
206 Invoke the button at @var{pos}, defaulting to point.
207 If point is not located on a button, invoke the binding in
208 @code{widget-global-map} (by default the global map).
212 @deffn Command widget-button-click @var{event}
213 Invoke the button at the location of the mouse pointer. If the mouse
214 pointer is located in an editable text field, invoke the binding in
215 @code{widget-global-map} (by default the global map).
219 There are several different kind of buttons, all of which are present in
223 @item The Option Field Tags.
224 When you invoke one of these buttons, you will be asked to choose
225 between a number of different options. This is how you edit an option
226 field. Option fields are created by the @code{menu-choice} widget. In
227 the example, @samp{@b{Choose}} is an option field tag.
228 @item The @samp{@b{[INS]}} and @samp{@b{[DEL]}} buttons.
229 Activating these will insert or delete elements from an editable list.
230 The list is created by the @code{editable-list} widget.
231 @item Embedded Buttons.
232 The @samp{@b{_other work_}} is an example of an embedded
233 button. Embedded buttons are not associated with a fields, but can serve
234 any purpose, such as implementing hypertext references. They are
235 usually created by the @code{link} widget.
236 @item The @samp{@b{[ ]}} and @samp{@b{[X]}} buttons.
237 Activating one of these will convert it to the other. This is useful
238 for implementing multiple-choice fields. You can create it wit
239 @item The @samp{@b{( )}} and @samp{@b{(*)}} buttons.
240 Only one radio button in a @code{radio-button-choice} widget can be
241 selected at any time. When you invoke one of the unselected radio
242 buttons, it will be selected and the previous selected radio button will
244 @item The @samp{@b{[Apply Form]}} @samp{@b{[Reset Form]}} buttons.
245 These are explicit buttons made with the @code{push-button} widget. The main
246 difference from the @code{link} widget is that the buttons are will be
247 displayed as GUI buttons when possible.
251 To make them easier to locate, buttons are emphasized in the buffer.
253 @deffn Face widget-button-face
254 Face used for buttons.
257 @defopt widget-mouse-face
258 Face used for buttons when the mouse pointer is above it.
261 @subsection Navigation
263 You can use all the normal Emacs commands to move around in a form
264 buffer, plus you will have these additional commands:
268 @deffn Command widget-forward &optional count
269 Move point @var{count} buttons or editing fields forward.
272 @deffn Command widget-backward &optional count
273 Move point @var{count} buttons or editing fields backward.
277 @node Programming Example, Setting Up the Buffer, User Interface, Top
278 @comment node-name, next, previous, up
279 @section Programming Example
281 Here is the code to implement the user interface example (see @ref{User
290 (defvar widget-example-repeat)
292 (defun widget-example ()
293 "Create the widgets from the Widget manual."
295 (kill-buffer (get-buffer-create "*Widget Example*"))
296 (switch-to-buffer (get-buffer-create "*Widget Example*"))
297 (kill-all-local-variables)
298 (make-local-variable 'widget-example-repeat)
299 (widget-insert "Here is some documentation.\n\nName: ")
300 (widget-create 'editable-field
303 (widget-create 'menu-choice
306 :help-echo "Choose me, please!"
307 :notify (lambda (widget &rest ignore)
308 (message "%s is a good choice!"
309 (widget-value widget)))
310 '(item :tag "This option" :value "This")
311 '(choice-item "That option")
312 '(editable-field :menu-tag "No option" "Thus option"))
313 (widget-insert "Address: ")
314 (widget-create 'editable-field
315 "Some Place\nIn some City\nSome country.")
316 (widget-insert "\nSee also ")
318 :notify (lambda (&rest ignore)
319 (widget-value-set widget-example-repeat
323 (widget-insert " for more information.\n\nNumbers: count to three below\n")
324 (setq widget-example-repeat
325 (widget-create 'editable-list
326 :entry-format "%i %d %v"
327 :notify (lambda (widget &rest ignore)
328 (let ((old (widget-get widget
330 (new (length (widget-value widget))))
332 (widget-put widget ':example-length new)
333 (message "You can count to %d." new))))
334 :value '("One" "Eh, two?" "Five!")
335 '(editable-field :value "three")))
336 (widget-insert "\n\nSelect multiple:\n\n")
337 (widget-create 'checkbox t)
338 (widget-insert " This\n")
339 (widget-create 'checkbox nil)
340 (widget-insert " That\n")
341 (widget-create 'checkbox
342 :notify (lambda (&rest ignore) (message "Tickle"))
344 (widget-insert " Thus\n\nSelect one:\n\n")
345 (widget-create 'radio-button-choice
347 :notify (lambda (widget &rest ignore)
348 (message "You selected %s"
349 (widget-value widget)))
350 '(item "One") '(item "Another One.") '(item "A Final One."))
352 (widget-create 'push-button
353 :notify (lambda (&rest ignore)
354 (if (= (length (widget-value widget-example-repeat))
356 (message "Congratulation!")
357 (error "Three was the count!")))
360 (widget-create 'push-button
361 :notify (lambda (&rest ignore)
365 (use-local-map widget-keymap)
369 @node Setting Up the Buffer, Basic Types, Programming Example, Top
370 @comment node-name, next, previous, up
371 @section Setting Up the Buffer
373 Widgets are created with @code{widget-create}, which returns a
374 @dfn{widget} object. This object can be queried and manipulated by
375 other widget functions, until it is deleted with @code{widget-delete}.
376 After the widgets have been created, @code{widget-setup} must be called
379 @defun widget-create type [ keyword argument ]@dots{}
380 Create and return a widget of type @var{type}.
381 The syntax for the @var{type} argument is described in @ref{Basic Types}.
383 The keyword arguments can be used to overwrite the keyword arguments
384 that are part of @var{type}.
387 @defun widget-delete widget
388 Delete @var{widget} and remove it from the buffer.
392 Setup a buffer to support widgets.
394 This should be called after creating all the widgets and before allowing
395 the user to edit them.
399 If you want to insert text outside the widgets in the form, the
400 recommended way to do that is with @code{widget-insert}.
403 Insert the arguments, either strings or characters, at point.
404 The inserted text will be read only.
407 There is a standard widget keymap which you might find useful.
409 @defvr Const widget-keymap
410 A keymap with the global keymap as its parent.@*
411 @key{TAB} and @kbd{C-@key{TAB}} are bound to @code{widget-forward} and
412 @code{widget-backward}, respectively. @kbd{@key{RET}} and @kbd{mouse-2}
413 are bound to @code{widget-button-press} and
414 @code{widget-button-}.@refill
417 @defvar widget-global-map
418 Keymap used by @code{widget-button-press} and @code{widget-button-click}
419 when not on a button. By default this is @code{global-map}.
422 @node Basic Types, Sexp Types, Setting Up the Buffer, Top
423 @comment node-name, next, previous, up
426 The syntax of a type specification is given below:
429 NAME ::= (NAME [KEYWORD ARGUMENT]... ARGS)
433 where @var{name} is a widget name, @var{keyword} is the name of a
434 property, @var{argument} is the value of the property, and @var{args}
435 are interpreted in a widget specific way.
437 There following keyword arguments that apply to all widgets:
441 The initial value for widgets of this type.
444 This string will be inserted in the buffer when you create a widget.
445 The following @samp{%} escapes are available:
450 The text inside will be marked as a button.
452 By default, the text will be shown in @code{widget-button-face}, and
453 surrounded by brackets.
455 @defopt widget-button-prefix
456 String to prefix buttons.
459 @defopt widget-button-suffix
460 String to suffix buttons.
465 The text inside will be displayed in the face specified by
469 This will be replaced with the buffer representation of the widget's
470 value. What this is depends on the widget type.
473 Insert the string specified by @code{:doc} here.
476 Like @samp{%d}, with the following modifications: If the documentation
477 string is more than one line, it will add a button which will toggle
478 between showing only the first line, and showing the full text.
479 Furthermore, if there is no @code{:doc} property in the widget, it will
480 instead examine the @code{:documentation-property} property. If it is a
481 lambda expression, it will be called with the widget's value as an
482 argument, and the result will be used as the documentation text.
485 Insert the string specified by @code{:tag} here, or the @code{princ}
486 representation of the value if there is no tag.
489 Insert a literal @samp{%}.
493 Face used to highlight text inside %[ %] in the format.
496 @itemx :button-suffix
498 Text around %[ %] in the format.
506 The string is inserted literally.
509 The value of the symbol is expanded according to this table.
513 The string inserted by the @samp{%d} or @samp{%h} escape in the format
517 The string inserted by the @samp{%t} escape in the format
521 Name of image to use instead of the string specified by `:tag' on
522 Emacsen that supports it.
525 Message displayed whenever you move to the widget with either
526 @code{widget-forward} or @code{widget-backward}.
529 An integer indicating the absolute number of spaces to indent children
533 An integer indicating how many extra spaces to add to the widget's
534 grandchildren compared to this widget.
537 An integer indicating how many extra spaces to add to the widget's
538 children compared to this widget.
541 A function called each time the widget or a nested widget is changed.
542 The function is called with two or three arguments. The first argument
543 is the widget itself, the second argument is the widget that was
544 changed, and the third argument is the event leading to the change, if
548 Tag used in the menu when the widget is used as an option in a
549 @code{menu-choice} widget.
552 Function used for finding the tag when the widget is used as an option
553 in a @code{menu-choice} widget. By default, the tag used will be either the
554 @code{:menu-tag} or @code{:tag} property if present, or the @code{princ}
555 representation of the @code{:value} property if not.
558 Should be a function called with two arguments, the widget and a value,
559 and returning non-nil if the widget can represent the specified value.
562 A function which takes a widget as an argument, and returns nil if the
563 widget's current value is valid for the widget. Otherwise it should
564 return the widget containing the invalid data, and set that widget's
565 @code{:error} property to a string explaining the error.
567 The following predefined function can be used:
569 @defun widget-children-validate widget
570 All the @code{:children} of @var{widget} must be valid.
574 Specify the order in which widgets are traversed with
575 @code{widget-forward} or @code{widget-backward}. This is only partially
580 Widgets with tabbing order @code{-1} are ignored.
583 (Unimplemented) When on a widget with tabbing order @var{n}, go to the
584 next widget in the buffer with tabbing order @var{n+1} or @code{nil},
585 whichever comes first.
588 When on a widget with no tabbing order specified, go to the next widget
589 in the buffer with a positive tabbing order, or @code{nil}
593 The parent of a nested widget (e.g. a @code{menu-choice} item or an
594 element of an @code{editable-list} widget).
597 This keyword is only used for members of a @code{radio-button-choice} or
598 @code{checklist}. The value should be a list of extra keyword
599 arguments, which will be used when creating the @code{radio-button} or
600 @code{checkbox} associated with this item.
604 @deffn {User Option} widget-glyph-directory
605 Directory where glyphs are found.
606 Widget will look here for a file with the same name as specified for the
607 image, with either a @samp{.xpm} (if supported) or @samp{.xbm} extension.
610 @deffn{User Option} widget-glyph-enable
611 If non-nil, allow glyphs to appear on displays where they are supported.
623 * radio-button-choice::
633 @node link, url-link, Basic Types, Basic Types
634 @comment node-name, next, previous, up
635 @subsection The @code{link} Widget
640 TYPE ::= (link [KEYWORD ARGUMENT]... [ VALUE ])
643 The @var{value}, if present, is used to initialize the @code{:value}
644 property. The value should be a string, which will be inserted in the
647 By default the link will be shown in brackets.
649 @defopt widget-link-prefix
650 String to prefix links.
653 @defopt widget-link-suffix
654 String to suffix links.
657 @node url-link, info-link, link, Basic Types
658 @comment node-name, next, previous, up
659 @subsection The @code{url-link} Widget
664 TYPE ::= (url-link [KEYWORD ARGUMENT]... URL)
667 When this link is invoked, the @sc{www} browser specified by
668 @code{browse-url-browser-function} will be called with @var{url}.
670 @node info-link, push-button, url-link, Basic Types
671 @comment node-name, next, previous, up
672 @subsection The @code{info-link} Widget
677 TYPE ::= (info-link [KEYWORD ARGUMENT]... ADDRESS)
680 When this link is invoked, the built-in info browser is started on
683 @node push-button, editable-field, info-link, Basic Types
684 @comment node-name, next, previous, up
685 @subsection The @code{push-button} Widget
690 TYPE ::= (push-button [KEYWORD ARGUMENT]... [ VALUE ])
693 The @var{value}, if present, is used to initialize the @code{:value}
694 property. The value should be a string, which will be inserted in the
697 By default the tag will be shown in brackets.
699 @defopt widget-push-button-prefix
700 String to prefix push buttons.
703 @defopt widget-push-button-suffix
704 String to suffix push buttons.
707 @node editable-field, text, push-button, Basic Types
708 @comment node-name, next, previous, up
709 @subsection The @code{editable-field} Widget
714 TYPE ::= (editable-field [KEYWORD ARGUMENT]... [ VALUE ])
717 The @var{value}, if present, is used to initialize the @code{:value}
718 property. The value should be a string, which will be inserted in
719 field. This widget will match all string values.
721 The following extra properties are recognized.
725 The minimum width of the editable field.@*
726 By default the field will reach to the end of the line. If the
727 content is too large, the displayed representation will expand to
728 contain it. The content is not truncated to size.
731 Face used for highlighting the editable field. Default is
732 @code{widget-field-face}.
735 Character used to display the value. You can set this to e.g. @code{?*}
736 if the field contains a password or other secret information. By
737 default, the value is not secret.
740 By default the @code{:validate} function will match the content of the
741 field with the value of this attribute. The default value is @code{""}
742 which matches everything.
745 Keymap used in the editable field. The default value is
746 @code{widget-field-keymap}, which allows you to use all the normal
747 editing commands, even if the buffer's major mode suppress some of them.
748 Pressing return invokes the function specified by @code{:action}.
751 @node text, menu-choice, editable-field, Basic Types
752 @comment node-name, next, previous, up
753 @subsection The @code{text} Widget
755 This is just like @code{editable-field}, but intended for multiline text
756 fields. The default @code{:keymap} is @code{widget-text-keymap}, which
757 does not rebind the return key.
759 @node menu-choice, radio-button-choice, text, Basic Types
760 @comment node-name, next, previous, up
761 @subsection The @code{menu-choice} Widget
766 TYPE ::= (menu-choice [KEYWORD ARGUMENT]... TYPE ... )
769 The @var{type} argument represents each possible choice. The widget's
770 value will be that of the chosen @var{type} argument. This widget will
771 match any value matching at least one of the specified @var{type}
776 Widget type used as a fallback when the value does not match any of the
777 specified @var{type} arguments.
780 Set this to nil if you don't want to ignore case when prompting for a
781 choice through the minibuffer.
784 A list whose car is the widget representing the currently chosen type in
788 The current chosen type
794 @node radio-button-choice, item, menu-choice, Basic Types
795 @comment node-name, next, previous, up
796 @subsection The @code{radio-button-choice} Widget
801 TYPE ::= (radio-button-choice [KEYWORD ARGUMENT]... TYPE ... )
804 The @var{type} argument represents each possible choice. The widget's
805 value will be that of the chosen @var{type} argument. This widget will
806 match any value matching at least one of the specified @var{type}
809 The following extra properties are recognized.
813 This string will be inserted for each entry in the list.
814 The following @samp{%} escapes are available:
817 Replaced with the buffer representation of the @var{type} widget.
819 Replace with the radio button.
821 Insert a literal @samp{%}.
825 A list of keywords to pass to the radio buttons. Useful for setting
826 e.g. the @samp{:help-echo} for each button.
829 The widgets representing the radio buttons.
832 The widgets representing each type.
835 The current chosen type
841 You can add extra radio button items to a @code{radio-button-choice}
842 widget after it has been created with the function
843 @code{widget-radio-add-item}.
845 @defun widget-radio-add-item widget type
846 Add to @code{radio-button-choice} widget @var{widget} a new radio button item of type
850 Please note that such items added after the @code{radio-button-choice}
851 widget has been created will @strong{not} be properly destructed when
852 you call @code{widget-delete}.
854 @node item, choice-item, radio-button-choice, Basic Types
855 @comment node-name, next, previous, up
856 @subsection The @code{item} Widget
861 ITEM ::= (item [KEYWORD ARGUMENT]... VALUE)
864 The @var{value}, if present, is used to initialize the @code{:value}
865 property. The value should be a string, which will be inserted in the
866 buffer. This widget will only match the specified value.
868 @node choice-item, toggle, item, Basic Types
869 @comment node-name, next, previous, up
870 @subsection The @code{choice-item} Widget
875 ITEM ::= (choice-item [KEYWORD ARGUMENT]... VALUE)
878 The @var{value}, if present, is used to initialize the @code{:value}
879 property. The value should be a string, which will be inserted in the
880 buffer as a button. Activating the button of a @code{choice-item} is
881 equivalent to activating the parent widget. This widget will only match
884 @node toggle, checkbox, choice-item, Basic Types
885 @comment node-name, next, previous, up
886 @subsection The @code{toggle} Widget
891 TYPE ::= (toggle [KEYWORD ARGUMENT]...)
894 The widget has two possible states, `on' and `off', which correspond to
895 a @code{t} or @code{nil} value respectively.
897 The following extra properties are recognized.
901 String representing the `on' state. By default the string @samp{on}.
903 String representing the `off' state. By default the string @samp{off}.
905 Name of a glyph to be used instead of the `:on' text string, on emacsen
908 Name of a glyph to be used instead of the `:off' text string, on emacsen
912 @node checkbox, checklist, toggle, Basic Types
913 @comment node-name, next, previous, up
914 @subsection The @code{checkbox} Widget
916 The widget has two possible states, `selected' and `unselected', which
917 corresponds to a @code{t} or @code{nil} value.
922 TYPE ::= (checkbox [KEYWORD ARGUMENT]...)
925 @node checklist, editable-list, checkbox, Basic Types
926 @comment node-name, next, previous, up
927 @subsection The @code{checklist} Widget
932 TYPE ::= (checklist [KEYWORD ARGUMENT]... TYPE ... )
935 The @var{type} arguments represents each checklist item. The widget's
936 value will be a list containing the values of all ticked @var{type}
937 arguments. The checklist widget will match a list whose elements all
938 match at least one of the specified @var{type} arguments.
940 The following extra properties are recognized.
944 This string will be inserted for each entry in the list.
945 The following @samp{%} escapes are available:
948 Replaced with the buffer representation of the @var{type} widget.
950 Replace with the checkbox.
952 Insert a literal @samp{%}.
956 Usually a checklist will only match if the items are in the exact
957 sequence given in the specification. By setting @code{:greedy} to
958 non-nil, it will allow the items to appear in any sequence. However, if
959 you extract the values they will be in the sequence given in the
960 checklist. I.e. the original sequence is forgotten.
963 A list of keywords to pass to the checkboxes. Useful for setting
964 e.g. the @samp{:help-echo} for each checkbox.
967 The widgets representing the checkboxes.
970 The widgets representing each type.
976 @node editable-list, group, checklist, Basic Types
977 @comment node-name, next, previous, up
978 @subsection The @code{editable-list} Widget
983 TYPE ::= (editable-list [KEYWORD ARGUMENT]... TYPE)
986 The value is a list, where each member represents one widget of type
989 The following extra properties are recognized.
993 This string will be inserted for each entry in the list.
994 The following @samp{%} escapes are available:
997 This will be replaced with the buffer representation of the @var{type}
1000 Insert the @b{[INS]} button.
1002 Insert the @b{[DEL]} button.
1004 Insert a literal @samp{%}.
1007 @item :insert-button-args
1008 A list of keyword arguments to pass to the insert buttons.
1010 @item :delete-button-args
1011 A list of keyword arguments to pass to the delete buttons.
1013 @item :append-button-args
1014 A list of keyword arguments to pass to the trailing insert button.
1018 The widgets representing the insert and delete buttons.
1021 The widgets representing the elements of the list.
1024 List whose car is the type of the list elements.
1028 @node group, , editable-list, Basic Types
1029 @comment node-name, next, previous, up
1030 @subsection The @code{group} Widget
1032 This widget simply groups other widgets together.
1037 TYPE ::= (group [KEYWORD ARGUMENT]... TYPE...)
1040 The value is a list, with one member for each @var{type}.
1042 @node Sexp Types, Widget Properties, Basic Types, Top
1046 A number of widgets for editing s-expressions (lisp types) are also
1047 available. These basically fall in the following categories.
1056 @node constants, generic, Sexp Types, Sexp Types
1057 @comment node-name, next, previous, up
1058 @subsection The Constant Widgets.
1060 The @code{const} widget can contain any lisp expression, but the user is
1061 prohibited from editing it, which is mainly useful as a component of one
1062 of the composite widgets.
1064 The syntax for the @code{const} widget is
1067 TYPE ::= (const [KEYWORD ARGUMENT]... [ VALUE ])
1070 The @var{value}, if present, is used to initialize the @code{:value}
1071 property and can be any s-expression.
1074 This will display any valid s-expression in an immutable part of the
1078 There are two variations of the @code{const} widget, namely
1079 @code{variable-item} and @code{function-item}. These should contain a
1080 symbol with a variable or function binding. The major difference from
1081 the @code{const} widget is that they will allow the user to see the
1082 variable or function documentation for the symbol.
1084 @deffn Widget variable-item
1085 An immutable symbol that is bound as a variable.
1088 @deffn Widget function-item
1089 An immutable symbol that is bound as a function.
1092 @node generic, atoms, constants, Sexp Types
1093 @comment node-name, next, previous, up
1094 @subsection Generic Sexp Widget.
1096 The @code{sexp} widget can contain any lisp expression, and allows the
1097 user to edit it inline in the buffer.
1099 The syntax for the @code{sexp} widget is
1102 TYPE ::= (sexp [KEYWORD ARGUMENT]... [ VALUE ])
1106 This will allow you to edit any valid s-expression in an editable buffer
1109 The @code{sexp} widget takes the same keyword arguments as the
1110 @code{editable-field} widget.
1113 @node atoms, composite, generic, Sexp Types
1114 @comment node-name, next, previous, up
1115 @subsection Atomic Sexp Widgets.
1117 The atoms are s-expressions that does not consist of other
1118 s-expressions. A string is an atom, while a list is a composite type.
1119 You can edit the value of an atom with the following widgets.
1121 The syntax for all the atoms are
1124 TYPE ::= (NAME [KEYWORD ARGUMENT]... [ VALUE ])
1127 The @var{value}, if present, is used to initialize the @code{:value}
1128 property and must be an expression of the same type as the widget.
1129 I.e. the string widget can only be initialized with a string.
1131 All the atom widgets take the same keyword arguments as the
1132 @code{editable-field} widget.
1134 @deffn Widget string
1135 Allows you to edit a string in an editable field.
1138 @deffn Widget regexp
1139 Allows you to edit a regular expression in an editable field.
1142 @deffn Widget character
1143 Allows you to enter a character in an editable field.
1147 Allows you to edit a file name in an editable field. If you invoke
1148 the tag button, you can edit the file name in the mini-buffer with
1154 If this is set to non-nil, only existing file names will be allowed in
1159 @deffn Widget directory
1160 Allows you to edit a directory name in an editable field.
1161 Similar to the @code{file} widget.
1164 @deffn Widget symbol
1165 Allows you to edit a lisp symbol in an editable field.
1168 @deffn Widget function
1169 Allows you to edit a lambda expression, or a function name with completion.
1172 @deffn Widget variable
1173 Allows you to edit a variable name, with completion.
1176 @deffn Widget integer
1177 Allows you to edit an integer in an editable field.
1180 @deffn Widget number
1181 Allows you to edit a number in an editable field.
1184 @deffn Widget boolean
1185 Allows you to edit a boolean. In lisp this means a variable which is
1186 either nil meaning false, or non-nil meaning true.
1190 @node composite, , atoms, Sexp Types
1191 @comment node-name, next, previous, up
1192 @subsection Composite Sexp Widgets.
1194 The syntax for the composite are
1197 TYPE ::= (NAME [KEYWORD ARGUMENT]... COMPONENT...)
1200 Where each @var{component} must be a widget type. Each component widget
1201 will be displayed in the buffer, and be editable to the user.
1204 The value of a @code{cons} widget is a cons-cell where the car is the
1205 value of the first component and the cdr is the value of the second
1206 component. There must be exactly two components.
1210 The value of a @code{list} widget is a list containing the value of
1211 each of its component.
1214 @deffn Widget vector
1215 The value of a @code{vector} widget is a vector containing the value of
1216 each of its component.
1219 The above suffice for specifying fixed size lists and vectors. To get
1220 variable length lists and vectors, you can use a @code{choice},
1221 @code{set} or @code{repeat} widgets together with the @code{:inline}
1222 keywords. If any component of a composite widget has the @code{:inline}
1223 keyword set, its value must be a list which will then be spliced into
1224 the composite. For example, to specify a list whose first element must
1225 be a file name, and whose remaining arguments should either by the
1226 symbol @code{t} or two files, you can use the following widget
1233 :value ("foo" "bar")
1237 The value of a widget of this type will either have the form
1238 @samp{(file t)} or @code{(file string string)}.
1240 This concept of inline is probably hard to understand. It was certainly
1241 hard to implement so instead of confusing you more by trying to explain
1242 it here, I'll just suggest you meditate over it for a while.
1244 @deffn Widget choice
1245 Allows you to edit a sexp which may have one of a fixed set of types.
1246 It is currently implemented with the @code{choice-menu} basic widget,
1247 and has a similar syntax.
1251 Allows you to specify a type which must be a list whose elements all
1252 belong to given set. The elements of the list is not significant. This
1253 is implemented on top of the @code{checklist} basic widget, and has a
1257 @deffn Widget repeat
1258 Allows you to specify a variable length list whose members are all of
1259 the same type. Implemented on top of the `editable-list' basic widget,
1260 and has a similar syntax.
1263 @node Widget Properties, Defining New Widgets, Sexp Types, Top
1264 @comment node-name, next, previous, up
1267 You can examine or set the value of a widget by using the widget object
1268 that was returned by @code{widget-create}.
1270 @defun widget-value widget
1271 Return the current value contained in @var{widget}.
1272 It is an error to call this function on an uninitialized widget.
1275 @defun widget-value-set widget value
1276 Set the value contained in @var{widget} to @var{value}.
1277 It is an error to call this function with an invalid @var{value}.
1280 @strong{Important:} You @emph{must} call @code{widget-setup} after
1281 modifying the value of a widget before the user is allowed to edit the
1282 widget again. It is enough to call @code{widget-setup} once if you
1283 modify multiple widgets. This is currently only necessary if the widget
1284 contains an editing field, but may be necessary for other widgets in the
1287 If your application needs to associate some information with the widget
1288 objects, for example a reference to the item being edited, it can be
1289 done with @code{widget-put} and @code{widget-get}. The property names
1290 must begin with a @samp{:}.
1292 @defun widget-put widget property value
1293 In @var{widget} set @var{property} to @var{value}.
1294 @var{property} should be a symbol, while @var{value} can be anything.
1297 @defun widget-get widget property
1298 In @var{widget} return the value for @var{property}.
1299 @var{property} should be a symbol, the value is what was last set by
1300 @code{widget-put} for @var{property}.
1303 @defun widget-member widget property
1304 Non-nil if @var{widget} has a value (even nil) for property @var{property}.
1307 Occasionally it can be useful to know which kind of widget you have,
1308 i.e. the name of the widget type you gave when the widget was created.
1310 @defun widget-type widget
1311 Return the name of @var{widget}, a symbol.
1314 Widgets can be in two states: active, which means they are modifiable by
1315 the user, or inactive, which means they cannot be modified by the user.
1316 You can query or set the state with the following code:
1319 ;; Examine if @var{widget} is active or not.
1320 (if (widget-apply @var{widget} :active)
1321 (message "Widget is active.")
1322 (message "Widget is inactive.")
1324 ;; Make @var{widget} inactive.
1325 (widget-apply @var{widget} :deactivate)
1327 ;; Make @var{widget} active.
1328 (widget-apply @var{widget} :activate)
1331 A widget is inactive if itself or any of its ancestors (found by
1332 following the @code{:parent} link) have been deactivated. To make sure
1333 a widget is really active, you must therefore activate both itself and
1338 (widget-apply widget :activate)
1339 (setq widget (widget-get widget :parent)))
1342 You can check if a widget has been made inactive by examining the value
1343 of the @code{:inactive} keyword. If this is non-nil, the widget itself
1344 has been deactivated. This is different from using the @code{:active}
1345 keyword, in that the latter tells you if the widget @strong{or} any of
1346 its ancestors have been deactivated. Do not attempt to set the
1347 @code{:inactive} keyword directly. Use the @code{:activate}
1348 @code{:deactivate} keywords instead.
1351 @node Defining New Widgets, Widget Browser, Widget Properties, Top
1352 @comment node-name, next, previous, up
1353 @section Defining New Widgets
1355 You can define specialized widgets with @code{define-widget}. It allows
1356 you to create a shorthand for more complex widgets. This includes
1357 specifying component widgets and new default values for the keyword
1360 @defun widget-define name class doc &rest args
1361 Define a new widget type named @var{name} from @code{class}.
1363 @var{name} and class should both be symbols, @code{class} should be one
1364 of the existing widget types.
1366 The third argument @var{DOC} is a documentation string for the widget.
1368 After the new widget has been defined the following two calls will
1369 create identical widgets:
1374 (widget-create @var{name})
1379 (apply widget-create @var{class} @var{args})
1385 Using @code{widget-define} just stores the definition of the widget type
1386 in the @code{widget-type} property of @var{name}, which is what
1387 @code{widget-create} uses.
1389 If you just want to specify defaults for keywords with no complex
1390 conversions, you can use @code{identity} as your conversion function.
1392 The following additional keyword arguments are useful when defining new
1395 @item :convert-widget
1396 Function to convert a widget type before creating a widget of that
1397 type. It takes a widget type as an argument, and returns the converted
1398 widget type. When a widget is created, this function is called for the
1399 widget type and all the widget's parent types, most derived first.
1401 The following predefined functions can be used here:
1403 @defun widget-types-convert-widget widget
1404 Convert @code{:args} as widget types in @var{widget}.
1407 @defun widget-value-convert-widget widget
1408 Initialize @code{:value} from @code{:args} in @var{widget}.
1411 @item :value-to-internal
1412 Function to convert the value to the internal format. The function
1413 takes two arguments, a widget and an external value. It returns the
1414 internal value. The function is called on the present @code{:value}
1415 when the widget is created, and on any value set later with
1416 @code{widget-value-set}.
1418 @item :value-to-external
1419 Function to convert the value to the external format. The function
1420 takes two arguments, a widget and an internal value, and returns the
1421 internal value. The function is called on the present @code{:value}
1422 when the widget is created, and on any value set later with
1423 @code{widget-value-set}.
1426 Function to create a widget from scratch. The function takes one
1427 argument, a widget type, and creates a widget of that type, inserts it
1428 in the buffer, and returns a widget object.
1431 Function to delete a widget. The function takes one argument, a widget,
1432 and should remove all traces of the widget from the buffer.
1435 Function to expand the @samp{%v} escape in the format string. It will
1436 be called with the widget as its argument and should insert a
1437 representation of the widget's value in the buffer.
1440 Should remove the representation of the widget's value from the buffer.
1441 It will be called with the widget as its argument. It doesn't have to
1442 remove the text, but it should release markers and delete nested widgets
1443 if such have been used.
1445 The following predefined function can be used here:
1447 @defun widget-children-value-delete widget
1448 Delete all @code{:children} and @code{:buttons} in @var{widget}.
1452 Function to extract the value of a widget, as it is displayed in the
1455 The following predefined function can be used here:
1457 @defun widget-value-value-get widget
1458 Return the @code{:value} property of @var{widget}.
1461 @item :format-handler
1462 Function to handle unknown @samp{%} escapes in the format string. It
1463 will be called with the widget and the escape character as arguments.
1464 You can set this to allow your widget to handle non-standard escapes.
1466 You should end up calling @code{widget-default-format-handler} to handle
1467 unknown escape sequences. It will handle the @samp{%h} and any future
1468 escape sequences as well as give an error for unknown escapes.
1471 Function to handle user initiated events. By default, @code{:notify}
1474 The following predefined function can be used here:
1476 @defun widget-parent-action widget &optional event
1477 Tell @code{:parent} of @var{widget} to handle the @code{:action}.@*
1478 Optional @var{event} is the event that triggered the action.
1482 Function to prompt for a value in the minibuffer. The function should
1483 take four arguments, @var{widget}, @var{prompt}, @var{value}, and
1484 @var{unbound} and should return a value for widget entered by the user.
1485 @var{prompt} is the prompt to use. @var{value} is the default value to
1486 use, unless @var{unbound} is non-nil. In this case there is no default
1487 value. The function should read the value using the method most natural
1488 for this widget and does not have to check whether it matches.
1491 If you want to define a new widget from scratch, use the @code{default}
1494 @deffn Widget default
1495 Widget used as a base for other widgets.
1497 It provides most of the functionality that is referred to as ``by
1498 default'' in this text.
1501 @node Widget Browser, Widget Minor Mode, Defining New Widgets, Top
1502 @comment node-name, next, previous, up
1503 @section Widget Browser
1505 There is a separate package to browse widgets. This is intended to help
1506 programmers who want to examine the content of a widget. The browser
1507 shows the value of each keyword, but uses links for certain keywords
1508 such as `:parent', which avoids printing cyclic structures.
1510 @deffn Command widget-browse WIDGET
1511 Create a widget browser for WIDGET.
1512 When called interactively, prompt for WIDGET.
1515 @deffn Command widget-browse-other-window WIDGET
1516 Create a widget browser for WIDGET and show it in another window.
1517 When called interactively, prompt for WIDGET.
1520 @deffn Command widget-browse-at POS
1521 Create a widget browser for the widget at POS.
1522 When called interactively, use the position of point.
1525 @node Widget Minor Mode, Utilities, Widget Browser, Top
1526 @comment node-name, next, previous, up
1527 @section Widget Minor Mode
1529 There is a minor mode for manipulating widgets in major modes that
1530 doesn't provide any support for widgets themselves. This is mostly
1531 intended to be useful for programmers doing experiments.
1533 @deffn Command widget-minor-mode
1534 Toggle minor mode for traversing widgets.
1535 With arg, turn widget mode on if and only if arg is positive.
1538 @defvar widget-minor-mode-keymap
1539 Keymap used in @code{widget-minor-mode}.
1542 @node Utilities, Widget Wishlist, Widget Minor Mode, Top
1543 @comment node-name, next, previous, up
1546 @defun widget-prompt-value widget prompt [ value unbound ]
1547 Prompt for a value matching @var{widget}, using @var{prompt}.@*
1548 The current value is assumed to be @var{value}, unless @var{unbound} is
1552 @defun widget-get-sibling widget
1553 Get the item @var{widget} is assumed to toggle.@*
1554 This is only meaningful for radio buttons or checkboxes in a list.
1557 @node Widget Wishlist, , Utilities, Top
1558 @comment node-name, next, previous, up
1563 It should be possible to add or remove items from a list with @kbd{C-k}
1564 and @kbd{C-o} (suggested by @sc{rms}).
1567 The @samp{[INS]} and @samp{[DEL]} buttons should be replaced by a single
1568 dash (@samp{-}). The dash should be a button that, when invoked, ask
1569 whether you want to add or delete an item (@sc{rms} wanted to git rid of
1570 the ugly buttons, the dash is my idea).
1573 The @code{menu-choice} tag should be prettier, something like the abbreviated
1577 Finish @code{:tab-order}.
1580 Make indentation work with glyphs and proportional fonts.
1583 Add commands to show overview of object and class hierarchies to the
1587 Find a way to disable mouse highlight for inactive widgets.
1590 Find a way to make glyphs look inactive.
1593 Add @code{property-list} widget.
1596 Add @code{association-list} widget.
1599 Add @code{key-binding} widget.
1602 Add @code{widget} widget for editing widget specifications.
1605 Find clean way to implement variable length list.
1606 See @code{TeX-printer-list} for an explanation.
1609 @kbd{C-h} in @code{widget-prompt-value} should give type specific help.
1615 @kbd{C-e e} in a fixed size field should go to the end of the text in
1616 the field, not the end of the field itself.
1619 Use and overlay instead of markers to delimit the widget. Create
1620 accessors for the end points.
1623 Clicking on documentation links should call @code{describe-function} or
1624 @code{widget-browse-other-window} and friends directly, instead of going
1625 through @code{apropos}. If more than one function is valid for the
1626 symbol, it should pop up a menu.