1 This is ../info/widget.info, produced by makeinfo version 4.6 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::
32 File: widget.info, Node: Introduction, Next: User Interface, Prev: Top, Up: Top
37 Most graphical user interface toolkits, such as Motif and XView, provide
38 a number of standard user interface controls (sometimes known as
39 `widgets' or `gadgets'). Emacs doesn't really support anything like
40 this, except for an incredible powerful text "widget". On the other
41 hand, Emacs does provide the necessary primitives to implement many
42 other widgets within a text buffer. The `widget' package simplifies
45 The basic widgets are:
48 Areas of text with an associated action. Intended for hypertext
49 links embedded in text.
52 Like link, but intended for stand-alone buttons.
55 An editable text field. It can be either variable or fixed length.
58 Allows the user to choose one of multiple options from a menu, each
59 option is itself a widget. Only the selected option will be
60 visible in the buffer.
63 Allows the user to choose one of multiple options by activating
64 radio buttons. The options are implemented as widgets. All
65 options will be visible in the buffer.
68 A simple constant widget intended to be used in the `menu-choice'
69 and `radio-button-choice' widgets.
72 A button item only intended for use in choices. When invoked, the
73 user will be asked to select another option from the choice widget.
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 `define-widget', 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 consists of read only text for documentation and some fields,
134 where each of the fields contains two parts, a tag and a value. The
135 tags are used to identify the fields, so the documentation can refer to
136 the foo field, meaning the field tagged with `Foo'. Here is an example
139 Here is some documentation.
141 Name: My Name *Choose*: This option
146 See also _other work_ for more information.
148 Numbers: count to three below
166 [Apply Form] [Reset Form]
168 The top level widgets in is example are tagged `Name', `Choose',
169 `Address', `_other work_', `Numbers', `Select multiple', `Select one',
170 `[Apply Form]', and `[Reset Form]'. There are basically two thing the
171 user can do within a form, namely editing the editable text fields and
172 activating the buttons.
177 In the example, the value for the `Name' is most likely displayed in an
178 editable text field, and so are values for each of the members of the
179 `Numbers' list. All the normal Emacs editing operations are available
180 for editing these fields. The only restriction is that each change you
181 make must be contained within a single editable text field. For
182 example, capitalizing all text from the middle of one field to the
183 middle of another field is prohibited.
185 Editing text fields are created by the `editable-field' widget.
187 The editing text fields are highlighted with the `widget-field-face'
188 face, making them easy to find.
190 - Face: widget-field-face
191 Face used for other editing fields.
196 Some portions of the buffer have an associated "action", which can be
197 "invoked" by a standard key or mouse command. These portions are
198 called "buttons". The default commands for activating a button are:
201 - Command: widget-button-press POS &optional EVENT
202 Invoke the button at POS, defaulting to point. If point is
203 not located on a button, invoke the binding in
204 `widget-global-map' (by default the global map).
207 - Command: widget-button-click EVENT
208 Invoke the button at the location of the mouse pointer. If
209 the mouse pointer is located in an editable text field,
210 invoke the binding in `widget-global-map' (by default the
213 There are several different kind of buttons, all of which are
214 present in the example:
216 _The Option Field Tags._
217 When you invoke one of these buttons, you will be asked to choose
218 between a number of different options. This is how you edit an
219 option field. Option fields are created by the `menu-choice'
220 widget. In the example, `Choose' is an option field tag.
222 _The `[INS]' and `[DEL]' buttons._
223 Activating these will insert or delete elements from an editable
224 list. The list is created by the `editable-list' widget.
227 The `_other work_' is an example of an embedded button. Embedded
228 buttons are not associated with a fields, but can serve any
229 purpose, such as implementing hypertext references. They are
230 usually created by the `link' widget.
232 _The `[ ]' and `[X]' buttons._
233 Activating one of these will convert it to the other. This is
234 useful for implementing multiple-choice fields. You can create it
237 _The `( )' and `(*)' buttons._
238 Only one radio button in a `radio-button-choice' widget can be
239 selected at any time. When you invoke one of the unselected radio
240 buttons, it will be selected and the previous selected radio
241 button will become unselected.
243 _The `[Apply Form]' `[Reset Form]' buttons._
244 These are explicit buttons made with the `push-button' widget.
245 The main difference from the `link' widget is that the buttons are
246 will be displayed as GUI buttons when possible. enough.
248 To make them easier to locate, buttons are emphasized in the buffer.
250 - Face: widget-button-face
251 Face used for buttons.
253 - User Option: widget-mouse-face
254 Face used for buttons when the mouse pointer is above it.
259 You can use all the normal Emacs commands to move around in a form
260 buffer, plus you will have these additional commands:
263 - Command: widget-forward &optional count
264 Move point COUNT buttons or editing fields forward.
267 - Command: widget-backward &optional count
268 Move point COUNT buttons or editing fields backward.
271 File: widget.info, Node: Programming Example, Next: Setting Up the Buffer, Prev: User Interface, Up: Top
276 Here is the code to implement the user interface example (see *Note
284 (defvar widget-example-repeat)
286 (defun widget-example ()
287 "Create the widgets from the Widget manual."
289 (kill-buffer (get-buffer-create "*Widget Example*"))
290 (switch-to-buffer (get-buffer-create "*Widget Example*"))
291 (kill-all-local-variables)
292 (make-local-variable 'widget-example-repeat)
293 (widget-insert "Here is some documentation.\n\nName: ")
294 (widget-create 'editable-field
297 (widget-create 'menu-choice
300 :help-echo "Choose me, please!"
301 :notify (lambda (widget &rest ignore)
302 (message "%s is a good choice!"
303 (widget-value widget)))
304 '(item :tag "This option" :value "This")
305 '(choice-item "That option")
306 '(editable-field :menu-tag "No option" "Thus option"))
307 (widget-insert "Address: ")
308 (widget-create 'editable-field
309 "Some Place\nIn some City\nSome country.")
310 (widget-insert "\nSee also ")
312 :notify (lambda (&rest ignore)
313 (widget-value-set widget-example-repeat
317 (widget-insert " for more information.\n\nNumbers: count to three below\n")
318 (setq widget-example-repeat
319 (widget-create 'editable-list
320 :entry-format "%i %d %v"
321 :notify (lambda (widget &rest ignore)
322 (let ((old (widget-get widget
324 (new (length (widget-value widget))))
326 (widget-put widget ':example-length new)
327 (message "You can count to %d." new))))
328 :value '("One" "Eh, two?" "Five!")
329 '(editable-field :value "three")))
330 (widget-insert "\n\nSelect multiple:\n\n")
331 (widget-create 'checkbox t)
332 (widget-insert " This\n")
333 (widget-create 'checkbox nil)
334 (widget-insert " That\n")
335 (widget-create 'checkbox
336 :notify (lambda (&rest ignore) (message "Tickle"))
338 (widget-insert " Thus\n\nSelect one:\n\n")
339 (widget-create 'radio-button-choice
341 :notify (lambda (widget &rest ignore)
342 (message "You selected %s"
343 (widget-value widget)))
344 '(item "One") '(item "Another One.") '(item "A Final One."))
346 (widget-create 'push-button
347 :notify (lambda (&rest ignore)
348 (if (= (length (widget-value widget-example-repeat))
350 (message "Congratulation!")
351 (error "Three was the count!")))
354 (widget-create 'push-button
355 :notify (lambda (&rest ignore)
359 (use-local-map widget-keymap)
363 File: widget.info, Node: Setting Up the Buffer, Next: Basic Types, Prev: Programming Example, Up: Top
365 Setting Up the Buffer
366 =====================
368 Widgets are created with `widget-create', which returns a "widget"
369 object. This object can be queried and manipulated by other widget
370 functions, until it is deleted with `widget-delete'. After the widgets
371 have been created, `widget-setup' must be called to enable them.
373 - Function: widget-create type [ keyword argument ]...
374 Create and return a widget of type TYPE. The syntax for the TYPE
375 argument is described in *Note Basic Types::.
377 The keyword arguments can be used to overwrite the keyword
378 arguments that are part of TYPE.
380 - Function: widget-delete widget
381 Delete WIDGET and remove it from the buffer.
383 - Function: widget-setup
384 Setup a buffer to support widgets.
386 This should be called after creating all the widgets and before
387 allowing the user to edit them.
390 If you want to insert text outside the widgets in the form, the
391 recommended way to do that is with `widget-insert'.
393 - Function: widget-insert
394 Insert the arguments, either strings or characters, at point. The
395 inserted text will be read only.
397 There is a standard widget keymap which you might find useful.
399 - Const: widget-keymap
400 A keymap with the global keymap as its parent.
401 <TAB> and `C-<TAB>' are bound to `widget-forward' and
402 `widget-backward', respectively. `<RET>' and `mouse-2' are bound
403 to `widget-button-press' and `widget-button-'.
405 - Variable: widget-global-map
406 Keymap used by `widget-button-press' and `widget-button-click'
407 when not on a button. By default this is `global-map'.
410 File: widget.info, Node: Basic Types, Next: Sexp Types, Prev: Setting Up the Buffer, Up: Top
415 The syntax of a type specification is given below:
417 NAME ::= (NAME [KEYWORD ARGUMENT]... ARGS)
420 where NAME is a widget name, KEYWORD is the name of a property,
421 ARGUMENT is the value of the property, and ARGS are interpreted in a
424 There following keyword arguments that apply to all widgets:
427 The initial value for widgets of this type.
430 This string will be inserted in the buffer when you create a
431 widget. The following `%' escapes are available:
435 The text inside will be marked as a button.
437 By default, the text will be shown in `widget-button-face',
438 and surrounded by brackets.
440 - User Option: widget-button-prefix
441 String to prefix buttons.
443 - User Option: widget-button-suffix
444 String to suffix buttons.
448 The text inside will be displayed in the face specified by
452 This will be replaced with the buffer representation of the
453 widget's value. What this is depends on the widget type.
456 Insert the string specified by `:doc' here.
459 Like `%d', with the following modifications: If the
460 documentation string is more than one line, it will add a
461 button which will toggle between showing only the first line,
462 and showing the full text. Furthermore, if there is no
463 `:doc' property in the widget, it will instead examine the
464 `:documentation-property' property. If it is a lambda
465 expression, it will be called with the widget's value as an
466 argument, and the result will be used as the documentation
470 Insert the string specified by `:tag' here, or the `princ'
471 representation of the value if there is no tag.
474 Insert a literal `%'.
477 Face used to highlight text inside %[ %] in the format.
481 Text around %[ %] in the format.
488 The string is inserted literally.
491 The value of the symbol is expanded according to this table.
494 The string inserted by the `%d' or `%h' escape in the format
498 The string inserted by the `%t' escape in the format string.
501 Name of image to use instead of the string specified by `:tag' on
502 Emacsen that supports it.
505 Message displayed whenever you move to the widget with either
506 `widget-forward' or `widget-backward'.
509 An integer indicating the absolute number of spaces to indent
510 children of this widget.
513 An integer indicating how many extra spaces to add to the widget's
514 grandchildren compared to this widget.
517 An integer indicating how many extra spaces to add to the widget's
518 children compared to this widget.
521 A function called each time the widget or a nested widget is
522 changed. The function is called with two or three arguments. The
523 first argument is the widget itself, the second argument is the
524 widget that was changed, and the third argument is the event
525 leading to the change, if any. In editable fields, this includes
526 all insertions, deletions, _etc_. To watch only for "final"
527 actions, redefine the `:action' callback.
530 Tag used in the menu when the widget is used as an option in a
531 `menu-choice' widget.
534 Function used for finding the tag when the widget is used as an
535 option in a `menu-choice' widget. By default, the tag used will
536 be either the `:menu-tag' or `:tag' property if present, or the
537 `princ' representation of the `:value' property if not.
540 Should be a function called with two arguments, the widget and a
541 value, and returning non-nil if the widget can represent the
545 A function which takes a widget as an argument, and returns nil if
546 the widget's current value is valid for the widget. Otherwise it
547 should return the widget containing the invalid data, and set that
548 widget's `:error' property to a string explaining the error.
550 The following predefined function can be used:
552 - Function: widget-children-validate widget
553 All the `:children' of WIDGET must be valid.
556 Specify the order in which widgets are traversed with
557 `widget-forward' or `widget-backward'. This is only partially
560 a. Widgets with tabbing order `-1' are ignored.
562 b. (Unimplemented) When on a widget with tabbing order N, go to
563 the next widget in the buffer with tabbing order N+1 or `nil',
564 whichever comes first.
566 c. When on a widget with no tabbing order specified, go to the
567 next widget in the buffer with a positive tabbing order, or
571 The parent of a nested widget (e.g. a `menu-choice' item or an
572 element of an `editable-list' widget).
575 This keyword is only used for members of a `radio-button-choice' or
576 `checklist'. The value should be a list of extra keyword
577 arguments, which will be used when creating the `radio-button' or
578 `checkbox' associated with this item.
581 - User Option: widget-glyph-directory
582 Directory where glyphs are found. Widget will look here for a
583 file with the same name as specified for the image, with either a
584 `.xpm' (if supported) or `.xbm' extension.
586 - User Option: widget-glyph-enable
587 If non-nil, allow glyphs to appear on displays where they are
599 * radio-button-choice::
609 File: widget.info, Node: link, Next: url-link, Prev: Basic Types, Up: Basic Types
616 TYPE ::= (link [KEYWORD ARGUMENT]... [ VALUE ])
618 The VALUE, if present, is used to initialize the `:value' property.
619 The value should be a string, which will be inserted in the buffer.
621 By default the link will be shown in brackets.
623 - User Option: widget-link-prefix
624 String to prefix links.
626 - User Option: widget-link-suffix
627 String to suffix links.
630 File: widget.info, Node: url-link, Next: info-link, Prev: link, Up: Basic Types
632 The `url-link' Widget
633 ---------------------
637 TYPE ::= (url-link [KEYWORD ARGUMENT]... URL)
639 When this link is invoked, the WWW browser specified by
640 `browse-url-browser-function' will be called with URL.
643 File: widget.info, Node: info-link, Next: push-button, Prev: url-link, Up: Basic Types
645 The `info-link' Widget
646 ----------------------
650 TYPE ::= (info-link [KEYWORD ARGUMENT]... ADDRESS)
652 When this link is invoked, the built-in info browser is started on
656 File: widget.info, Node: push-button, Next: editable-field, Prev: info-link, Up: Basic Types
658 The `push-button' Widget
659 ------------------------
663 TYPE ::= (push-button [KEYWORD ARGUMENT]... [ VALUE ])
665 The VALUE, if present, is used to initialize the `:value' property.
666 The value should be a string, which will be inserted in the buffer.
668 By default the tag will be shown in brackets.
670 - User Option: widget-push-button-prefix
671 String to prefix push buttons.
673 - User Option: widget-push-button-suffix
674 String to suffix push buttons.
677 File: widget.info, Node: editable-field, Next: text, Prev: push-button, Up: Basic Types
679 The `editable-field' Widget
680 ---------------------------
684 TYPE ::= (editable-field [KEYWORD ARGUMENT]... [ VALUE ])
686 The VALUE, if present, is used to initialize the `:value' property.
687 The value should be a string, which will be inserted in field. This
688 widget will match all string values.
690 The following extra properties are recognized.
693 The minimum width of the editable field.
694 By default the field will reach to the end of the line. If the
695 content is too large, the displayed representation will expand to
696 contain it. The content is not truncated to size.
699 Face used for highlighting the editable field. Default is
703 Character used to display the value. You can set this to e.g. `?*'
704 if the field contains a password or other secret information. By
705 default, the value is not secret.
708 By default the `:validate' function will match the content of the
709 field with the value of this attribute. The default value is `""'
710 which matches everything.
713 Keymap used in the editable field. The default value is
714 `widget-field-keymap', which allows you to use all the normal
715 editing commands, even if the buffer's major mode suppress some of
716 them. Pressing return invokes the function specified by `:action'.
719 File: widget.info, Node: text, Next: menu-choice, Prev: editable-field, Up: Basic Types
724 This is just like `editable-field', but intended for multiline text
725 fields. The default `:keymap' is `widget-text-keymap', which does not
726 rebind the return key.
729 File: widget.info, Node: menu-choice, Next: radio-button-choice, Prev: text, Up: Basic Types
731 The `menu-choice' Widget
732 ------------------------
736 TYPE ::= (menu-choice [KEYWORD ARGUMENT]... TYPE ... )
738 The TYPE argument represents each possible choice. The widget's
739 value will be that of the chosen TYPE argument. This widget will match
740 any value matching at least one of the specified TYPE arguments.
743 Widget type used as a fallback when the value does not match any
744 of the specified TYPE arguments.
747 Set this to nil if you don't want to ignore case when prompting
748 for a choice through the minibuffer.
751 A list whose car is the widget representing the currently chosen
755 The current chosen type
761 File: widget.info, Node: radio-button-choice, Next: item, Prev: menu-choice, Up: Basic Types
763 The `radio-button-choice' Widget
764 --------------------------------
768 TYPE ::= (radio-button-choice [KEYWORD ARGUMENT]... TYPE ... )
770 The TYPE argument represents each possible choice. The widget's
771 value will be that of the chosen TYPE argument. This widget will match
772 any value matching at least one of the specified TYPE arguments.
774 The following extra properties are recognized.
777 This string will be inserted for each entry in the list. The
778 following `%' escapes are available:
780 Replaced with the buffer representation of the TYPE widget.
783 Replace with the radio button.
786 Insert a literal `%'.
789 A list of keywords to pass to the radio buttons. Useful for
790 setting e.g. the `:help-echo' for each button.
793 The widgets representing the radio buttons.
796 The widgets representing each type.
799 The current chosen type
804 You can add extra radio button items to a `radio-button-choice'
805 widget after it has been created with the function
806 `widget-radio-add-item'.
808 - Function: widget-radio-add-item widget type
809 Add to `radio-button-choice' widget WIDGET a new radio button item
812 Please note that such items added after the `radio-button-choice'
813 widget has been created will *not* be properly destructed when you call
817 File: widget.info, Node: item, Next: choice-item, Prev: radio-button-choice, Up: Basic Types
824 ITEM ::= (item [KEYWORD ARGUMENT]... VALUE)
826 The VALUE, if present, is used to initialize the `:value' property.
827 The value should be a string, which will be inserted in the buffer.
828 This widget will only match the specified value.
831 File: widget.info, Node: choice-item, Next: toggle, Prev: item, Up: Basic Types
833 The `choice-item' Widget
834 ------------------------
838 ITEM ::= (choice-item [KEYWORD ARGUMENT]... VALUE)
840 The VALUE, if present, is used to initialize the `:value' property.
841 The value should be a string, which will be inserted in the buffer as a
842 button. Activating the button of a `choice-item' is equivalent to
843 activating the parent widget. This widget will only match the
847 File: widget.info, Node: toggle, Next: checkbox, Prev: choice-item, Up: Basic Types
854 TYPE ::= (toggle [KEYWORD ARGUMENT]...)
856 The widget has two possible states, `on' and `off', which correspond
857 to a `t' or `nil' value respectively.
859 The following extra properties are recognized.
862 String representing the `on' state. By default the string `on'.
865 String representing the `off' state. By default the string `off'.
868 Name of a glyph to be used instead of the `:on' text string, on
869 emacsen that supports it.
872 Name of a glyph to be used instead of the `:off' text string, on
873 emacsen that supports it.
876 File: widget.info, Node: checkbox, Next: checklist, Prev: toggle, Up: Basic Types
878 The `checkbox' Widget
879 ---------------------
881 The widget has two possible states, `selected' and `unselected', which
882 corresponds to a `t' or `nil' value.
886 TYPE ::= (checkbox [KEYWORD ARGUMENT]...)
889 File: widget.info, Node: checklist, Next: editable-list, Prev: checkbox, Up: Basic Types
891 The `checklist' Widget
892 ----------------------
896 TYPE ::= (checklist [KEYWORD ARGUMENT]... TYPE ... )
898 The TYPE arguments represents each checklist item. The widget's
899 value will be a list containing the values of all ticked TYPE
900 arguments. The checklist widget will match a list whose elements all
901 match at least one of the specified TYPE arguments.
903 The following extra properties are recognized.
906 This string will be inserted for each entry in the list. The
907 following `%' escapes are available:
909 Replaced with the buffer representation of the TYPE widget.
912 Replace with the checkbox.
915 Insert a literal `%'.
918 Usually a checklist will only match if the items are in the exact
919 sequence given in the specification. By setting `:greedy' to
920 non-nil, it will allow the items to appear in any sequence.
921 However, if you extract the values they will be in the sequence
922 given in the checklist. I.e. the original sequence is forgotten.
925 A list of keywords to pass to the checkboxes. Useful for setting
926 e.g. the `:help-echo' for each checkbox.
929 The widgets representing the checkboxes.
932 The widgets representing each type.
938 File: widget.info, Node: editable-list, Next: group, Prev: checklist, Up: Basic Types
940 The `editable-list' Widget
941 --------------------------
945 TYPE ::= (editable-list [KEYWORD ARGUMENT]... TYPE)
947 The value is a list, where each member represents one widget of type
950 The following extra properties are recognized.
953 This string will be inserted for each entry in the list. The
954 following `%' escapes are available:
956 This will be replaced with the buffer representation of the
960 Insert the [INS] button.
963 Insert the [DEL] button.
966 Insert a literal `%'.
968 `:insert-button-args'
969 A list of keyword arguments to pass to the insert buttons.
971 `:delete-button-args'
972 A list of keyword arguments to pass to the delete buttons.
974 `:append-button-args'
975 A list of keyword arguments to pass to the trailing insert button.
978 The widgets representing the insert and delete buttons.
981 The widgets representing the elements of the list.
984 List whose car is the type of the list elements.
988 File: widget.info, Node: group, Prev: editable-list, Up: Basic Types
993 This widget simply groups other widgets together.
997 TYPE ::= (group [KEYWORD ARGUMENT]... TYPE...)
999 The value is a list, with one member for each TYPE.
1002 File: widget.info, Node: Sexp Types, Next: Widget Properties, Prev: Basic Types, Up: Top
1007 A number of widgets for editing s-expressions (lisp types) are also
1008 available. These basically fall in the following categories.
1018 File: widget.info, Node: constants, Next: generic, Prev: Sexp Types, Up: Sexp Types
1020 The Constant Widgets.
1021 ---------------------
1023 The `const' widget can contain any lisp expression, but the user is
1024 prohibited from editing it, which is mainly useful as a component of one
1025 of the composite widgets.
1027 The syntax for the `const' widget is
1029 TYPE ::= (const [KEYWORD ARGUMENT]... [ VALUE ])
1031 The VALUE, if present, is used to initialize the `:value' property
1032 and can be any s-expression.
1035 This will display any valid s-expression in an immutable part of
1038 There are two variations of the `const' widget, namely
1039 `variable-item' and `function-item'. These should contain a symbol
1040 with a variable or function binding. The major difference from the
1041 `const' widget is that they will allow the user to see the variable or
1042 function documentation for the symbol.
1044 - Widget: variable-item
1045 An immutable symbol that is bound as a variable.
1047 - Widget: function-item
1048 An immutable symbol that is bound as a function.
1051 File: widget.info, Node: generic, Next: atoms, Prev: constants, Up: Sexp Types
1053 Generic Sexp Widget.
1054 --------------------
1056 The `sexp' widget can contain any lisp expression, and allows the user
1057 to edit it inline in the buffer.
1059 The syntax for the `sexp' widget is
1061 TYPE ::= (sexp [KEYWORD ARGUMENT]... [ VALUE ])
1064 This will allow you to edit any valid s-expression in an editable
1067 The `sexp' widget takes the same keyword arguments as the
1068 `editable-field' widget.
1071 File: widget.info, Node: atoms, Next: composite, Prev: generic, Up: Sexp Types
1073 Atomic Sexp Widgets.
1074 --------------------
1076 The atoms are s-expressions that does not consist of other
1077 s-expressions. A string is an atom, while a list is a composite type.
1078 You can edit the value of an atom with the following widgets.
1080 The syntax for all the atoms are
1082 TYPE ::= (NAME [KEYWORD ARGUMENT]... [ VALUE ])
1084 The VALUE, if present, is used to initialize the `:value' property
1085 and must be an expression of the same type as the widget. I.e. the
1086 string widget can only be initialized with a string.
1088 All the atom widgets take the same keyword arguments as the
1089 `editable-field' widget.
1092 Allows you to edit a string in an editable field.
1095 Allows you to edit a regular expression in an editable field.
1098 Allows you to enter a character in an editable field.
1101 Allows you to edit a file name in an editable field. If you invoke
1102 the tag button, you can edit the file name in the mini-buffer with
1107 If this is set to non-nil, only existing file names will be
1108 allowed in the minibuffer.
1111 Allows you to edit a directory name in an editable field. Similar
1112 to the `file' widget.
1115 Allows you to edit a lisp symbol in an editable field.
1118 Allows you to edit a lambda expression, or a function name with
1122 Allows you to edit a variable name, with completion.
1125 Allows you to edit an integer in an editable field.
1128 Allows you to edit a number in an editable field.
1131 Allows you to edit a boolean. In lisp this means a variable which
1132 is either nil meaning false, or non-nil meaning true.
1135 File: widget.info, Node: composite, Prev: atoms, Up: Sexp Types
1137 Composite Sexp Widgets.
1138 -----------------------
1140 The syntax for the composite are
1142 TYPE ::= (NAME [KEYWORD ARGUMENT]... COMPONENT...)
1144 Where each COMPONENT must be a widget type. Each component widget
1145 will be displayed in the buffer, and be editable to the user.
1148 The value of a `cons' widget is a cons-cell where the car is the
1149 value of the first component and the cdr is the value of the second
1150 component. There must be exactly two components.
1153 The value of a `list' widget is a list containing the value of
1154 each of its component.
1157 The value of a `vector' widget is a vector containing the value of
1158 each of its component.
1160 The above suffice for specifying fixed size lists and vectors. To
1161 get variable length lists and vectors, you can use a `choice', `set' or
1162 `repeat' widgets together with the `:inline' keywords. If any
1163 component of a composite widget has the `:inline' keyword set, its
1164 value must be a list which will then be spliced into the composite.
1165 For example, to specify a list whose first element must be a file name,
1166 and whose remaining arguments should either by the symbol `t' or two
1167 files, you can use the following widget specification:
1172 :value ("foo" "bar")
1175 The value of a widget of this type will either have the form `(file
1176 t)' or `(file string string)'.
1178 This concept of inline is probably hard to understand. It was
1179 certainly hard to implement so instead of confusing you more by trying
1180 to explain it here, I'll just suggest you meditate over it for a while.
1183 Allows you to edit a sexp which may have one of a fixed set of
1184 types. It is currently implemented with the `choice-menu' basic
1185 widget, and has a similar syntax.
1188 Allows you to specify a type which must be a list whose elements
1189 all belong to given set. The elements of the list is not
1190 significant. This is implemented on top of the `checklist' basic
1191 widget, and has a similar syntax.
1194 Allows you to specify a variable length list whose members are all
1195 of the same type. Implemented on top of the `editable-list' basic
1196 widget, and has a similar syntax.
1199 File: widget.info, Node: Widget Properties, Next: Defining New Widgets, Prev: Sexp Types, Up: Top
1204 You can examine or set the value of a widget by using the widget object
1205 that was returned by `widget-create'.
1207 - Function: widget-value widget
1208 Return the current value contained in WIDGET. It is an error to
1209 call this function on an uninitialized widget.
1211 - Function: widget-value-set widget value
1212 Set the value contained in WIDGET to VALUE. It is an error to
1213 call this function with an invalid VALUE.
1215 *Important:* You _must_ call `widget-setup' after modifying the
1216 value of a widget before the user is allowed to edit the widget again.
1217 It is enough to call `widget-setup' once if you modify multiple
1218 widgets. This is currently only necessary if the widget contains an
1219 editing field, but may be necessary for other widgets in the future.
1221 If your application needs to associate some information with the
1222 widget objects, for example a reference to the item being edited, it
1223 can be done with `widget-put' and `widget-get'. The property names
1224 must begin with a `:'.
1226 - Function: widget-put widget property value
1227 In WIDGET set PROPERTY to VALUE. PROPERTY should be a symbol,
1228 while VALUE can be anything.
1230 - Function: widget-get widget property
1231 In WIDGET return the value for PROPERTY. PROPERTY should be a
1232 symbol, the value is what was last set by `widget-put' for
1235 - Function: widget-member widget property
1236 Non-nil if WIDGET has a value (even nil) for property PROPERTY.
1238 Occasionally it can be useful to know which kind of widget you have,
1239 i.e. the name of the widget type you gave when the widget was created.
1241 - Function: widget-type widget
1242 Return the name of WIDGET, a symbol.
1244 Widgets can be in two states: active, which means they are
1245 modifiable by the user, or inactive, which means they cannot be
1246 modified by the user. You can query or set the state with the
1249 ;; Examine if WIDGET is active or not.
1250 (if (widget-apply WIDGET :active)
1251 (message "Widget is active.")
1252 (message "Widget is inactive.")
1254 ;; Make WIDGET inactive.
1255 (widget-apply WIDGET :deactivate)
1257 ;; Make WIDGET active.
1258 (widget-apply WIDGET :activate)
1260 A widget is inactive if itself or any of its ancestors (found by
1261 following the `:parent' link) have been deactivated. To make sure a
1262 widget is really active, you must therefore activate both itself and
1266 (widget-apply widget :activate)
1267 (setq widget (widget-get widget :parent)))
1269 You can check if a widget has been made inactive by examining the
1270 value of the `:inactive' keyword. If this is non-nil, the widget itself
1271 has been deactivated. This is different from using the `:active'
1272 keyword, in that the latter tells you if the widget *or* any of its
1273 ancestors have been deactivated. Do not attempt to set the `:inactive'
1274 keyword directly. Use the `:activate' `:deactivate' keywords instead.
1277 File: widget.info, Node: Defining New Widgets, Next: Widget Browser, Prev: Widget Properties, Up: Top
1279 Defining New Widgets
1280 ====================
1282 You can define specialized widgets with `define-widget'. It allows you
1283 to create a shorthand for more complex widgets. This includes
1284 specifying component widgets and new default values for the keyword
1287 - Function: define-widget name class doc &rest args
1288 Define a new widget type named NAME from `class'.
1290 NAME and class should both be symbols, `class' should be one of
1291 the existing widget types.
1293 The third argument DOC is a documentation string for the widget.
1295 After the new widget has been defined the following two calls will
1296 create identical widgets:
1298 * (widget-create NAME)
1300 * (apply widget-create CLASS ARGS)
1303 Using `define-widget' just stores the definition of the widget type
1304 in the `widget-type' property of NAME, which is what `widget-create'
1307 If you just want to specify defaults for keywords with no complex
1308 conversions, you can use `identity' as your `:convert-widget' function.
1310 The following additional keyword arguments are useful when defining
1313 Method to convert type-specific components of a widget type before
1314 instantiating a widget of that type. Not normally called from user
1315 code, it is invoked by `widget-convert'. Typical operations
1316 include converting types of child widgets to widget instances and
1317 converting values from external format (_i.e._, as expected by the
1318 calling code) to internal format (which is often different for the
1319 convenience of widget manipulation). It takes a widget type as an
1320 argument, and returns the converted widget type. When a widget is
1321 created, the value of this property is called for the widget type,
1322 then for all the widget's parent types, most derived first. (The
1323 property is reevaluated for each parent type.)
1325 The following predefined functions can be used here:
1327 - Function: widget-types-convert-widget widget
1328 Convert each member of `:args' in WIDGET from a widget type
1331 - Function: widget-value-convert-widget widget
1332 Initialize `:value' from `(car :args)' in WIDGET, and reset
1336 A method to implement deep copying of the type. Any member of the
1337 widget which might be changed in place (rather than replaced)
1338 should be copied by this method. (`widget-copy' uses
1339 `copy-sequence' to ensure that the top-level list is a copy.)
1340 This particularly applies to child widgets.
1342 `:value-to-internal'
1343 Function to convert the value to the internal format. The function
1344 takes two arguments, a widget and an external value. It returns
1345 the internal value. The function is called on the present `:value'
1346 when the widget is created, and on any value set later with
1349 `:value-to-external'
1350 Function to convert the value to the external format. The function
1351 takes two arguments, a widget and an internal value, and returns
1352 the internal value. The function is called on the present `:value'
1353 when the widget is created, and on any value set later with
1357 Function to create a widget from scratch. The function takes one
1358 argument, a widget, and inserts it in the buffer. Not normally
1359 called from user code. Instead, call `widget-create' or related
1360 functions, which take a type argument, (usually) convert it to a
1361 widget, call the `:create' function to insert it in the buffer,
1362 and then return the (possibly converted) widget.
1364 The default, `widget-default-create', is invariably appropriate.
1365 (None of the standard widgets specify `:create'.)
1368 Function to delete a widget. The function takes one argument, a
1369 widget, and should remove all traces of the widget from the buffer.
1372 Function to expand the `%v' escape in the format string. It will
1373 be called with the widget as its argument and should insert a
1374 representation of the widget's value in the buffer.
1377 Should remove the representation of the widget's value from the
1378 buffer. It will be called with the widget as its argument. It
1379 doesn't have to remove the text, but it should release markers and
1380 delete nested widgets if such have been used.
1382 The following predefined function can be used here:
1384 - Function: widget-children-value-delete widget
1385 Delete all `:children' and `:buttons' in WIDGET.
1388 Function to extract the value of a widget, as it is displayed in
1391 The following predefined function can be used here:
1393 - Function: widget-value-value-get widget
1394 Return the `:value' property of WIDGET.
1397 Function to handle unknown `%' escapes in the format string. It
1398 will be called with the widget and the escape character as
1399 arguments. You can set this to allow your widget to handle
1400 non-standard escapes.
1402 You should end up calling `widget-default-format-handler' to handle
1403 unknown escape sequences. It will handle the `%h' and any future
1404 escape sequences as well as give an error for unknown escapes.
1407 Function to handle user initiated events. By default, `:notify'
1408 the parent. Actions normally do not include mere edits, but refer
1409 to things like invoking buttons or hitting enter in an editable
1410 field. To watch for any change, redefine the `:notify' callback.
1412 The following predefined function can be used here:
1414 - Function: widget-parent-action widget &optional event
1415 Tell `:parent' of WIDGET to handle the `:action'.
1416 Optional EVENT is the event that triggered the action.
1419 Function to prompt for a value in the minibuffer. The function
1420 should take four arguments, WIDGET, PROMPT, VALUE, and UNBOUND and
1421 should return a value for widget entered by the user. PROMPT is
1422 the prompt to use. VALUE is the default value to use, unless
1423 UNBOUND is non-nil. In this case there is no default value. The
1424 function should read the value using the method most natural for
1425 this widget and does not have to check whether it matches.
1427 If you want to define a new widget from scratch, use the `default'
1431 Widget used as a base for other widgets.
1433 It provides most of the functionality that is referred to as "by
1434 default" in this text.
1436 In implementing complex hierarchical widgets (_e.g._, using the
1437 `group' widget), the following functions may be useful. The syntax for
1438 the TYPE arguments to these functions is described in *Note Basic
1441 - Function: widget-create-child-and-convert parent type &rest args
1442 As a child of PARENT, create a widget with type TYPE and value
1443 VALUE. TYPE is copied, and the `:widget-contvert' method is
1444 applied to the optional keyword arguments from ARGS.
1446 - Function: widget-create-child parent type
1447 As a child of PARENT, create a widget with type TYPE. TYPE is
1448 copied, but no conversion method is applied.
1450 - Function: widget-create-child-value parent type value
1451 As a child of PARENT, create a widget with type TYPE and value
1452 VALUE. TYPE is copied, but no conversion method is applied.
1454 - Function: widget-convert type &rest args
1455 Convert TYPE to a widget without inserting it in the buffer. The
1456 optional ARGS are additional keyword arguments.
1458 The widget's `:args' property is set from the longest tail of ARGS
1459 whose `cdr' is not a keyword, or if that is null, from the longest
1460 tail of TYPE's `:args' property whose cdr is not a keyword.
1461 Keyword arguments from ARGS are set, and the `:value' property (if
1462 any) is converted from external to internal format.
1464 `widget-convert' is typically not called from user code; rather it
1465 is called implicitly through the `widget-create*' functions.
1468 File: widget.info, Node: Widget Browser, Next: Widget Minor Mode, Prev: Defining New Widgets, Up: Top
1473 There is a separate package to browse widgets. This is intended to help
1474 programmers who want to examine the content of a widget. The browser
1475 shows the value of each keyword, but uses links for certain keywords
1476 such as `:parent', which avoids printing cyclic structures.
1478 - Command: widget-browse WIDGET
1479 Create a widget browser for WIDGET. When called interactively,
1482 - Command: widget-browse-other-window WIDGET
1483 Create a widget browser for WIDGET and show it in another window.
1484 When called interactively, prompt for WIDGET.
1486 - Command: widget-browse-at POS
1487 Create a widget browser for the widget at POS. When called
1488 interactively, use the position of point.
1491 File: widget.info, Node: Widget Minor Mode, Next: Utilities, Prev: Widget Browser, Up: Top
1496 There is a minor mode for manipulating widgets in major modes that
1497 doesn't provide any support for widgets themselves. This is mostly
1498 intended to be useful for programmers doing experiments.
1500 - Command: widget-minor-mode
1501 Toggle minor mode for traversing widgets. With arg, turn widget
1502 mode on if and only if arg is positive.
1504 - Variable: widget-minor-mode-keymap
1505 Keymap used in `widget-minor-mode'.
1508 File: widget.info, Node: Utilities, Next: Widget Wishlist, Prev: Widget Minor Mode, Up: Top
1513 - Function: widget-prompt-value widget prompt [ value unbound ]
1514 Prompt for a value matching WIDGET, using PROMPT.
1515 The current value is assumed to be VALUE, unless UNBOUND is
1518 - Function: widget-get-sibling widget
1519 Get the item WIDGET is assumed to toggle.
1520 This is only meaningful for radio buttons or checkboxes in a list.
1523 File: widget.info, Node: Widget Wishlist, Next: Widget Internals, Prev: Utilities, Up: Top
1528 * It should be possible to add or remove items from a list with `C-k'
1529 and `C-o' (suggested by RMS).
1531 * The `[INS]' and `[DEL]' buttons should be replaced by a single
1532 dash (`-'). The dash should be a button that, when invoked, ask
1533 whether you want to add or delete an item (RMS wanted to git rid of
1534 the ugly buttons, the dash is my idea).
1536 * The `menu-choice' tag should be prettier, something like the
1537 abbreviated menus in Open Look.
1539 * Finish `:tab-order'.
1541 * Make indentation work with glyphs and proportional fonts.
1543 * Add commands to show overview of object and class hierarchies to
1546 * Find a way to disable mouse highlight for inactive widgets.
1548 * Find a way to make glyphs look inactive.
1550 * Add `property-list' widget.
1552 * Add `association-list' widget.
1554 * Add `key-binding' widget.
1556 * Add `widget' widget for editing widget specifications.
1558 * Find clean way to implement variable length list. See
1559 `TeX-printer-list' for an explanation.
1561 * `C-h' in `widget-prompt-value' should give type specific help.
1565 * `C-e e' in a fixed size field should go to the end of the text in
1566 the field, not the end of the field itself.
1568 * Use an overlay instead of markers to delimit the widget. Create
1569 accessors for the end points.
1571 * Clicking on documentation links should call `describe-function' or
1572 `widget-browse-other-window' and friends directly, instead of going
1573 through `apropos'. If more than one function is valid for the
1574 symbol, it should pop up a menu.
1578 File: widget.info, Node: Widget Internals, Prev: Widget Wishlist, Up: Top
1583 This (very brief!) section provides a few notes on the internal
1584 structure and implementation of Emacs widgets. Avoid relying on this
1585 information. (We intend to improve it, but this will take some time.)
1586 To the extent that it actually describes APIs, the information will be
1587 moved to appropriate sections of the manual in due course.
1589 The "Widget" and "Type" Structures
1590 ----------------------------------
1592 Widgets and types are currently both implemented as lists.
1594 A symbol may be defined as a "type name" using `define-widget'.
1595 *Note Defining New Widgets::. A "type" is a list whose car is a
1596 previously defined type name, nil, or (recursively) a type. The car is
1597 the "class" or parent type of the type, and properties which are not
1598 specified in the new type will be inherited from ancestors. Probably
1599 the only type without a class should be the `default' type. The cdr of
1600 a type is a plist whose keys are widget property keywords.
1602 A type or type name may also be referred to as an "unconverted
1605 A "converted widget" or "widget instance" is a list whose car is a
1606 type name or a type, and whose cdr is a property list. Furthermore,
1607 all children of the converted widget must be converted. Finally, in the
1608 process of appropriate parts of the list structure are copied to ensure
1609 that changes in values of one instance do not affect another's.
1615 Node: Introduction
\7f612
1616 Node: User Interface
\7f4087
1617 Node: Programming Example
\7f8976
1618 Node: Setting Up the Buffer
\7f13123
1619 Node: Basic Types
\7f14837
1621 Node: url-link
\7f21553
1622 Node: info-link
\7f21862
1623 Node: push-button
\7f22150
1624 Node: editable-field
\7f22720
1626 Node: menu-choice
\7f24495
1627 Node: radio-button-choice
\7f25345
1629 Node: choice-item
\7f27294
1630 Node: toggle
\7f27789
1631 Node: checkbox
\7f28523
1632 Node: checklist
\7f28826
1633 Node: editable-list
\7f30267
1635 Node: Sexp Types
\7f31733
1636 Node: constants
\7f32043
1637 Node: generic
\7f33114
1639 Node: composite
\7f35588
1640 Node: Widget Properties
\7f38055
1641 Node: Defining New Widgets
\7f41117
1642 Node: Widget Browser
\7f49281
1643 Node: Widget Minor Mode
\7f50136
1644 Node: Utilities
\7f50690
1645 Node: Widget Wishlist
\7f51171
1646 Node: Widget Internals
\7f52892