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 field 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' escape in the format string.
496 The string inserted by the `%t' escape in the format string.
499 Name of image to use instead of the string specified by `:tag' on
500 Emacsen that supports it.
503 Message displayed whenever you move to the widget with either
504 `widget-forward' or `widget-backward'.
507 An integer indicating the absolute number of spaces to indent
508 children of this widget.
511 An integer indicating how many extra spaces to add to the widget's
512 grandchildren compared to this widget.
515 An integer indicating how many extra spaces to add to the widget's
516 children compared to this widget.
519 A function called each time the widget or a nested widget is
520 changed. The function is called with two or three arguments. The
521 first argument is the widget itself, the second argument is the
522 widget that was changed, and the third argument is the event
523 leading to the change, if any.
526 Tag used in the menu when the widget is used as an option in a
527 `menu-choice' widget.
530 Function used for finding the tag when the widget is used as an
531 option in a `menu-choice' widget. By default, the tag used will
532 be either the `:menu-tag' or `:tag' property if present, or the
533 `princ' representation of the `:value' property if not.
536 Should be a function called with two arguments, the widget and a
537 value, and returning non-nil if the widget can represent the
541 A function which takes a widget as an argument, and return nil if
542 the widget's current value is valid for the widget. Otherwise it
543 should return the widget containing the invalid data, and set that
544 widget's `:error' property to a string explaining the error.
546 The following predefined function can be used:
548 - Function: widget-children-validate widget
549 All the `:children' of WIDGET must be valid.
552 Specify the order in which widgets are traversed with
553 `widget-forward' or `widget-backward'. This is only partially
556 a. Widgets with tabbing order `-1' are ignored.
558 b. (Unimplemented) When on a widget with tabbing order N, go to
559 the next widget in the buffer with tabbing order N+1 or `nil',
560 whichever comes first.
562 c. When on a widget with no tabbing order specified, go to the
563 next widget in the buffer with a positive tabbing order, or
567 The parent of a nested widget (e.g. a `menu-choice' item or an
568 element of a `editable-list' widget).
571 This keyword is only used for members of a `radio-button-choice' or
572 `checklist'. The value should be a list of extra keyword
573 arguments, which will be used when creating the `radio-button' or
574 `checkbox' associated with this item.
576 - User Option: widget-glyph-directory
577 Directory where glyphs are found. Widget will look here for a
578 file with the same name as specified for the image, with either a
579 `.xpm' (if supported) or `.xbm' extension.
581 - User Option: widget-glyph-enable
582 If non-nil, allow glyphs to appear on displays where they are
594 * radio-button-choice::
604 File: widget.info, Node: link, Next: url-link, Prev: Basic Types, Up: Basic Types
611 TYPE ::= (link [KEYWORD ARGUMENT]... [ VALUE ])
613 The VALUE, if present, is used to initialize the `:value' property.
614 The value should be a string, which will be inserted in the buffer.
616 By default the link will be shown in brackets.
618 - User Option: widget-link-prefix
619 String to prefix links.
621 - User Option: widget-link-suffix
622 String to suffix links.
625 File: widget.info, Node: url-link, Next: info-link, Prev: link, Up: Basic Types
627 The `url-link' Widget
628 ---------------------
632 TYPE ::= (url-link [KEYWORD ARGUMENT]... URL)
634 When this link is invoked, the WWW browser specified by
635 `browse-url-browser-function' will be called with URL.
638 File: widget.info, Node: info-link, Next: push-button, Prev: url-link, Up: Basic Types
640 The `info-link' Widget
641 ----------------------
645 TYPE ::= (info-link [KEYWORD ARGUMENT]... ADDRESS)
647 When this link is invoked, the built-in info browser is started on
651 File: widget.info, Node: push-button, Next: editable-field, Prev: info-link, Up: Basic Types
653 The `push-button' Widget
654 ------------------------
658 TYPE ::= (push-button [KEYWORD ARGUMENT]... [ VALUE ])
660 The VALUE, if present, is used to initialize the `:value' property.
661 The value should be a string, which will be inserted in the buffer.
663 By default the tag will be shown in brackets.
665 - User Option: widget-push-button-prefix
666 String to prefix push buttons.
668 - User Option: widget-push-button-suffix
669 String to suffix push buttons.
672 File: widget.info, Node: editable-field, Next: text, Prev: push-button, Up: Basic Types
674 The `editable-field' Widget
675 ---------------------------
679 TYPE ::= (editable-field [KEYWORD ARGUMENT]... [ VALUE ])
681 The VALUE, if present, is used to initialize the `:value' property.
682 The value should be a string, which will be inserted in field. This
683 widget will match all string values.
685 The following extra properties are recognized.
688 The width of the editable field.
689 By default the field will reach to the end of the line.
692 Face used for highlighting the editable field. Default is
696 Character used to display the value. You can set this to e.g. `?*'
697 if the field contains a password or other secret information. By
698 default, the value is not secret.
701 By default the `:validate' function will match the content of the
702 field with the value of this attribute. The default value is `""'
703 which matches everything.
706 Keymap used in the editable field. The default value is
707 `widget-field-keymap', which allows you to use all the normal
708 editing commands, even if the buffers major mode suppress some of
709 them. Pressing return invokes the function specified by `:action'.
712 File: widget.info, Node: text, Next: menu-choice, Prev: editable-field, Up: Basic Types
717 This is just like `editable-field', but intended for multiline text
718 fields. The default `:keymap' is `widget-text-keymap', which does not
719 rebind the return key.
722 File: widget.info, Node: menu-choice, Next: radio-button-choice, Prev: text, Up: Basic Types
724 The `menu-choice' Widget
725 ------------------------
729 TYPE ::= (menu-choice [KEYWORD ARGUMENT]... TYPE ... )
731 The TYPE argument represents each possible choice. The widget's
732 value will be that of the chosen TYPE argument. This widget will match
733 any value matching at least one of the specified TYPE arguments.
736 Widget type used as a fallback when the value does not match any
737 of the specified TYPE arguments.
740 Set this to nil if you don't want to ignore case when prompting
741 for a choice through the minibuffer.
744 A list whose car is the widget representing the currently chosen
748 The current chosen type
754 File: widget.info, Node: radio-button-choice, Next: item, Prev: menu-choice, Up: Basic Types
756 The `radio-button-choice' Widget
757 --------------------------------
761 TYPE ::= (radio-button-choice [KEYWORD ARGUMENT]... TYPE ... )
763 The TYPE argument represents each possible choice. The widget's
764 value will be that of the chosen TYPE argument. This widget will match
765 any value matching at least one of the specified TYPE arguments.
767 The following extra properties are recognized.
770 This string will be inserted for each entry in the list. The
771 following `%' escapes are available:
773 Replaced with the buffer representation of the TYPE widget.
776 Replace with the radio button.
779 Insert a literal `%'.
782 A list of keywords to pass to the radio buttons. Useful for
783 setting e.g. the `:help-echo' for each button.
786 The widgets representing the radio buttons.
789 The widgets representing each type.
792 The current chosen type
797 You can add extra radio button items to a `radio-button-choice'
798 widget after it has been created with the function
799 `widget-radio-add-item'.
801 - Function: widget-radio-add-item widget type
802 Add to `radio-button-choice' widget WIDGET a new radio button item
805 Please note that such items added after the `radio-button-choice'
806 widget has been created will *not* be properly destructed when you call
810 File: widget.info, Node: item, Next: choice-item, Prev: radio-button-choice, Up: Basic Types
817 ITEM ::= (item [KEYWORD ARGUMENT]... VALUE)
819 The VALUE, if present, is used to initialize the `:value' property.
820 The value should be a string, which will be inserted in the buffer.
821 This widget will only match the specified value.
824 File: widget.info, Node: choice-item, Next: toggle, Prev: item, Up: Basic Types
826 The `choice-item' Widget
827 ------------------------
831 ITEM ::= (choice-item [KEYWORD ARGUMENT]... VALUE)
833 The VALUE, if present, is used to initialize the `:value' property.
834 The value should be a string, which will be inserted in the buffer as a
835 button. Activating the button of a `choice-item' is equivalent to
836 activating the parent widget. This widget will only match the
840 File: widget.info, Node: toggle, Next: checkbox, Prev: choice-item, Up: Basic Types
847 TYPE ::= (toggle [KEYWORD ARGUMENT]...)
849 The widget has two possible states, `on' and `off', which correspond
850 to a `t' or `nil' value respectively.
852 The following extra properties are recognized.
855 String representing the `on' state. By default the string `on'.
858 String representing the `off' state. By default the string `off'.
861 Name of a glyph to be used instead of the `:on' text string, on
862 emacsen that supports it.
865 Name of a glyph to be used instead of the `:off' text string, on
866 emacsen that supports it.
869 File: widget.info, Node: checkbox, Next: checklist, Prev: toggle, Up: Basic Types
871 The `checkbox' Widget
872 ---------------------
874 The widget has two possible states, `selected' and `unselected',
875 which corresponds to a `t' or `nil' value.
879 TYPE ::= (checkbox [KEYWORD ARGUMENT]...)
882 File: widget.info, Node: checklist, Next: editable-list, Prev: checkbox, Up: Basic Types
884 The `checklist' Widget
885 ----------------------
889 TYPE ::= (checklist [KEYWORD ARGUMENT]... TYPE ... )
891 The TYPE arguments represents each checklist item. The widget's
892 value will be a list containing the values of all ticked TYPE
893 arguments. The checklist widget will match a list whose elements all
894 match at least one of the specified TYPE arguments.
896 The following extra properties are recognized.
899 This string will be inserted for each entry in the list. The
900 following `%' escapes are available:
902 Replaced with the buffer representation of the TYPE widget.
905 Replace with the checkbox.
908 Insert a literal `%'.
911 Usually a checklist will only match if the items are in the exact
912 sequence given in the specification. By setting `:greedy' to
913 non-nil, it will allow the items to appear in any sequence.
914 However, if you extract the values they will be in the sequence
915 given in the checklist. I.e. the original sequence is forgotten.
918 A list of keywords to pass to the checkboxes. Useful for setting
919 e.g. the `:help-echo' for each checkbox.
922 The widgets representing the checkboxes.
925 The widgets representing each type.
931 File: widget.info, Node: editable-list, Next: group, Prev: checklist, Up: Basic Types
933 The `editable-list' Widget
934 --------------------------
938 TYPE ::= (editable-list [KEYWORD ARGUMENT]... TYPE)
940 The value is a list, where each member represents one widget of type
943 The following extra properties are recognized.
946 This string will be inserted for each entry in the list. The
947 following `%' escapes are available:
949 This will be replaced with the buffer representation of the
953 Insert the [INS] button.
956 Insert the [DEL] button.
959 Insert a literal `%'.
961 `:insert-button-args'
962 A list of keyword arguments to pass to the insert buttons.
964 `:delete-button-args'
965 A list of keyword arguments to pass to the delete buttons.
967 `:append-button-args'
968 A list of keyword arguments to pass to the trailing insert button.
971 The widgets representing the insert and delete buttons.
974 The widgets representing the elements of the list.
977 List whose car is the type of the list elements.
980 File: widget.info, Node: group, Prev: editable-list, Up: Basic Types
985 This widget simply group other widget together.
989 TYPE ::= (group [KEYWORD ARGUMENT]... TYPE...)
991 The value is a list, with one member for each TYPE.
994 File: widget.info, Node: Sexp Types, Next: Widget Properties, Prev: Basic Types, Up: Top
999 A number of widgets for editing s-expressions (lisp types) are also
1000 available. These basically fall in the following categories.
1010 File: widget.info, Node: constants, Next: generic, Prev: Sexp Types, Up: Sexp Types
1012 The Constant Widgets.
1013 ---------------------
1015 The `const' widget can contain any lisp expression, but the user is
1016 prohibited from editing edit it, which is mainly useful as a component
1017 of one of the composite widgets.
1019 The syntax for the `const' widget is
1021 TYPE ::= (const [KEYWORD ARGUMENT]... [ VALUE ])
1023 The VALUE, if present, is used to initialize the `:value' property
1024 and can be any s-expression.
1027 This will display any valid s-expression in an immutable part of
1030 There are two variations of the `const' widget, namely
1031 `variable-item' and `function-item'. These should contain a symbol
1032 with a variable or function binding. The major difference from the
1033 `const' widget is that they will allow the user to see the variable or
1034 function documentation for the symbol.
1036 - Widget: variable-item
1037 An immutable symbol that is bound as a variable.
1039 - Widget: function-item
1040 An immutable symbol that is bound as a function.
1043 File: widget.info, Node: generic, Next: atoms, Prev: constants, Up: Sexp Types
1045 Generic Sexp Widget.
1046 --------------------
1048 The `sexp' widget can contain any lisp expression, and allows the
1049 user to edit it inline in the buffer.
1051 The syntax for the `sexp' widget is
1053 TYPE ::= (sexp [KEYWORD ARGUMENT]... [ VALUE ])
1056 This will allow you to edit any valid s-expression in an editable
1059 The `sexp' widget takes the same keyword arguments as the
1060 `editable-field' widget.
1063 File: widget.info, Node: atoms, Next: composite, Prev: generic, Up: Sexp Types
1065 Atomic Sexp Widgets.
1066 --------------------
1068 The atoms are s-expressions that does not consist of other
1069 s-expressions. A string is an atom, while a list is a composite type.
1070 You can edit the value of an atom with the following widgets.
1072 The syntax for all the atoms are
1074 TYPE ::= (NAME [KEYWORD ARGUMENT]... [ VALUE ])
1076 The VALUE, if present, is used to initialize the `:value' property
1077 and must be an expression of the same type as the widget. I.e. the
1078 string widget can only be initialized with a string.
1080 All the atom widgets take the same keyword arguments as the
1081 `editable-field' widget.
1084 Allows you to edit a string in an editable field.
1087 Allows you to edit a regular expression in an editable field.
1090 Allows you to enter a character in an editable field.
1093 Allows you to edit a file name in an editable field. If you invoke
1094 the tag button, you can edit the file name in the mini-buffer with
1099 If this is set to non-nil, only existing file names will be
1100 allowed in the minibuffer.
1103 Allows you to edit a directory name in an editable field. Similar
1104 to the `file' widget.
1107 Allows you to edit a lisp symbol in an editable field.
1110 Allows you to edit a lambda expression, or a function name with
1114 Allows you to edit a variable name, with completion.
1117 Allows you to edit an integer in an editable field.
1120 Allows you to edit a number in an editable field.
1123 Allows you to edit a boolean. In lisp this means a variable which
1124 is either nil meaning false, or non-nil meaning true.
1127 File: widget.info, Node: composite, Prev: atoms, Up: Sexp Types
1129 Composite Sexp Widgets.
1130 -----------------------
1132 The syntax for the composite are
1134 TYPE ::= (NAME [KEYWORD ARGUMENT]... COMPONENT...)
1136 Where each COMPONENT must be a widget type. Each component widget
1137 will be displayed in the buffer, and be editable to the user.
1140 The value of a `cons' widget is a cons-cell where the car is the
1141 value of the first component and the cdr is the value of the second
1142 component. There must be exactly two components.
1145 The value of a `list' widget is a list containing the value of
1146 each of its component.
1149 The value of a `vector' widget is a vector containing the value of
1150 each of its component.
1152 The above suffice for specifying fixed size lists and vectors. To
1153 get variable length lists and vectors, you can use a `choice', `set' or
1154 `repeat' widgets together with the `:inline' keywords. If any
1155 component of a composite widget has the `:inline' keyword set, its
1156 value must be a list which will then be spliced into the composite.
1157 For example, to specify a list whose first element must be a file name,
1158 and whose remaining arguments should either by the symbol `t' or two
1159 files, you can use the following widget specification:
1164 :value ("foo" "bar")
1167 The value of a widget of this type will either have the form `(file
1168 t)' or `(file string string)'.
1170 This concept of inline is probably hard to understand. It was
1171 certainly hard to implement so instead of confusing you more by trying
1172 to explain it here, I'll just suggest you meditate over it for a while.
1175 Allows you to edit a sexp which may have one of a fixed set of
1176 types. It is currently implemented with the `choice-menu' basic
1177 widget, and has a similar syntax.
1180 Allows you to specify a type which must be a list whose elements
1181 all belong to given set. The elements of the list is not
1182 significant. This is implemented on top of the `checklist' basic
1183 widget, and has a similar syntax.
1186 Allows you to specify a variable length list whose members are all
1187 of the same type. Implemented on top of the `editable-list' basic
1188 widget, and has a similar syntax.
1191 File: widget.info, Node: Widget Properties, Next: Defining New Widgets, Prev: Sexp Types, Up: Top
1196 You can examine or set the value of a widget by using the widget
1197 object that was returned by `widget-create'.
1199 - Function: widget-value widget
1200 Return the current value contained in WIDGET. It is an error to
1201 call this function on an uninitialized widget.
1203 - Function: widget-value-set widget value
1204 Set the value contained in WIDGET to VALUE. It is an error to
1205 call this function with an invalid VALUE.
1207 *Important:* You _must_ call `widget-setup' after modifying the
1208 value of a widget before the user is allowed to edit the widget again.
1209 It is enough to call `widget-setup' once if you modify multiple
1210 widgets. This is currently only necessary if the widget contains an
1211 editing field, but may be necessary for other widgets in the future.
1213 If your application needs to associate some information with the
1214 widget objects, for example a reference to the item being edited, it
1215 can be done with `widget-put' and `widget-get'. The property names
1216 must begin with a `:'.
1218 - Function: widget-put widget property value
1219 In WIDGET set PROPERTY to VALUE. PROPERTY should be a symbol,
1220 while VALUE can be anything.
1222 - Function: widget-get widget property
1223 In WIDGET return the value for PROPERTY. PROPERTY should be a
1224 symbol, the value is what was last set by `widget-put' for
1227 - Function: widget-member widget property
1228 Non-nil if WIDGET has a value (even nil) for property PROPERTY.
1230 Occasionally it can be useful to know which kind of widget you have,
1231 i.e. the name of the widget type you gave when the widget was created.
1233 - Function: widget-type widget
1234 Return the name of WIDGET, a symbol.
1236 Widgets can be in two states: active, which means they are
1237 modifiable by the user, or inactive, which means they cannot be
1238 modified by the user. You can query or set the state with the
1241 ;; Examine if WIDGET is active or not.
1242 (if (widget-apply WIDGET :active)
1243 (message "Widget is active.")
1244 (message "Widget is inactive.")
1246 ;; Make WIDGET inactive.
1247 (widget-apply WIDGET :deactivate)
1249 ;; Make WIDGET active.
1250 (widget-apply WIDGET :activate)
1252 A widget is inactive if itself or any of its ancestors (found by
1253 following the `:parent' link) have been deactivated. To make sure a
1254 widget is really active, you must therefore activate both itself and
1258 (widget-apply widget :activate)
1259 (setq widget (widget-get widget :parent)))
1261 You can check if a widget has been made inactive by examining the
1262 value of the `:inactive' keyword. If this is non-nil, the widget itself
1263 has been deactivated. This is different from using the `:active'
1264 keyword, in that the latter tells you if the widget *or* any of its
1265 ancestors have been deactivated. Do not attempt to set the `:inactive'
1266 keyword directly. Use the `:activate' `:deactivate' keywords instead.
1269 File: widget.info, Node: Defining New Widgets, Next: Widget Browser, Prev: Widget Properties, Up: Top
1271 Defining New Widgets
1272 ====================
1274 You can define specialized widgets with `define-widget'. It allows
1275 you to create a shorthand for more complex widgets. This includes
1276 specifying component widgets and new default values for the keyword
1279 - Function: widget-define name class doc &rest args
1280 Define a new widget type named NAME from `class'.
1282 NAME and class should both be symbols, `class' should be one of
1283 the existing widget types.
1285 The third argument DOC is a documentation string for the widget.
1287 After the new widget has been defined the following two calls will
1288 create identical widgets:
1290 * (widget-create NAME)
1292 * (apply widget-create CLASS ARGS)
1295 Using `widget-define' just stores the definition of the widget type
1296 in the `widget-type' property of NAME, which is what `widget-create'
1299 If you just want to specify defaults for keywords with no complex
1300 conversions, you can use `identity' as your conversion function.
1302 The following additional keyword arguments are useful when defining
1305 Function to convert a widget type before creating a widget of that
1306 type. It takes a widget type as an argument, and returns the
1307 converted widget type. When a widget is created, this function is
1308 called for the widget type and all the widget's parent types, most
1311 The following predefined functions can be used here:
1313 - Function: widget-types-convert-widget widget
1314 Convert `:args' as widget types in WIDGET.
1316 - Function: widget-value-convert-widget widget
1317 Initialize `:value' from `:args' in WIDGET.
1319 `:value-to-internal'
1320 Function to convert the value to the internal format. The function
1321 takes two arguments, a widget and an external value. It returns
1322 the internal value. The function is called on the present `:value'
1323 when the widget is created, and on any value set later with
1326 `:value-to-external'
1327 Function to convert the value to the external format. The function
1328 takes two arguments, a widget and an internal value, and returns
1329 the internal value. The function is called on the present `:value'
1330 when the widget is created, and on any value set later with
1334 Function to create a widget from scratch. The function takes one
1335 argument, a widget type, and creates a widget of that type,
1336 inserts it in the buffer, and returns a widget object.
1339 Function to delete a widget. The function takes one argument, a
1340 widget, and should remove all traces of the widget from the buffer.
1343 Function to expand the `%v' escape in the format string. It will
1344 be called with the widget as its argument and should insert a
1345 representation of the widget's value in the buffer.
1348 Should remove the representation of the widget's value from the
1349 buffer. It will be called with the widget as its argument. It
1350 doesn't have to remove the text, but it should release markers and
1351 delete nested widgets if such have been used.
1353 The following predefined function can be used here:
1355 - Function: widget-children-value-delete widget
1356 Delete all `:children' and `:buttons' in WIDGET.
1359 Function to extract the value of a widget, as it is displayed in
1362 The following predefined function can be used here:
1364 - Function: widget-value-value-get widget
1365 Return the `:value' property of WIDGET.
1368 Function to handle unknown `%' escapes in the format string. It
1369 will be called with the widget and the escape character as
1370 arguments. You can set this to allow your widget to handle
1371 non-standard escapes.
1373 You should end up calling `widget-default-format-handler' to handle
1374 unknown escape sequences. It will handle the `%h' and any future
1375 escape sequences as well as give an error for unknown escapes.
1378 Function to handle user initiated events. By default, `:notify'
1381 The following predefined function can be used here:
1383 - Function: widget-parent-action widget &optional event
1384 Tell `:parent' of WIDGET to handle the `:action'.
1385 Optional EVENT is the event that triggered the action.
1388 Function to prompt for a value in the minibuffer. The function
1389 should take four arguments, WIDGET, PROMPT, VALUE, and UNBOUND and
1390 should return a value for widget entered by the user. PROMPT is
1391 the prompt to use. VALUE is the default value to use, unless
1392 UNBOUND is non-nil. In this case there is no default value. The
1393 function should read the value using the method most natural for
1394 this widget and does not have to check whether it matches.
1396 If you want to define a new widget from scratch, use the `default'
1400 Widget used as a base for other widgets.
1402 It provides most of the functionality that is referred to as "by
1403 default" in this text.
1406 File: widget.info, Node: Widget Browser, Next: Widget Minor Mode, Prev: Defining New Widgets, Up: Top
1411 There is a separate package to browse widgets. This is intended to
1412 help programmers who want to examine the content of a widget. The
1413 browser shows the value of each keyword, but uses links for certain
1414 keywords such as `:parent', which avoids printing cyclic structures.
1416 - Command: widget-browse WIDGET
1417 Create a widget browser for WIDGET. When called interactively,
1420 - Command: widget-browse-other-window WIDGET
1421 Create a widget browser for WIDGET and show it in another window.
1422 When called interactively, prompt for WIDGET.
1424 - Command: widget-browse-at POS
1425 Create a widget browser for the widget at POS. When called
1426 interactively, use the position of point.
1429 File: widget.info, Node: Widget Minor Mode, Next: Utilities, Prev: Widget Browser, Up: Top
1434 There is a minor mode for manipulating widgets in major modes that
1435 doesn't provide any support for widgets themselves. This is mostly
1436 intended to be useful for programmers doing experiments.
1438 - Command: widget-minor-mode
1439 Toggle minor mode for traversing widgets. With arg, turn widget
1440 mode on if and only if arg is positive.
1442 - Variable: widget-minor-mode-keymap
1443 Keymap used in `widget-minor-mode'.
1446 File: widget.info, Node: Utilities, Next: Widget Wishlist, Prev: Widget Minor Mode, Up: Top
1451 - Function: widget-prompt-value widget prompt [ value unbound ]
1452 Prompt for a value matching WIDGET, using PROMPT.
1453 The current value is assumed to be VALUE, unless UNBOUND is
1456 - Function: widget-get-sibling widget
1457 Get the item WIDGET is assumed to toggle.
1458 This is only meaningful for radio buttons or checkboxes in a list.
1461 File: widget.info, Node: Widget Wishlist, Prev: Utilities, Up: Top
1466 * It should be possible to add or remove items from a list with `C-k'
1467 and `C-o' (suggested by RMS).
1469 * The `[INS]' and `[DEL]' buttons should be replaced by a single
1470 dash (`-'). The dash should be a button that, when invoked, ask
1471 whether you want to add or delete an item (RMS wanted to git rid of
1472 the ugly buttons, the dash is my idea).
1474 * The `menu-choice' tag should be prettier, something like the
1475 abbreviated menus in Open Look.
1477 * Finish `:tab-order'.
1479 * Make indentation work with glyphs and proportional fonts.
1481 * Add commands to show overview of object and class hierarchies to
1484 * Find a way to disable mouse highlight for inactive widgets.
1486 * Find a way to make glyphs look inactive.
1488 * Add `property-list' widget.
1490 * Add `association-list' widget.
1492 * Add `key-binding' widget.
1494 * Add `widget' widget for editing widget specifications.
1496 * Find clean way to implement variable length list. See
1497 `TeX-printer-list' for an explanation.
1499 * `C-h' in `widget-prompt-value' should give type specific help.
1503 * `C-e e' in a fixed size field should go to the end of the text in
1504 the field, not the end of the field itself.
1506 * Use and overlay instead of markers to delimit the widget. Create
1507 accessors for the end points.
1509 * Clicking on documentation links should call `describe-function' or
1510 `widget-browse-other-window' and friends directly, instead of going
1511 through `apropos'. If more than one function is valid for the
1512 symbol, it should pop up a menu.
1519 Node: Introduction
\7f581
1520 Node: User Interface
\7f4064
1521 Node: Programming Example
\7f8959
1522 Node: Setting Up the Buffer
\7f12276
1523 Node: Basic Types
\7f13993
1525 Node: url-link
\7f20552
1526 Node: info-link
\7f20864
1527 Node: push-button
\7f21155
1528 Node: editable-field
\7f21728
1530 Node: menu-choice
\7f23365
1531 Node: radio-button-choice
\7f24218
1533 Node: choice-item
\7f26173
1534 Node: toggle
\7f26671
1535 Node: checkbox
\7f27408
1536 Node: checklist
\7f27714
1537 Node: editable-list
\7f29158
1539 Node: Sexp Types
\7f30627
1540 Node: constants
\7f30940
1541 Node: generic
\7f32019
1543 Node: composite
\7f34499
1544 Node: Widget Properties
\7f36969
1545 Node: Defining New Widgets
\7f40034
1546 Node: Widget Browser
\7f45334
1547 Node: Widget Minor Mode
\7f46192
1548 Node: Utilities
\7f46749
1549 Node: Widget Wishlist
\7f47230