1 This is ../info/widget.info, produced by makeinfo version 4.0 from
4 INFO-DIR-SECTION XEmacs Editor
6 * Widgets: (widget). The Emacs Widget Library.
10 File: widget.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
12 The Emacs Widget Library
13 ************************
19 * Programming Example::
20 * Setting Up the Buffer::
24 * Defining New Widgets::
31 File: widget.info, Node: Introduction, Next: User Interface, Prev: Top, Up: Top
36 Most graphical user interface toolkits, such as Motif and XView,
37 provide 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 `widget' package simplifies
44 The basic widgets are:
47 Areas of text with an associated action. Intended for hypertext
48 links embedded in text.
51 Like link, but intended for stand-alone buttons.
54 An editable text field. It can be either variable or fixed length.
57 Allows the user to choose one of multiple options from a menu, each
58 option is itself a widget. Only the selected option will be
59 visible in the buffer.
62 Allows the user to choose one of multiple options by activating
63 radio buttons. The options are implemented as widgets. All
64 options will be visible in the buffer.
67 A simple constant widget intended to be used in the `menu-choice'
68 and `radio-button-choice' widgets.
71 An button item only intended for use in choices. When invoked,
72 the user will be asked to select another option from the choice
76 A simple `on'/`off' switch.
79 A checkbox (`[ ]'/`[X]').
82 Create an editable list. The user can insert or delete items in
83 the list. Each list item is itself a widget.
85 Now of what possible use can support for widgets be in a text editor?
86 I'm glad you asked. The answer is that widgets are useful for
87 implementing forms. A "form" in emacs is a buffer where the user is
88 supposed to fill out a number of fields, each of which has a specific
89 meaning. The user is not supposed to change or delete any of the text
90 between the fields. Examples of forms in Emacs are the `forms' package
91 (of course), the customize buffers, the mail and news compose modes,
92 and the HTML form support in the `w3' browser.
94 The advantages for a programmer of using the `widget' package to
97 1. More complex fields than just editable text are supported.
99 2. You can give the user immediate feedback if he enters invalid data
100 in a text field, and sometimes prevent entering invalid data.
102 3. You can have fixed sized fields, thus allowing multiple field to be
105 4. It is simple to query or set the value of a field.
107 5. Editing happens in buffer, not in the mini-buffer.
109 6. Packages using the library get a uniform look, making them easier
110 for the user to learn.
112 7. 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.
116 In order to minimize the code that is loaded by users who does not
117 create any widgets, the code has been split in two files:
120 This will declare the user variables, define the function
121 `widget-define', and autoload the function `widget-create'.
124 Everything else is here, there is no reason to load it explicitly,
125 as it will be autoloaded when needed.
128 File: widget.info, Node: User Interface, Next: Programming Example, Prev: Introduction, Up: Top
133 A form consist of read only text for documentation and some fields,
134 where each the fields contain two parts, as tag and a value. The tags
135 are used to identify the fields, so the documentation can refer to the
136 foo field, meaning the field tagged with `Foo'. Here is an example form:
138 Here is some documentation.
140 Name: My Name *Choose*: This option
145 See also _other work_ for more information.
147 Numbers: count to three below
165 [Apply Form] [Reset Form]
167 The top level widgets in is example are tagged `Name', `Choose',
168 `Address', `_other work_', `Numbers', `Select multiple', `Select one',
169 `[Apply Form]', and `[Reset Form]'. There are basically two thing the
170 user can do within a form, namely editing the editable text fields and
171 activating the buttons.
176 In the example, the value for the `Name' is most likely displayed in
177 an editable text field, and so are values for each of the members of
178 the `Numbers' list. All the normal Emacs editing operations are
179 available for editing these fields. The only restriction is that each
180 change you make must be contained within a single editable text field.
181 For example, capitalizing all text from the middle of one field to the
182 middle of another field is prohibited.
184 Editing text fields are created by the `editable-field' widget.
186 The editing text fields are highlighted with the `widget-field-face'
187 face, making them easy to find.
189 - Face: widget-field-face
190 Face used for other editing fields.
195 Some portions of the buffer have an associated "action", which can
196 be "invoked" by a standard key or mouse command. These portions are
197 called "buttons". The default commands for activating a button are:
200 - Command: widget-button-press POS &optional EVENT
201 Invoke the button at POS, defaulting to point. If point is
202 not located on a button, invoke the binding in
203 `widget-global-map' (by default the global map).
206 - Command: widget-button-click EVENT
207 Invoke the button at the location of the mouse pointer. If
208 the mouse pointer is located in an editable text field,
209 invoke the binding in `widget-global-map' (by default the
212 There are several different kind of buttons, all of which are
213 present in the example:
215 _The Option Field Tags._
216 When you invoke one of these buttons, you will be asked to choose
217 between a number of different options. This is how you edit an
218 option field. Option fields are created by the `menu-choice'
219 widget. In the example, `Choose' is an option field tag.
221 _The `[INS]' and `[DEL]' buttons._
222 Activating these will insert or delete elements from a editable
223 list. The list is created by the `editable-list' widget.
226 The `_other work_' is an example of an embedded button. Embedded
227 buttons are not associated with a fields, but can serve any
228 purpose, such as implementing hypertext references. They are
229 usually created by the `link' widget.
231 _The `[ ]' and `[X]' buttons._
232 Activating one of these will convert it to the other. This is
233 useful for implementing multiple-choice fields. You can create it
236 _The `( )' and `(*)' buttons._
237 Only one radio button in a `radio-button-choice' widget can be
238 selected at any time. When you invoke one of the unselected radio
239 buttons, it will be selected and the previous selected radio
240 button will become unselected.
242 _The `[Apply Form]' `[Reset Form]' buttons._
243 These are explicit buttons made with the `push-button' widget.
244 The main difference from the `link' widget is that the buttons are
245 will be displayed as GUI buttons when possible. enough.
247 To make them easier to locate, buttons are emphasized in the buffer.
249 - Face: widget-button-face
250 Face used for buttons.
252 - User Option: widget-mouse-face
253 Face used for buttons when the mouse pointer is above it.
258 You can use all the normal Emacs commands to move around in a form
259 buffer, plus you will have these additional commands:
262 - Command: widget-forward &optional count
263 Move point COUNT buttons or editing fields forward.
266 - Command: widget-backward &optional count
267 Move point COUNT buttons or editing fields backward.
270 File: widget.info, Node: Programming Example, Next: Setting Up the Buffer, Prev: User Interface, Up: Top
275 Here is the code to implement the user interface example (see *Note
283 (defvar widget-example-repeat)
285 (defun widget-example ()
286 "Create the widgets from the Widget manual."
288 (kill-buffer (get-buffer-create "*Widget Example*"))
289 (switch-to-buffer (get-buffer-create "*Widget Example*"))
290 (kill-all-local-variables)
291 (make-local-variable 'widget-example-repeat)
292 (widget-insert "Here is some documentation.\n\nName: ")
293 (widget-create 'editable-field
296 (widget-create 'menu-choice
299 :help-echo "Choose me, please!"
300 :notify (lambda (widget &rest ignore)
301 (message "%s is a good choice!"
302 (widget-value widget)))
303 '(item :tag "This option" :value "This")
304 '(choice-item "That option")
305 '(editable-field :menu-tag "No option" "Thus option"))
306 (widget-insert "Address: ")
307 (widget-create 'editable-field
308 "Some Place\nIn some City\nSome country.")
309 (widget-insert "\nSee also ")
311 :notify (lambda (&rest ignore)
312 (widget-value-set widget-example-repeat
316 (widget-insert " for more information.\n\nNumbers: count to three below\n")
317 (setq widget-example-repeat
318 (widget-create 'editable-list
319 :entry-format "%i %d %v"
320 :notify (lambda (widget &rest ignore)
321 (let ((old (widget-get widget
323 (new (length (widget-value widget))))
325 (widget-put widget ':example-length new)
326 (message "You can count to %d." new))))
327 :value '("One" "Eh, two?" "Five!")
328 '(editable-field :value "three")))
329 (widget-insert "\n\nSelect multiple:\n\n")
330 (widget-create 'checkbox t)
331 (widget-insert " This\n")
332 (widget-create 'checkbox nil)
333 (widget-insert " That\n")
334 (widget-create 'checkbox
335 :notify (lambda (&rest ignore) (message "Tickle"))
337 (widget-insert " Thus\n\nSelect one:\n\n")
338 (widget-create 'radio-button-choice
340 :notify (lambda (widget &rest ignore)
341 (message "You selected %s"
342 (widget-value widget)))
343 '(item "One") '(item "Another One.") '(item "A Final One."))
345 (widget-create 'push-button
346 :notify (lambda (&rest ignore)
347 (if (= (length (widget-value widget-example-repeat))
349 (message "Congratulation!")
350 (error "Three was the count!")))
353 (widget-create 'push-button
354 :notify (lambda (&rest ignore)
358 (use-local-map widget-keymap)
362 File: widget.info, Node: Setting Up the Buffer, Next: Basic Types, Prev: Programming Example, Up: Top
364 Setting Up the Buffer
365 =====================
367 Widgets are created with `widget-create', which returns a "widget"
368 object. This object can be queried and manipulated by other widget
369 functions, until it is deleted with `widget-delete'. After the widgets
370 have been created, `widget-setup' must be called to enable them.
372 - Function: widget-create type [ keyword argument ]...
373 Create and return a widget of type TYPE. The syntax for the TYPE
374 argument is described in *Note Basic Types::.
376 The keyword arguments can be used to overwrite the keyword
377 arguments that are part of TYPE.
379 - Function: widget-delete widget
380 Delete WIDGET and remove it from the buffer.
382 - Function: widget-setup
383 Setup a buffer to support widgets.
385 This should be called after creating all the widgets and before
386 allowing 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 `widget-insert'.
392 - Function: widget-insert
393 Insert the arguments, either strings or characters, at point. The
394 inserted text will be read only.
396 There is a standard widget keymap which you might find useful.
398 - Const: widget-keymap
399 A keymap with the global keymap as its parent.
400 <TAB> and `C-<TAB>' are bound to `widget-forward' and
401 `widget-backward', respectively. `<RET>' and `mouse-2' are bound
402 to `widget-button-press' and `widget-button-'.
404 - Variable: widget-global-map
405 Keymap used by `widget-button-press' and `widget-button-click'
406 when not on a button. By default this is `global-map'.
409 File: widget.info, Node: Basic Types, Next: Sexp Types, Prev: Setting Up the Buffer, Up: Top
414 The syntax of a type specification is given below:
416 NAME ::= (NAME [KEYWORD ARGUMENT]... ARGS)
419 where NAME is a widget name, KEYWORD is the name of a property,
420 ARGUMENT is the value of the property, and ARGS are interpreted in a
423 There following keyword arguments that apply to all widgets:
426 The initial value for widgets of this type.
429 This string will be inserted in the buffer when you create a
430 widget. The following `%' escapes are available:
434 The text inside will be marked as a button.
436 By default, the text will be shown in `widget-button-face',
437 and surrounded by brackets.
439 - User Option: widget-button-prefix
440 String to prefix buttons.
442 - User Option: widget-button-suffix
443 String to suffix buttons.
447 The text inside will be displayed in the face specified by
451 This will be replaced with the buffer representation of the
452 widget's value. What this is depends on the widget type.
455 Insert the string specified by `:doc' here.
458 Like `%d', with the following modifications: If the
459 documentation string is more than one line, it will add a
460 button which will toggle between showing only the first line,
461 and showing the full text. Furthermore, if there is no
462 `:doc' property in the widget, it will instead examine the
463 `:documentation-property' property. If it is a lambda
464 expression, it will be called with the widget's value as an
465 argument, and the result will be used as the documentation
469 Insert the string specified by `:tag' here, or the `princ'
470 representation of the value if there is no tag.
473 Insert a literal `%'.
476 Face used to highlight text inside %[ %] in the format.
480 Text around %[ %] in the format.
487 The string is inserted literally.
490 The value of the symbol is expanded according to this table.
493 The string inserted by the `%d' or `%h' escape in the format
497 The string inserted by the `%t' escape in the format string.
500 Name of image to use instead of the string specified by `:tag' on
501 Emacsen that supports it.
504 Message displayed whenever you move to the widget with either
505 `widget-forward' or `widget-backward'.
508 An integer indicating the absolute number of spaces to indent
509 children of this widget.
512 An integer indicating how many extra spaces to add to the widget's
513 grandchildren compared to this widget.
516 An integer indicating how many extra spaces to add to the widget's
517 children compared to this widget.
520 A function called each time the widget or a nested widget is
521 changed. The function is called with two or three arguments. The
522 first argument is the widget itself, the second argument is the
523 widget that was changed, and the third argument is the event
524 leading to the change, if any.
527 Tag used in the menu when the widget is used as an option in a
528 `menu-choice' widget.
531 Function used for finding the tag when the widget is used as an
532 option in a `menu-choice' widget. By default, the tag used will
533 be either the `:menu-tag' or `:tag' property if present, or the
534 `princ' representation of the `:value' property if not.
537 Should be a function called with two arguments, the widget and a
538 value, and returning non-nil if the widget can represent the
542 A function which takes a widget as an argument, and returns nil if
543 the widget's current value is valid for the widget. Otherwise it
544 should return the widget containing the invalid data, and set that
545 widget's `:error' property to a string explaining the error.
547 The following predefined function can be used:
549 - Function: widget-children-validate widget
550 All the `:children' of WIDGET must be valid.
553 Specify the order in which widgets are traversed with
554 `widget-forward' or `widget-backward'. This is only partially
557 a. Widgets with tabbing order `-1' are ignored.
559 b. (Unimplemented) When on a widget with tabbing order N, go to
560 the next widget in the buffer with tabbing order N+1 or `nil',
561 whichever comes first.
563 c. When on a widget with no tabbing order specified, go to the
564 next widget in the buffer with a positive tabbing order, or
568 The parent of a nested widget (e.g. a `menu-choice' item or an
569 element of a `editable-list' widget).
572 This keyword is only used for members of a `radio-button-choice' or
573 `checklist'. The value should be a list of extra keyword
574 arguments, which will be used when creating the `radio-button' or
575 `checkbox' associated with this item.
577 - User Option: widget-glyph-directory
578 Directory where glyphs are found. Widget will look here for a
579 file with the same name as specified for the image, with either a
580 `.xpm' (if supported) or `.xbm' extension.
582 - User Option: widget-glyph-enable
583 If non-nil, allow glyphs to appear on displays where they are
595 * radio-button-choice::
605 File: widget.info, Node: link, Next: url-link, Prev: Basic Types, Up: Basic Types
612 TYPE ::= (link [KEYWORD ARGUMENT]... [ VALUE ])
614 The VALUE, if present, is used to initialize the `:value' property.
615 The value should be a string, which will be inserted in the buffer.
617 By default the link will be shown in brackets.
619 - User Option: widget-link-prefix
620 String to prefix links.
622 - User Option: widget-link-suffix
623 String to suffix links.
626 File: widget.info, Node: url-link, Next: info-link, Prev: link, Up: Basic Types
628 The `url-link' Widget
629 ---------------------
633 TYPE ::= (url-link [KEYWORD ARGUMENT]... URL)
635 When this link is invoked, the WWW browser specified by
636 `browse-url-browser-function' will be called with URL.
639 File: widget.info, Node: info-link, Next: push-button, Prev: url-link, Up: Basic Types
641 The `info-link' Widget
642 ----------------------
646 TYPE ::= (info-link [KEYWORD ARGUMENT]... ADDRESS)
648 When this link is invoked, the built-in info browser is started on
652 File: widget.info, Node: push-button, Next: editable-field, Prev: info-link, Up: Basic Types
654 The `push-button' Widget
655 ------------------------
659 TYPE ::= (push-button [KEYWORD ARGUMENT]... [ VALUE ])
661 The VALUE, if present, is used to initialize the `:value' property.
662 The value should be a string, which will be inserted in the buffer.
664 By default the tag will be shown in brackets.
666 - User Option: widget-push-button-prefix
667 String to prefix push buttons.
669 - User Option: widget-push-button-suffix
670 String to suffix push buttons.
673 File: widget.info, Node: editable-field, Next: text, Prev: push-button, Up: Basic Types
675 The `editable-field' Widget
676 ---------------------------
680 TYPE ::= (editable-field [KEYWORD ARGUMENT]... [ VALUE ])
682 The VALUE, if present, is used to initialize the `:value' property.
683 The value should be a string, which will be inserted in field. This
684 widget will match all string values.
686 The following extra properties are recognized.
689 The minimum width of the editable field.
690 By default the field will reach to the end of the line. If the
691 content is too large, the displayed representation will expand to
692 contain it. The content is not truncated to size.
695 Face used for highlighting the editable field. Default is
699 Character used to display the value. You can set this to e.g. `?*'
700 if the field contains a password or other secret information. By
701 default, the value is not secret.
704 By default the `:validate' function will match the content of the
705 field with the value of this attribute. The default value is `""'
706 which matches everything.
709 Keymap used in the editable field. The default value is
710 `widget-field-keymap', which allows you to use all the normal
711 editing commands, even if the buffer's major mode suppress some of
712 them. Pressing return invokes the function specified by `:action'.
715 File: widget.info, Node: text, Next: menu-choice, Prev: editable-field, Up: Basic Types
720 This is just like `editable-field', but intended for multiline text
721 fields. The default `:keymap' is `widget-text-keymap', which does not
722 rebind the return key.
725 File: widget.info, Node: menu-choice, Next: radio-button-choice, Prev: text, Up: Basic Types
727 The `menu-choice' Widget
728 ------------------------
732 TYPE ::= (menu-choice [KEYWORD ARGUMENT]... TYPE ... )
734 The TYPE argument represents each possible choice. The widget's
735 value will be that of the chosen TYPE argument. This widget will match
736 any value matching at least one of the specified TYPE arguments.
739 Widget type used as a fallback when the value does not match any
740 of the specified TYPE arguments.
743 Set this to nil if you don't want to ignore case when prompting
744 for a choice through the minibuffer.
747 A list whose car is the widget representing the currently chosen
751 The current chosen type
757 File: widget.info, Node: radio-button-choice, Next: item, Prev: menu-choice, Up: Basic Types
759 The `radio-button-choice' Widget
760 --------------------------------
764 TYPE ::= (radio-button-choice [KEYWORD ARGUMENT]... TYPE ... )
766 The TYPE argument represents each possible choice. The widget's
767 value will be that of the chosen TYPE argument. This widget will match
768 any value matching at least one of the specified TYPE arguments.
770 The following extra properties are recognized.
773 This string will be inserted for each entry in the list. The
774 following `%' escapes are available:
776 Replaced with the buffer representation of the TYPE widget.
779 Replace with the radio button.
782 Insert a literal `%'.
785 A list of keywords to pass to the radio buttons. Useful for
786 setting e.g. the `:help-echo' for each button.
789 The widgets representing the radio buttons.
792 The widgets representing each type.
795 The current chosen type
800 You can add extra radio button items to a `radio-button-choice'
801 widget after it has been created with the function
802 `widget-radio-add-item'.
804 - Function: widget-radio-add-item widget type
805 Add to `radio-button-choice' widget WIDGET a new radio button item
808 Please note that such items added after the `radio-button-choice'
809 widget has been created will *not* be properly destructed when you call
813 File: widget.info, Node: item, Next: choice-item, Prev: radio-button-choice, Up: Basic Types
820 ITEM ::= (item [KEYWORD ARGUMENT]... VALUE)
822 The VALUE, if present, is used to initialize the `:value' property.
823 The value should be a string, which will be inserted in the buffer.
824 This widget will only match the specified value.
827 File: widget.info, Node: choice-item, Next: toggle, Prev: item, Up: Basic Types
829 The `choice-item' Widget
830 ------------------------
834 ITEM ::= (choice-item [KEYWORD ARGUMENT]... VALUE)
836 The VALUE, if present, is used to initialize the `:value' property.
837 The value should be a string, which will be inserted in the buffer as a
838 button. Activating the button of a `choice-item' is equivalent to
839 activating the parent widget. This widget will only match the
843 File: widget.info, Node: toggle, Next: checkbox, Prev: choice-item, Up: Basic Types
850 TYPE ::= (toggle [KEYWORD ARGUMENT]...)
852 The widget has two possible states, `on' and `off', which correspond
853 to a `t' or `nil' value respectively.
855 The following extra properties are recognized.
858 String representing the `on' state. By default the string `on'.
861 String representing the `off' state. By default the string `off'.
864 Name of a glyph to be used instead of the `:on' text string, on
865 emacsen that supports it.
868 Name of a glyph to be used instead of the `:off' text string, on
869 emacsen that supports it.
872 File: widget.info, Node: checkbox, Next: checklist, Prev: toggle, Up: Basic Types
874 The `checkbox' Widget
875 ---------------------
877 The widget has two possible states, `selected' and `unselected',
878 which corresponds to a `t' or `nil' value.
882 TYPE ::= (checkbox [KEYWORD ARGUMENT]...)
885 File: widget.info, Node: checklist, Next: editable-list, Prev: checkbox, Up: Basic Types
887 The `checklist' Widget
888 ----------------------
892 TYPE ::= (checklist [KEYWORD ARGUMENT]... TYPE ... )
894 The TYPE arguments represents each checklist item. The widget's
895 value will be a list containing the values of all ticked TYPE
896 arguments. The checklist widget will match a list whose elements all
897 match at least one of the specified TYPE arguments.
899 The following extra properties are recognized.
902 This string will be inserted for each entry in the list. The
903 following `%' escapes are available:
905 Replaced with the buffer representation of the TYPE widget.
908 Replace with the checkbox.
911 Insert a literal `%'.
914 Usually a checklist will only match if the items are in the exact
915 sequence given in the specification. By setting `:greedy' to
916 non-nil, it will allow the items to appear in any sequence.
917 However, if you extract the values they will be in the sequence
918 given in the checklist. I.e. the original sequence is forgotten.
921 A list of keywords to pass to the checkboxes. Useful for setting
922 e.g. the `:help-echo' for each checkbox.
925 The widgets representing the checkboxes.
928 The widgets representing each type.
934 File: widget.info, Node: editable-list, Next: group, Prev: checklist, Up: Basic Types
936 The `editable-list' Widget
937 --------------------------
941 TYPE ::= (editable-list [KEYWORD ARGUMENT]... TYPE)
943 The value is a list, where each member represents one widget of type
946 The following extra properties are recognized.
949 This string will be inserted for each entry in the list. The
950 following `%' escapes are available:
952 This will be replaced with the buffer representation of the
956 Insert the [INS] button.
959 Insert the [DEL] button.
962 Insert a literal `%'.
964 `:insert-button-args'
965 A list of keyword arguments to pass to the insert buttons.
967 `:delete-button-args'
968 A list of keyword arguments to pass to the delete buttons.
970 `:append-button-args'
971 A list of keyword arguments to pass to the trailing insert button.
974 The widgets representing the insert and delete buttons.
977 The widgets representing the elements of the list.
980 List whose car is the type of the list elements.
983 File: widget.info, Node: group, Prev: editable-list, Up: Basic Types
988 This widget simply group other widget together.
992 TYPE ::= (group [KEYWORD ARGUMENT]... TYPE...)
994 The value is a list, with one member for each TYPE.
997 File: widget.info, Node: Sexp Types, Next: Widget Properties, Prev: Basic Types, Up: Top
1002 A number of widgets for editing s-expressions (lisp types) are also
1003 available. These basically fall in the following categories.
1013 File: widget.info, Node: constants, Next: generic, Prev: Sexp Types, Up: Sexp Types
1015 The Constant Widgets.
1016 ---------------------
1018 The `const' widget can contain any lisp expression, but the user is
1019 prohibited from editing edit it, which is mainly useful as a component
1020 of one of the composite widgets.
1022 The syntax for the `const' widget is
1024 TYPE ::= (const [KEYWORD ARGUMENT]... [ VALUE ])
1026 The VALUE, if present, is used to initialize the `:value' property
1027 and can be any s-expression.
1030 This will display any valid s-expression in an immutable part of
1033 There are two variations of the `const' widget, namely
1034 `variable-item' and `function-item'. These should contain a symbol
1035 with a variable or function binding. The major difference from the
1036 `const' widget is that they will allow the user to see the variable or
1037 function documentation for the symbol.
1039 - Widget: variable-item
1040 An immutable symbol that is bound as a variable.
1042 - Widget: function-item
1043 An immutable symbol that is bound as a function.
1046 File: widget.info, Node: generic, Next: atoms, Prev: constants, Up: Sexp Types
1048 Generic Sexp Widget.
1049 --------------------
1051 The `sexp' widget can contain any lisp expression, and allows the
1052 user to edit it inline in the buffer.
1054 The syntax for the `sexp' widget is
1056 TYPE ::= (sexp [KEYWORD ARGUMENT]... [ VALUE ])
1059 This will allow you to edit any valid s-expression in an editable
1062 The `sexp' widget takes the same keyword arguments as the
1063 `editable-field' widget.
1066 File: widget.info, Node: atoms, Next: composite, Prev: generic, Up: Sexp Types
1068 Atomic Sexp Widgets.
1069 --------------------
1071 The atoms are s-expressions that does not consist of other
1072 s-expressions. A string is an atom, while a list is a composite type.
1073 You can edit the value of an atom with the following widgets.
1075 The syntax for all the atoms are
1077 TYPE ::= (NAME [KEYWORD ARGUMENT]... [ VALUE ])
1079 The VALUE, if present, is used to initialize the `:value' property
1080 and must be an expression of the same type as the widget. I.e. the
1081 string widget can only be initialized with a string.
1083 All the atom widgets take the same keyword arguments as the
1084 `editable-field' widget.
1087 Allows you to edit a string in an editable field.
1090 Allows you to edit a regular expression in an editable field.
1093 Allows you to enter a character in an editable field.
1096 Allows you to edit a file name in an editable field. If you invoke
1097 the tag button, you can edit the file name in the mini-buffer with
1102 If this is set to non-nil, only existing file names will be
1103 allowed in the minibuffer.
1106 Allows you to edit a directory name in an editable field. Similar
1107 to the `file' widget.
1110 Allows you to edit a lisp symbol in an editable field.
1113 Allows you to edit a lambda expression, or a function name with
1117 Allows you to edit a variable name, with completion.
1120 Allows you to edit an integer in an editable field.
1123 Allows you to edit a number in an editable field.
1126 Allows you to edit a boolean. In lisp this means a variable which
1127 is either nil meaning false, or non-nil meaning true.
1130 File: widget.info, Node: composite, Prev: atoms, Up: Sexp Types
1132 Composite Sexp Widgets.
1133 -----------------------
1135 The syntax for the composite are
1137 TYPE ::= (NAME [KEYWORD ARGUMENT]... COMPONENT...)
1139 Where each COMPONENT must be a widget type. Each component widget
1140 will be displayed in the buffer, and be editable to the user.
1143 The value of a `cons' widget is a cons-cell where the car is the
1144 value of the first component and the cdr is the value of the second
1145 component. There must be exactly two components.
1148 The value of a `list' widget is a list containing the value of
1149 each of its component.
1152 The value of a `vector' widget is a vector containing the value of
1153 each of its component.
1155 The above suffice for specifying fixed size lists and vectors. To
1156 get variable length lists and vectors, you can use a `choice', `set' or
1157 `repeat' widgets together with the `:inline' keywords. If any
1158 component of a composite widget has the `:inline' keyword set, its
1159 value must be a list which will then be spliced into the composite.
1160 For example, to specify a list whose first element must be a file name,
1161 and whose remaining arguments should either by the symbol `t' or two
1162 files, you can use the following widget specification:
1167 :value ("foo" "bar")
1170 The value of a widget of this type will either have the form `(file
1171 t)' or `(file string string)'.
1173 This concept of inline is probably hard to understand. It was
1174 certainly hard to implement so instead of confusing you more by trying
1175 to explain it here, I'll just suggest you meditate over it for a while.
1178 Allows you to edit a sexp which may have one of a fixed set of
1179 types. It is currently implemented with the `choice-menu' basic
1180 widget, and has a similar syntax.
1183 Allows you to specify a type which must be a list whose elements
1184 all belong to given set. The elements of the list is not
1185 significant. This is implemented on top of the `checklist' basic
1186 widget, and has a similar syntax.
1189 Allows you to specify a variable length list whose members are all
1190 of the same type. Implemented on top of the `editable-list' basic
1191 widget, and has a similar syntax.
1194 File: widget.info, Node: Widget Properties, Next: Defining New Widgets, Prev: Sexp Types, Up: Top
1199 You can examine or set the value of a widget by using the widget
1200 object that was returned by `widget-create'.
1202 - Function: widget-value widget
1203 Return the current value contained in WIDGET. It is an error to
1204 call this function on an uninitialized widget.
1206 - Function: widget-value-set widget value
1207 Set the value contained in WIDGET to VALUE. It is an error to
1208 call this function with an invalid VALUE.
1210 *Important:* You _must_ call `widget-setup' after modifying the
1211 value of a widget before the user is allowed to edit the widget again.
1212 It is enough to call `widget-setup' once if you modify multiple
1213 widgets. This is currently only necessary if the widget contains an
1214 editing field, but may be necessary for other widgets in the future.
1216 If your application needs to associate some information with the
1217 widget objects, for example a reference to the item being edited, it
1218 can be done with `widget-put' and `widget-get'. The property names
1219 must begin with a `:'.
1221 - Function: widget-put widget property value
1222 In WIDGET set PROPERTY to VALUE. PROPERTY should be a symbol,
1223 while VALUE can be anything.
1225 - Function: widget-get widget property
1226 In WIDGET return the value for PROPERTY. PROPERTY should be a
1227 symbol, the value is what was last set by `widget-put' for
1230 - Function: widget-member widget property
1231 Non-nil if WIDGET has a value (even nil) for property PROPERTY.
1233 Occasionally it can be useful to know which kind of widget you have,
1234 i.e. the name of the widget type you gave when the widget was created.
1236 - Function: widget-type widget
1237 Return the name of WIDGET, a symbol.
1239 Widgets can be in two states: active, which means they are
1240 modifiable by the user, or inactive, which means they cannot be
1241 modified by the user. You can query or set the state with the
1244 ;; Examine if WIDGET is active or not.
1245 (if (widget-apply WIDGET :active)
1246 (message "Widget is active.")
1247 (message "Widget is inactive.")
1249 ;; Make WIDGET inactive.
1250 (widget-apply WIDGET :deactivate)
1252 ;; Make WIDGET active.
1253 (widget-apply WIDGET :activate)
1255 A widget is inactive if itself or any of its ancestors (found by
1256 following the `:parent' link) have been deactivated. To make sure a
1257 widget is really active, you must therefore activate both itself and
1261 (widget-apply widget :activate)
1262 (setq widget (widget-get widget :parent)))
1264 You can check if a widget has been made inactive by examining the
1265 value of the `:inactive' keyword. If this is non-nil, the widget itself
1266 has been deactivated. This is different from using the `:active'
1267 keyword, in that the latter tells you if the widget *or* any of its
1268 ancestors have been deactivated. Do not attempt to set the `:inactive'
1269 keyword directly. Use the `:activate' `:deactivate' keywords instead.
1272 File: widget.info, Node: Defining New Widgets, Next: Widget Browser, Prev: Widget Properties, Up: Top
1274 Defining New Widgets
1275 ====================
1277 You can define specialized widgets with `define-widget'. It allows
1278 you to create a shorthand for more complex widgets. This includes
1279 specifying component widgets and new default values for the keyword
1282 - Function: widget-define name class doc &rest args
1283 Define a new widget type named NAME from `class'.
1285 NAME and class should both be symbols, `class' should be one of
1286 the existing widget types.
1288 The third argument DOC is a documentation string for the widget.
1290 After the new widget has been defined the following two calls will
1291 create identical widgets:
1293 * (widget-create NAME)
1295 * (apply widget-create CLASS ARGS)
1298 Using `widget-define' just stores the definition of the widget type
1299 in the `widget-type' property of NAME, which is what `widget-create'
1302 If you just want to specify defaults for keywords with no complex
1303 conversions, you can use `identity' as your conversion function.
1305 The following additional keyword arguments are useful when defining
1308 Function to convert a widget type before creating a widget of that
1309 type. It takes a widget type as an argument, and returns the
1310 converted widget type. When a widget is created, this function is
1311 called for the widget type and all the widget's parent types, most
1314 The following predefined functions can be used here:
1316 - Function: widget-types-convert-widget widget
1317 Convert `:args' as widget types in WIDGET.
1319 - Function: widget-value-convert-widget widget
1320 Initialize `:value' from `:args' in WIDGET.
1322 `:value-to-internal'
1323 Function to convert the value to the internal format. The function
1324 takes two arguments, a widget and an external value. It returns
1325 the internal value. The function is called on the present `:value'
1326 when the widget is created, and on any value set later with
1329 `:value-to-external'
1330 Function to convert the value to the external format. The function
1331 takes two arguments, a widget and an internal value, and returns
1332 the internal value. The function is called on the present `:value'
1333 when the widget is created, and on any value set later with
1337 Function to create a widget from scratch. The function takes one
1338 argument, a widget type, and creates a widget of that type,
1339 inserts it in the buffer, and returns a widget object.
1342 Function to delete a widget. The function takes one argument, a
1343 widget, and should remove all traces of the widget from the buffer.
1346 Function to expand the `%v' escape in the format string. It will
1347 be called with the widget as its argument and should insert a
1348 representation of the widget's value in the buffer.
1351 Should remove the representation of the widget's value from the
1352 buffer. It will be called with the widget as its argument. It
1353 doesn't have to remove the text, but it should release markers and
1354 delete nested widgets if such have been used.
1356 The following predefined function can be used here:
1358 - Function: widget-children-value-delete widget
1359 Delete all `:children' and `:buttons' in WIDGET.
1362 Function to extract the value of a widget, as it is displayed in
1365 The following predefined function can be used here:
1367 - Function: widget-value-value-get widget
1368 Return the `:value' property of WIDGET.
1371 Function to handle unknown `%' escapes in the format string. It
1372 will be called with the widget and the escape character as
1373 arguments. You can set this to allow your widget to handle
1374 non-standard escapes.
1376 You should end up calling `widget-default-format-handler' to handle
1377 unknown escape sequences. It will handle the `%h' and any future
1378 escape sequences as well as give an error for unknown escapes.
1381 Function to handle user initiated events. By default, `:notify'
1384 The following predefined function can be used here:
1386 - Function: widget-parent-action widget &optional event
1387 Tell `:parent' of WIDGET to handle the `:action'.
1388 Optional EVENT is the event that triggered the action.
1391 Function to prompt for a value in the minibuffer. The function
1392 should take four arguments, WIDGET, PROMPT, VALUE, and UNBOUND and
1393 should return a value for widget entered by the user. PROMPT is
1394 the prompt to use. VALUE is the default value to use, unless
1395 UNBOUND is non-nil. In this case there is no default value. The
1396 function should read the value using the method most natural for
1397 this widget and does not have to check whether it matches.
1399 If you want to define a new widget from scratch, use the `default'
1403 Widget used as a base for other widgets.
1405 It provides most of the functionality that is referred to as "by
1406 default" in this text.
1409 File: widget.info, Node: Widget Browser, Next: Widget Minor Mode, Prev: Defining New Widgets, Up: Top
1414 There is a separate package to browse widgets. This is intended to
1415 help programmers who want to examine the content of a widget. The
1416 browser shows the value of each keyword, but uses links for certain
1417 keywords such as `:parent', which avoids printing cyclic structures.
1419 - Command: widget-browse WIDGET
1420 Create a widget browser for WIDGET. When called interactively,
1423 - Command: widget-browse-other-window WIDGET
1424 Create a widget browser for WIDGET and show it in another window.
1425 When called interactively, prompt for WIDGET.
1427 - Command: widget-browse-at POS
1428 Create a widget browser for the widget at POS. When called
1429 interactively, use the position of point.
1432 File: widget.info, Node: Widget Minor Mode, Next: Utilities, Prev: Widget Browser, Up: Top
1437 There is a minor mode for manipulating widgets in major modes that
1438 doesn't provide any support for widgets themselves. This is mostly
1439 intended to be useful for programmers doing experiments.
1441 - Command: widget-minor-mode
1442 Toggle minor mode for traversing widgets. With arg, turn widget
1443 mode on if and only if arg is positive.
1445 - Variable: widget-minor-mode-keymap
1446 Keymap used in `widget-minor-mode'.
1449 File: widget.info, Node: Utilities, Next: Widget Wishlist, Prev: Widget Minor Mode, Up: Top
1454 - Function: widget-prompt-value widget prompt [ value unbound ]
1455 Prompt for a value matching WIDGET, using PROMPT.
1456 The current value is assumed to be VALUE, unless UNBOUND is
1459 - Function: widget-get-sibling widget
1460 Get the item WIDGET is assumed to toggle.
1461 This is only meaningful for radio buttons or checkboxes in a list.
1464 File: widget.info, Node: Widget Wishlist, Prev: Utilities, Up: Top
1469 * It should be possible to add or remove items from a list with `C-k'
1470 and `C-o' (suggested by RMS).
1472 * The `[INS]' and `[DEL]' buttons should be replaced by a single
1473 dash (`-'). The dash should be a button that, when invoked, ask
1474 whether you want to add or delete an item (RMS wanted to git rid of
1475 the ugly buttons, the dash is my idea).
1477 * The `menu-choice' tag should be prettier, something like the
1478 abbreviated menus in Open Look.
1480 * Finish `:tab-order'.
1482 * Make indentation work with glyphs and proportional fonts.
1484 * Add commands to show overview of object and class hierarchies to
1487 * Find a way to disable mouse highlight for inactive widgets.
1489 * Find a way to make glyphs look inactive.
1491 * Add `property-list' widget.
1493 * Add `association-list' widget.
1495 * Add `key-binding' widget.
1497 * Add `widget' widget for editing widget specifications.
1499 * Find clean way to implement variable length list. See
1500 `TeX-printer-list' for an explanation.
1502 * `C-h' in `widget-prompt-value' should give type specific help.
1506 * `C-e e' in a fixed size field should go to the end of the text in
1507 the field, not the end of the field itself.
1509 * Use and overlay instead of markers to delimit the widget. Create
1510 accessors for the end points.
1512 * Clicking on documentation links should call `describe-function' or
1513 `widget-browse-other-window' and friends directly, instead of going
1514 through `apropos'. If more than one function is valid for the
1515 symbol, it should pop up a menu.
1522 Node: Introduction
\7f591
1523 Node: User Interface
\7f4075
1524 Node: Programming Example
\7f8970
1525 Node: Setting Up the Buffer
\7f13120
1526 Node: Basic Types
\7f14837
1528 Node: url-link
\7f21409
1529 Node: info-link
\7f21721
1530 Node: push-button
\7f22012
1531 Node: editable-field
\7f22585
1533 Node: menu-choice
\7f24366
1534 Node: radio-button-choice
\7f25219
1536 Node: choice-item
\7f27174
1537 Node: toggle
\7f27672
1538 Node: checkbox
\7f28409
1539 Node: checklist
\7f28715
1540 Node: editable-list
\7f30159
1542 Node: Sexp Types
\7f31628
1543 Node: constants
\7f31941
1544 Node: generic
\7f33020
1546 Node: composite
\7f35500
1547 Node: Widget Properties
\7f37970
1548 Node: Defining New Widgets
\7f41035
1549 Node: Widget Browser
\7f46335
1550 Node: Widget Minor Mode
\7f47193
1551 Node: Utilities
\7f47750
1552 Node: Widget Wishlist
\7f48231