1 This is Info file ../info/widget.info, produced by Makeinfo version
2 1.68 from the input file widget.texi.
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 with the face specified by
451 This will be replaces with the buffer representation of the
452 widgets 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 widgets current value is valid for the widget. Otherwise, it
543 should return the widget containing the invalid data, and set that
544 widgets `: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 arguments represents each possible choice. The widgets
732 value of will be the value of the chosen TYPE argument. This widget
733 will match any value that matches at least one of the specified TYPE
737 Widget type used as a fallback when the value does not match any
738 of the specified TYPE arguments.
741 Set this to nil if you don't want to ignore case when prompting
742 for a choice through the minibuffer.
745 A list whose car is the widget representing the currently chosen
749 The current chosen type
755 File: widget.info, Node: radio-button-choice, Next: item, Prev: menu-choice, Up: Basic Types
757 The `radio-button-choice' Widget
758 --------------------------------
762 TYPE ::= (radio-button-choice [KEYWORD ARGUMENT]... TYPE ... )
764 The TYPE arguments represents each possible choice. The widgets
765 value of will be the value of the chosen TYPE argument. This widget
766 will match any value that matches at least one of the specified TYPE
769 The following extra properties are recognized.
772 This string will be inserted for each entry in the list. The
773 following `%' escapes are available:
775 Replaced with the buffer representation of the TYPE widget.
778 Replace with the radio button.
781 Insert a literal `%'.
784 A list of keywords to pass to the radio buttons. Useful for
785 setting e.g. the `:help-echo' for each button.
788 The widgets representing the radio buttons.
791 The widgets representing each type.
794 The current chosen type
799 You can add extra radio button items to a `radio-button-choice'
800 widget after it has been created with the function
801 `widget-radio-add-item'.
803 - Function: widget-radio-add-item WIDGET TYPE
804 Add to `radio-button-choice' widget WIDGET a new radio button item
807 Please note that such items added after the `radio-button-choice'
808 widget has been created will *not* be properly destructed when you call
812 File: widget.info, Node: item, Next: choice-item, Prev: radio-button-choice, Up: Basic Types
819 ITEM ::= (item [KEYWORD ARGUMENT]... VALUE)
821 The VALUE, if present, is used to initialize the `:value' property.
822 The value should be a string, which will be inserted in the buffer.
823 This widget will only match the specified value.
826 File: widget.info, Node: choice-item, Next: toggle, Prev: item, Up: Basic Types
828 The `choice-item' Widget
829 ------------------------
833 ITEM ::= (choice-item [KEYWORD ARGUMENT]... VALUE)
835 The VALUE, if present, is used to initialize the `:value' property.
836 The value should be a string, which will be inserted in the buffer as a
837 button. Activating the button of a `choice-item' is equivalent to
838 activating the parent widget. This widget will only match the
842 File: widget.info, Node: toggle, Next: checkbox, Prev: choice-item, Up: Basic Types
849 TYPE ::= (toggle [KEYWORD ARGUMENT]...)
851 The widget has two possible states, `on' and `off', which
852 corresponds to a `t' or `nil' value.
854 The following extra properties are recognized.
857 String representing the `on' state. By default the string `on'.
860 String representing the `off' state. By default the string `off'.
863 Name of a glyph to be used instead of the `:on' text string, on
864 emacsen that supports it.
867 Name of a glyph to be used instead of the `:off' text string, on
868 emacsen that supports it.
871 File: widget.info, Node: checkbox, Next: checklist, Prev: toggle, Up: Basic Types
873 The `checkbox' Widget
874 ---------------------
876 The widget has two possible states, `selected' and `unselected',
877 which corresponds to a `t' or `nil' value.
881 TYPE ::= (checkbox [KEYWORD ARGUMENT]...)
884 File: widget.info, Node: checklist, Next: editable-list, Prev: checkbox, Up: Basic Types
886 The `checklist' Widget
887 ----------------------
891 TYPE ::= (checklist [KEYWORD ARGUMENT]... TYPE ... )
893 The TYPE arguments represents each checklist item. The widgets
894 value of will be a list containing the value of each ticked TYPE
895 argument. The checklist widget will match a list whose elements all
896 matches at least one of the specified TYPE arguments.
898 The following extra properties are recognized.
901 This string will be inserted for each entry in the list. The
902 following `%' escapes are available:
904 Replaced with the buffer representation of the TYPE widget.
907 Replace with the checkbox.
910 Insert a literal `%'.
913 Usually, a checklist will only match if the items are in the exact
914 sequence given in the specification. By setting `:greedy' to
915 non-nil, it will allow the items to come in any sequence.
916 However, if you extract the value they will be in the sequence
917 given in the checklist. I.e. the original sequence is forgotten.
920 A list of keywords to pass to the checkboxes. Useful for setting
921 e.g. the `:help-echo' for each checkbox.
924 The widgets representing the checkboxes.
927 The widgets representing each type.
933 File: widget.info, Node: editable-list, Next: group, Prev: checklist, Up: Basic Types
935 The `editable-list' Widget
936 --------------------------
940 TYPE ::= (editable-list [KEYWORD ARGUMENT]... TYPE)
942 The value is a list, where each member represents one widget of type
945 The following extra properties are recognized.
948 This string will be inserted for each entry in the list. The
949 following `%' escapes are available:
951 This will be replaced with the buffer representation of the
955 Insert the [INS] button.
958 Insert the [DEL] button.
961 Insert a literal `%'.
963 `:insert-button-args'
964 A list of keyword arguments to pass to the insert buttons.
966 `:delete-button-args'
967 A list of keyword arguments to pass to the delete buttons.
969 `:append-button-args'
970 A list of keyword arguments to pass to the trailing insert button.
973 The widgets representing the insert and delete buttons.
976 The widgets representing the elements of the list.
979 List whose car is the type of the list elements.
982 File: widget.info, Node: group, Prev: editable-list, Up: Basic Types
987 This widget simply group other widget together.
991 TYPE ::= (group [KEYWORD ARGUMENT]... TYPE...)
993 The value is a list, with one member for each TYPE.
996 File: widget.info, Node: Sexp Types, Next: Widget Properties, Prev: Basic Types, Up: Top
1001 A number of widgets for editing s-expressions (lisp types) are also
1002 available. These basically fall in the following categories.
1012 File: widget.info, Node: constants, Next: generic, Prev: Sexp Types, Up: Sexp Types
1014 The Constant Widgets.
1015 ---------------------
1017 The `const' widget can contain any lisp expression, but the user is
1018 prohibited from editing edit it, which is mainly useful as a component
1019 of one of the composite widgets.
1021 The syntax for the `const' widget is
1023 TYPE ::= (const [KEYWORD ARGUMENT]... [ VALUE ])
1025 The VALUE, if present, is used to initialize the `:value' property
1026 and can be any s-expression.
1029 This will display any valid s-expression in an immutable part of
1032 There are two variations of the `const' widget, namely
1033 `variable-item' and `function-item'. These should contain a symbol
1034 with a variable or function binding. The major difference from the
1035 `const' widget is that they will allow the user to see the variable or
1036 function documentation for the symbol.
1038 - Widget: variable-item
1039 An immutable symbol that is bound as a variable.
1041 - Widget: function-item
1042 An immutable symbol that is bound as a function.
1045 File: widget.info, Node: generic, Next: atoms, Prev: constants, Up: Sexp Types
1047 Generic Sexp Widget.
1048 --------------------
1050 The `sexp' widget can contain any lisp expression, and allows the
1051 user to edit it inline in the buffer.
1053 The syntax for the `sexp' widget is
1055 TYPE ::= (sexp [KEYWORD ARGUMENT]... [ VALUE ])
1058 This will allow you to edit any valid s-expression in an editable
1061 The `sexp' widget takes the same keyword arguments as the
1062 `editable-field' widget.
1065 File: widget.info, Node: atoms, Next: composite, Prev: generic, Up: Sexp Types
1067 Atomic Sexp Widgets.
1068 --------------------
1070 The atoms are s-expressions that does not consist of other
1071 s-expressions. A string is an atom, while a list is a composite type.
1072 You can edit the value of an atom with the following widgets.
1074 The syntax for all the atoms are
1076 TYPE ::= (NAME [KEYWORD ARGUMENT]... [ VALUE ])
1078 The VALUE, if present, is used to initialize the `:value' property
1079 and must be an expression of the same type as the widget. I.e. the
1080 string widget can only be initialized with a string.
1082 All the atom widgets take the same keyword arguments as the
1083 `editable-field' widget.
1086 Allows you to edit a string in an editable field.
1089 Allows you to edit a regular expression in an editable field.
1092 Allows you to enter a character in an editable field.
1095 Allows you to edit a file name in an editable field. If you invoke
1096 the tag button, you can edit the file name in the mini-buffer with
1101 If this is set to non-nil, only existing file names will be
1102 allowed in the minibuffer.
1105 Allows you to edit a directory name in an editable field. Similar
1106 to the `file' widget.
1109 Allows you to edit a lisp symbol in an editable field.
1112 Allows you to edit a lambda expression, or a function name with
1116 Allows you to edit a variable name, with completion.
1119 Allows you to edit an integer in an editable field.
1122 Allows you to edit a number in an editable field.
1125 Allows you to edit a boolean. In lisp this means a variable which
1126 is either nil meaning false, or non-nil meaning true.
1129 File: widget.info, Node: composite, Prev: atoms, Up: Sexp Types
1131 Composite Sexp Widgets.
1132 -----------------------
1134 The syntax for the composite are
1136 TYPE ::= (NAME [KEYWORD ARGUMENT]... COMPONENT...)
1138 Where each COMPONENT must be a widget type. Each component widget
1139 will be displayed in the buffer, and be editable to the user.
1142 The value of a `cons' widget is a cons-cell where the car is the
1143 value of the first component and the cdr is the value of the second
1144 component. There must be exactly two components.
1147 The value of a `list' widget is a list containing the value of
1148 each of its component.
1151 The value of a `vector' widget is a vector containing the value of
1152 each of its component.
1154 The above suffice for specifying fixed size lists and vectors. To
1155 get variable length lists and vectors, you can use a `choice', `set' or
1156 `repeat' widgets together with the `:inline' keywords. If any
1157 component of a composite widget has the `:inline' keyword set, its
1158 value must be a list which will then be spliced into the composite.
1159 For example, to specify a list whose first element must be a file name,
1160 and whose remaining arguments should either by the symbol `t' or two
1161 files, you can use the following widget specification:
1166 :value ("foo" "bar")
1169 The value of a widget of this type will either have the form `(file
1170 t)' or `(file string string)'.
1172 This concept of inline is probably hard to understand. It was
1173 certainly hard to implement so instead of confuse you more by trying to
1174 explain it here, I'll just suggest you meditate over it for a while.
1177 Allows you to edit a sexp which may have one of fixed set of
1178 types. It is currently implemented with the `choice-menu' basic
1179 widget, and has a similar syntax.
1182 Allows you to specify a type which must be a list whose elements
1183 all belong to given set. The elements of the list is not
1184 significant. This is implemented on top of the `checklist' basic
1185 widget, and has a similar syntax.
1188 Allows you to specify a variable length list whose members are all
1189 of the same type. Implemented on top of the `editable-list' basic
1190 widget, and has a similar syntax.
1193 File: widget.info, Node: Widget Properties, Next: Defining New Widgets, Prev: Sexp Types, Up: Top
1198 You can examine or set the value of a widget by using the widget
1199 object that was returned by `widget-create'.
1201 - Function: widget-value WIDGET
1202 Return the current value contained in WIDGET. It is an error to
1203 call this function on an uninitialized widget.
1205 - Function: widget-value-set WIDGET VALUE
1206 Set the value contained in WIDGET to VALUE. It is an error to
1207 call this function with an invalid VALUE.
1209 *Important:* You *must* call `widget-setup' after modifying the
1210 value of a widget before the user is allowed to edit the widget again.
1211 It is enough to call `widget-setup' once if you modify multiple
1212 widgets. This is currently only necessary if the widget contains an
1213 editing field, but may be necessary for other widgets in the future.
1215 If your application needs to associate some information with the
1216 widget objects, for example a reference to the item being edited, it
1217 can be done with `widget-put' and `widget-get'. The property names
1218 must begin with a `:'.
1220 - Function: widget-put WIDGET PROPERTY VALUE
1221 In WIDGET set PROPERTY to VALUE. PROPERTY should be a symbol,
1222 while VALUE can be anything.
1224 - Function: widget-get WIDGET PROPERTY
1225 In WIDGET return the value for PROPERTY. PROPERTY should be a
1226 symbol, the value is what was last set by `widget-put' for
1229 - Function: widget-member WIDGET PROPERTY
1230 Non-nil if WIDGET has a value (even nil) for property PROPERTY.
1232 Occasionally it can be useful to know which kind of widget you have,
1233 i.e. the name of the widget type you gave when the widget was created.
1235 - Function: widget-type WIDGET
1236 Return the name of WIDGET, a symbol.
1238 Widgets can be in two states: active, which means they are
1239 modifiable by the user, or inactive, which means they cannot be
1240 modified by the user. You can query or set the state with the
1243 ;; Examine if WIDGET is active or not.
1244 (if (widget-apply WIDGET :active)
1245 (message "Widget is active.")
1246 (message "Widget is inactive.")
1248 ;; Make WIDGET inactive.
1249 (widget-apply WIDGET :deactivate)
1251 ;; Make WIDGET active.
1252 (widget-apply WIDGET :activate)
1254 A widget is inactive if itself, or any of its ancestors (found by
1255 following the `:parent' link) have been deactivated. To make sure a
1256 widget is really active, you must therefore activate both itself, and
1260 (widget-apply widget :activate)
1261 (setq widget (widget-get widget :parent)))
1263 You can check if a widget has been made inactive by examining the
1264 value of `:inactive' keyword. If this is non-nil, the widget itself has
1265 been deactivated. This is different from using the `:active' keyword,
1266 in that the later tell you if the widget *or* any of its ancestors have
1267 been deactivated. Do not attempt to set the `:inactive' keyword
1268 directly. Use the `:activate' `:deactivated' keywords instead.
1271 File: widget.info, Node: Defining New Widgets, Next: Widget Browser, Prev: Widget Properties, Up: Top
1273 Defining New Widgets
1274 ====================
1276 You can define specialized widgets with `define-widget'. It allows
1277 you to create a shorthand for more complex widgets, including specifying
1278 component widgets and default new default values for the keyword
1281 - Function: widget-define NAME CLASS DOC &rest ARGS
1282 Define a new widget type named NAME from `class'.
1284 NAME and class should both be symbols, `class' should be one of
1285 the existing widget types.
1287 The third argument DOC is a documentation string for the widget.
1289 After the new widget has been defined, the following two calls will
1290 create identical widgets:
1292 * (widget-create NAME)
1294 * (apply widget-create CLASS ARGS)
1297 Using `widget-define' does just store the definition of the widget
1298 type in the `widget-type' property of NAME, which is what
1299 `widget-create' uses.
1301 If you just want to specify defaults for keywords with no complex
1302 conversions, you can use `identity' as your conversion function.
1304 The following additional keyword arguments are useful when defining
1307 Function to convert a widget type before creating a widget of that
1308 type. It takes a widget type as an argument, and returns the
1309 converted widget type. When a widget is created, this function is
1310 called for the widget type and all the widgets parent types, most
1313 The following predefined functions can be used here:
1315 - Function: widget-types-convert-widget WIDGET
1316 Convert `:args' as widget types in WIDGET.
1318 - Function: widget-value-convert-widget WIDGET
1319 Initialize `:value' from `:args' in WIDGET.
1321 `:value-to-internal'
1322 Function to convert the value to the internal format. The function
1323 takes two arguments, a widget and an external value, and returns
1324 the internal value. The function is called on the present `:value'
1325 when the widget is created, and on any value set later with
1328 `:value-to-external'
1329 Function to convert the value to the external format. The function
1330 takes two arguments, a widget and an internal value, and returns
1331 the internal value. The function is called on the present `:value'
1332 when the widget is created, and on any value set later with
1336 Function to create a widget from scratch. The function takes one
1337 argument, a widget type, and create a widget of that type, insert
1338 it in the buffer, and return a widget object.
1341 Function to delete a widget. The function takes one argument, a
1342 widget, and should remove all traces of the widget from the buffer.
1345 Function to expand the `%v' escape in the format string. It will
1346 be called with the widget as its argument. Should insert a
1347 representation of the widgets value in the buffer.
1350 Should remove the representation of the widgets value from the
1351 buffer. It will be called with the widget as its argument. It
1352 doesn't have to remove the text, but it should release markers and
1353 delete nested widgets if such has been used.
1355 The following predefined function can be used here:
1357 - Function: widget-children-value-delete WIDGET
1358 Delete all `:children' and `:buttons' in WIDGET.
1361 Function to extract the value of a widget, as it is displayed in
1364 The following predefined function can be used here:
1366 - Function: widget-value-value-get WIDGET
1367 Return the `:value' property of WIDGET.
1370 Function to handle unknown `%' escapes in the format string. It
1371 will be called with the widget and the escape character as
1372 arguments. You can set this to allow your widget to handle
1373 non-standard escapes.
1375 You should end up calling `widget-default-format-handler' to handle
1376 unknown escape sequences, which will handle the `%h' and any future
1377 escape sequences, as well as give an error for unknown escapes.
1380 Function to handle user initiated events. By default, `:notify'
1383 The following predefined function can be used here:
1385 - Function: widget-parent-action WIDGET &optional EVENT
1386 Tell `:parent' of WIDGET to handle the `:action'.
1387 Optional EVENT is the event that triggered the action.
1390 Function to prompt for a value in the minibuffer. The function
1391 should take four arguments, WIDGET, PROMPT, VALUE, and UNBOUND and
1392 should return a value for widget entered by the user. PROMPT is
1393 the prompt to use. VALUE is the default value to use, unless
1394 UNBOUND is non-nil in which case there are no default value. The
1395 function should read the value using the method most natural for
1396 this widget, and does not have to check that it matches.
1398 If you want to define a new widget from scratch, use the `default'
1402 Widget used as a base for other widgets.
1404 It provides most of the functionality that is referred to as "by
1405 default" in this text.
1408 File: widget.info, Node: Widget Browser, Next: Widget Minor Mode, Prev: Defining New Widgets, Up: Top
1413 There is a separate package to browse widgets. This is intended to
1414 help programmers who want to examine the content of a widget. The
1415 browser shows the value of each keyword, but uses links for certain
1416 keywords such as `:parent', which avoids printing cyclic structures.
1418 - Command: widget-browse WIDGET
1419 Create a widget browser for WIDGET. When called interactively,
1422 - Command: widget-browse-other-window WIDGET
1423 Create a widget browser for WIDGET and show it in another window.
1424 When called interactively, prompt for WIDGET.
1426 - Command: widget-browse-at POS
1427 Create a widget browser for the widget at POS. When called
1428 interactively, use the position of point.
1431 File: widget.info, Node: Widget Minor Mode, Next: Utilities, Prev: Widget Browser, Up: Top
1436 There is a minor mode for manipulating widgets in major modes that
1437 doesn't provide any support for widgets themselves. This is mostly
1438 intended to be useful for programmers doing experiments.
1440 - Command: widget-minor-mode
1441 Toggle minor mode for traversing widgets. With arg, turn widget
1442 mode on if and only if arg is positive.
1444 - Variable: widget-minor-mode-keymap
1445 Keymap used in `widget-minor-mode'.
1448 File: widget.info, Node: Utilities, Next: Widget Wishlist, Prev: Widget Minor Mode, Up: Top
1453 - Function: widget-prompt-value WIDGET PROMPT [ VALUE UNBOUND ]
1454 Prompt for a value matching WIDGET, using PROMPT.
1455 The current value is assumed to be VALUE, unless UNBOUND is
1458 - Function: widget-get-sibling WIDGET
1459 Get the item WIDGET is assumed to toggle.
1460 This is only meaningful for radio buttons or checkboxes in a list.
1463 File: widget.info, Node: Widget Wishlist, Prev: Utilities, Up: Top
1468 * It should be possible to add or remove items from a list with `C-k'
1469 and `C-o' (suggested by RMS).
1471 * The `[INS]' and `[DEL]' buttons should be replaced by a single
1472 dash (`-'). The dash should be a button that, when invoked, ask
1473 whether you want to add or delete an item (RMS wanted to git rid of
1474 the ugly buttons, the dash is my idea).
1476 * The `menu-choice' tag should be prettier, something like the
1477 abbreviated menus in Open Look.
1479 * Finish `:tab-order'.
1481 * Make indentation work with glyphs and proportional fonts.
1483 * Add commands to show overview of object and class hierarchies to
1486 * Find a way to disable mouse highlight for inactive widgets.
1488 * Find a way to make glyphs look inactive.
1490 * Add `property-list' widget.
1492 * Add `association-list' widget.
1494 * Add `key-binding' widget.
1496 * Add `widget' widget for editing widget specifications.
1498 * Find clean way to implement variable length list. See
1499 `TeX-printer-list' for an explanation.
1501 * `C-h' in `widget-prompt-value' should give type specific help.
1505 * `C-e e' in a fixed size field should go to the end of the text in
1506 the field, not the end of the field itself.
1508 * Use and overlay instead of markers to delimit the widget. Create
1509 accessors for the end points.
1511 * Clicking on documentation links should call `describe-function' or
1512 `widget-browse-other-window' and friends directly, instead of going
1513 through `apropos'. If more than one function is valid for the
1514 symbol, it should pop up a menu.
1520 Node: Introduction
\7f607
1521 Node: User Interface
\7f4090
1522 Node: Programming Example
\7f8985
1523 Node: Setting Up the Buffer
\7f12302
1524 Node: Basic Types
\7f14019
1526 Node: url-link
\7f20578
1527 Node: info-link
\7f20890
1528 Node: push-button
\7f21181
1529 Node: editable-field
\7f21754
1531 Node: menu-choice
\7f23391
1532 Node: radio-button-choice
\7f24256
1534 Node: choice-item
\7f26223
1535 Node: toggle
\7f26721
1536 Node: checkbox
\7f27446
1537 Node: checklist
\7f27752
1538 Node: editable-list
\7f29196
1540 Node: Sexp Types
\7f30665
1541 Node: constants
\7f30978
1542 Node: generic
\7f32057
1544 Node: composite
\7f34537
1545 Node: Widget Properties
\7f37003
1546 Node: Defining New Widgets
\7f40066
1547 Node: Widget Browser
\7f45366
1548 Node: Widget Minor Mode
\7f46224
1549 Node: Utilities
\7f46781
1550 Node: Widget Wishlist
\7f47262