aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Aranda2023-09-02 07:55:12 -0300
committerEli Zaretskii2023-09-02 14:25:04 +0300
commit71a85e226687c3150179ca36ecd67ea2bb0cfd13 (patch)
tree4249c015f6951c9ef6f427785c66d2fe71681459
parent2137fdfd55006598da70807361ac7b4b8e44ad22 (diff)
downloademacs-71a85e226687c3150179ca36ecd67ea2bb0cfd13.tar.gz
emacs-71a85e226687c3150179ca36ecd67ea2bb0cfd13.zip
A revision to the Widget manual
* doc/misc/widget.texi (Widgets Basics, Working with Widgets) (Widgets and the Buffer, Widget Gallery, Customization): New chapters. (Basic Types, Sexp Types): Demote to subsections. (Widget Browser): Rename to Inspecting Widgets. (Widget Properties): Remove. (Top): Adapt menu to changes. (Introduction): Rearrange text. Move warnings to a better place, and user options to the Customization chapter. (User Interface): Don't fully describe commands and customization options here. (Setting Up the Buffer): Expand on widget creation process and add documentation for useful functions which deal with creation/conversion. (Defining New Widgets): Expand the documentation on define-widget. All relevant properties moved to the description of the default widget, in Widget Gallery. (Utilities): Add some more useful functions not previously documented. (Wishlist): Remove out-of-date items.
-rw-r--r--doc/misc/widget.texi2467
1 files changed, 1914 insertions, 553 deletions
diff --git a/doc/misc/widget.texi b/doc/misc/widget.texi
index 13b37ab5b54..eb411f29c5c 100644
--- a/doc/misc/widget.texi
+++ b/doc/misc/widget.texi
@@ -49,14 +49,16 @@ modify this GNU manual.''
49* Introduction:: 49* Introduction::
50* User Interface:: 50* User Interface::
51* Programming Example:: 51* Programming Example::
52* Widgets Basics::
52* Setting Up the Buffer:: 53* Setting Up the Buffer::
53* Basic Types:: 54* Working with Widgets::
54* Sexp Types:: 55* Widgets and the Buffer::
55* Widget Properties:: 56* Widget Gallery::
56* Defining New Widgets:: 57* Defining New Widgets::
57* Widget Browser:: 58* Inspecting Widgets::
58* Widget Minor Mode:: 59* Widget Minor Mode::
59* Utilities:: 60* Utilities::
61* Customization::
60* Widget Wishlist:: 62* Widget Wishlist::
61* GNU Free Documentation License:: 63* GNU Free Documentation License::
62* Index:: 64* Index::
@@ -68,7 +70,7 @@ modify this GNU manual.''
68Most graphical user interface toolkits provide a number of standard 70Most graphical user interface toolkits provide a number of standard
69user interface controls (sometimes known as ``widgets'' or ``gadgets''). 71user interface controls (sometimes known as ``widgets'' or ``gadgets'').
70Emacs doesn't really support anything like this, except for an 72Emacs doesn't really support anything like this, except for an
71incredibly powerful text ``widget.'' On the other hand, Emacs does 73incredibly powerful text ``widget''. On the other hand, Emacs does
72provide the necessary primitives to implement many other widgets 74provide the necessary primitives to implement many other widgets
73within a text buffer. The @code{widget} package simplifies this task. 75within a text buffer. The @code{widget} package simplifies this task.
74 76
@@ -85,13 +87,13 @@ Like link, but intended for stand-alone buttons.
85@item editable-field 87@item editable-field
86An editable text field. It can be either variable or fixed length. 88An editable text field. It can be either variable or fixed length.
87@item menu-choice 89@item menu-choice
88Allows the user to choose one of multiple options from a menu, each 90Allows the user to choose one of multiple options from a menu, where
89option is itself a widget. Only the selected option will be visible in 91each option is itself a widget. Only the selected option is visible
90the buffer. 92in the buffer.
91@item radio-button-choice 93@item radio-button-choice
92Allows the user to choose one of multiple options by activating radio 94Allows the user to choose one of multiple options by activating radio
93buttons. The options are implemented as widgets. All options will be 95buttons. The options are implemented as widgets. All options are
94visible in the buffer. 96visible in the buffer, with the selected one marked as chosen.
95@item item 97@item item
96A simple constant widget intended to be used in the @code{menu-choice} and 98A simple constant widget intended to be used in the @code{menu-choice} and
97@code{radio-button-choice} widgets. 99@code{radio-button-choice} widgets.
@@ -137,9 +139,9 @@ Editing happens in the buffer, not in the mini-buffer.
137Packages using the library get a uniform look, making them easier for 139Packages using the library get a uniform look, making them easier for
138the user to learn. 140the user to learn.
139@item 141@item
140As support for embedded graphics improve, the widget library will be 142As support for embedded graphics improve, the Widget library will be
141extended to use the GUI features. This means that your code using the 143extended to use the GUI features. This means that your code using the
142widget library will also use the new graphic features automatically. 144Widget library will also use the new graphic features automatically.
143@end enumerate 145@end enumerate
144 146
145@node User Interface 147@node User Interface
@@ -201,12 +203,6 @@ middle of another field is prohibited.
201 203
202Editable text fields are created by the @code{editable-field} widget. 204Editable text fields are created by the @code{editable-field} widget.
203 205
204@strong{Warning:} In an @code{editable-field} widget, the editable
205field must not be adjacent to another widget---that won't work.
206You must put some text in between. Either make this text part of
207the @code{editable-field} widget itself, or insert it with
208@code{widget-insert}.
209
210The @code{:format} keyword is useful for generating the necessary 206The @code{:format} keyword is useful for generating the necessary
211text; for instance, if you give it a value of @code{"Name: %v "}, 207text; for instance, if you give it a value of @code{"Name: %v "},
212the @samp{Name: } part will provide the necessary separating text 208the @samp{Name: } part will provide the necessary separating text
@@ -215,17 +211,9 @@ separating text after the field. If you don't include the
215@code{:size} keyword, the field will extend to the end of the 211@code{:size} keyword, the field will extend to the end of the
216line, and the terminating newline will provide separation after. 212line, and the terminating newline will provide separation after.
217 213
218@strong{Warning:} In an @code{editable-field} widget, the @samp{%v} escape
219must be preceded by some other text in the @code{:format} string
220(if specified).
221
222The editing text fields are highlighted with the 214The editing text fields are highlighted with the
223@code{widget-field-face} face, making them easy to find. 215@code{widget-field-face} face, making them easy to find.
224 216
225@deffn Face widget-field-face
226Face used for other editing fields.
227@end deffn
228
229@section Buttons 217@section Buttons
230 218
231@cindex widget buttons 219@cindex widget buttons
@@ -233,24 +221,9 @@ Face used for other editing fields.
233Some portions of the buffer have an associated @dfn{action}, which can 221Some portions of the buffer have an associated @dfn{action}, which can
234be @dfn{invoked} by a standard key or mouse command. These portions 222be @dfn{invoked} by a standard key or mouse command. These portions
235are called @dfn{buttons}. The default commands for activating a button 223are called @dfn{buttons}. The default commands for activating a button
236are: 224are @code{widget-button-press} and @code{widget-button-click}. The
237 225user typically interacts with the buttons with a key, like @key{RET},
238@table @kbd 226or with the mouse buttons.
239@item @key{RET}
240@deffn Command widget-button-press @var{pos} &optional @var{event}
241Invoke the button at @var{pos}, defaulting to point.
242If point is not located on a button, invoke the binding in
243@code{widget-global-map} (by default the global map).
244@end deffn
245
246@kindex mouse-2 @r{(on button widgets})
247@item mouse-2
248@deffn Command widget-button-click @var{event}
249Invoke the button at the location of the mouse pointer. If the mouse
250pointer is located in an editable text field, invoke the binding in
251@code{widget-global-map} (by default the global map).
252@end deffn
253@end table
254 227
255There are several different kind of buttons, all of which are present in 228There are several different kind of buttons, all of which are present in
256the example: 229the example:
@@ -286,33 +259,15 @@ main difference from the @code{link} widget is that the buttons will be
286displayed as GUI buttons when possible. 259displayed as GUI buttons when possible.
287@end table 260@end table
288 261
289To make them easier to locate, buttons are emphasized in the buffer. 262To make them easier to locate, buttons are emphasized in the buffer
290 263with a distinctive face, like @code{widget-button-face} or
291@deffn Face widget-button-face 264@code{widget-mouse-face}.
292Face used for buttons.
293@end deffn
294
295@defopt widget-mouse-face
296Face used for highlighting a button when the mouse pointer moves across
297it.
298@end defopt
299 265
300@section Navigation 266@section Navigation
301 267
302You can use all the normal Emacs commands to move around in a form 268You can use all the normal Emacs commands to move around in a form
303buffer, plus you will have these additional commands: 269buffer, plus you will have these additional commands to navigate from
304 270widget to widget: @code{widget-forward} and @code{widget-backward}.
305@table @kbd
306@item @key{TAB}
307@deffn Command widget-forward &optional count
308Move point @var{count} buttons or editing fields forward.
309@end deffn
310@item @kbd{M-@key{TAB}}
311@itemx @kbd{S-@key{TAB}}
312@deffn Command widget-backward &optional count
313Move point @var{count} buttons or editing fields backward.
314@end deffn
315@end table
316 271
317@node Programming Example 272@node Programming Example
318@chapter Programming Example 273@chapter Programming Example
@@ -414,85 +369,598 @@ Interface}).
414 (widget-setup)) 369 (widget-setup))
415@end lisp 370@end lisp
416 371
372@node Widgets Basics
373@chapter Widgets Basics
374@cindex widget object
375The Widget Library deals with widgets objects. A widget object has
376properties whose value may be anything, be it numbers, strings,
377symbols, functions, etc. Those properties are referred to as keywords
378and are responsible for the way a widget is represented in a buffer,
379and control the way a user or a program can interact with it.
380
381@cindex widget inheritance
382The library defines several widget types, and gives you a way to
383define new types as well. In addition, widgets can derive from other
384types, creating a sort of widget inheritance. In fact, all widgets
385defined in the Widget Library share a common parent, the @dfn{default}
386widget. In this manual, when we talk about a default behavior, we
387usually mean the behavior as defined by this @code{default} widget.
388@xref{Widget Gallery}, for a description of each defined widget.
389
390Defining a new type that derives from a previous one is not mandatory
391to create widgets that work very different from a specified type.
392When creating a widget, you can override any default property,
393including functions, that control the widget. That is, you can
394specialize a widget on creation, without having to define it as a new
395type of widget.
396
397In addition to the function for defining a widget, this library
398provides functions to create widgets, query and change its properties,
399respond to user events and destroy them. The following sections
400describe them.
401
402@cindex widget value
403One important property of a widget is its @dfn{value}. All widgets
404may have a value, which is stored in a so-called @dfn{internal format}.
405For the rest of Emacs, the widget presents its value in a so-called
406@dfn{external format}. Both formats can be equal or different, and
407each widget is responsible for defining how the conversion between
408each format should happen.
409
410@c FIXME: Briefly describe inline widgets?
411@c The inline concept is described elsewhere, and it's difficult to
412@c describe.
413
414The value property is an important property for almost all widgets,
415and perhaps more important for @code{editable-field} widgets. This
416type of widgets allow the user to edit them via the usual editing
417commands in Emacs. They can also be edited programmatically.
418@strong{Important:} You @emph{must} call @code{widget-setup} after
419modifying the value of a widget before the user is allowed to edit the
420widget again. It is enough to call @code{widget-setup} once if you
421modify multiple widgets. This is currently only necessary if the widget
422contains an editing field, but may be necessary for other widgets in the
423future.
424
425@cindex widget properties
426If your application needs to associate some information with the widget
427objects, for example a reference to the item being edited, it can be
428done with the @code{widget-put} and @code{widget-get} functions. The
429property names, as shown, are keywords, so they must begin with a
430@samp{:}.
431
417@node Setting Up the Buffer 432@node Setting Up the Buffer
418@chapter Setting Up the Buffer 433@chapter Setting Up the Buffer
434@cindex widget creation, widget conversion
435To show the widgets in a buffer, you have to create them. Widget
436creation is actually a two-step process: conversion and creation per
437se. With simple projects, usually the conversion step isn't really
438important, and you only care about widget creation, so feel free to
439skip the conversion description until you really need to know it.
440
441Widget conversion is the process that involves taking a widget
442specification and transforming it into a @dfn{widget} object, suitable
443to be created, queried and manipulated with other widget functions.
444Widget creation is the process that takes a widget object and actually
445inserts it in the buffer.
446
447The simplest function to create a widget is @code{widget-create}, which
448gets a widget specification and returns a widget object.
449
450@defun widget-create type [ keyword argument ]@dots{} args
451Create and return a widget of type @var{type}, converting it.
452
453@var{type} is a symbol that specifies a widget type. @var{keyword}
454may be one of the properties supported by the widget type, and
455@var{argument} specify the value for that property. These keyword
456arguments can be used to overwrite the keyword arguments that are part
457of @var{type} by default, as well as to provide other properties not
458present in @var{type} by default. @var{args} holds additional
459information for the creation of @var{type} and each widget type is
460responsible for handling that information in a specific way.
461
462The syntax for the @var{type} argument is described in @ref{Widget
463Gallery}, and in more detail in every widget where it's relevant.
464@end defun
419 465
420Widgets are created with @code{widget-create}, which returns a 466There are other functions for creating widgets, useful when you work
421@dfn{widget} object. This object can be queried and manipulated by 467with composite widgets. That is, widgets that are part of other
422other widget functions, until it is deleted with @code{widget-delete}. 468widgets.
423After the widgets have been created, @code{widget-setup} must be called
424to enable them.
425 469
426@defun widget-create type [ keyword argument ]@dots{} 470@defun widget-create-child-and-convert parent type &rest args
427Create and return a widget of type @var{type}. 471Create a widget of type @var{type} as a child of @var{parent}.
428The syntax for the @var{type} argument is described in @ref{Basic Types}.
429 472
430The keyword arguments can be used to overwrite the keyword arguments 473Before creating it, converts @var{type} using the keyword arguments
431that are part of @var{type}. 474provided in @var{args}.
475@c FIXME: Is this description useful?
476Adds the @code{:indent} property, unless it is already present, and
477sets it to the sum of the values of: @code{:indent} and @code{:offset}
478from @var{parent} and @code{:extra-offset} from @var{type}.
479
480Returns a widget object, with the property @code{:parent} set to
481@var{PARENT}.
432@end defun 482@end defun
433 483
434@defun widget-delete widget 484@defun widget-create-child parent type
435Delete @var{widget} and remove it from the buffer. 485Create a widget of type @var{type} as a child of @var{parent}.
486
487This function is like @code{widget-create-child-and-convert} but it
488doesn't convert @var{type}, so it expects an already converted widget.
489@end defun
490
491@defun widget-create-child-value parent type value
492Create a widget of type @var{type} as a child of @var{parent} with
493value @var{value}.
494
495This function is like @code{widget-create-child}, but it lets you
496specify a value for the widget.
497
498Converts @var{value} to the internal format, as specified by
499@var{type}, and stores it into the @code{:value} property of @var{type}.
500That means, @var{value} should be in the external format, as
501specified by @var{type}.
436@end defun 502@end defun
437 503
504All these creating functions described here use the function stored in
505the @code{:create} property. So, to modify the creation logic for a
506widget, you can provide a different @code{:create} function.
507
508When you're done creating widgets and you're ready for the user to
509interact with the buffer, use the function @code{widget-setup}.
510
438@defun widget-setup 511@defun widget-setup
439Set up a buffer to support widgets. 512Setup the current buffer, so that editable widgets can be edited.
440 513
441This should be called after creating all the widgets and before allowing 514This should be called after creating all the widgets and before allowing
442the user to edit them. 515the user to edit them.
443@end defun 516@end defun
444 517
445If you want to insert text outside the widgets in the form, the 518As mentioned, all these functions return a widget object. That widget
446recommended way to do that is with @code{widget-insert}. 519object can be queried and manipulated with widget functions that
520take widgets as arguments, until deleting it with the widgets
521functions available to delete widgets. Even if you don't save the
522returned widget object, you still can interact programmatically with
523the widget. @xref{Working with Widgets}.
447 524
448@defun widget-insert 525@defun widget-delete widget
449Insert the arguments, either strings or characters, at point. 526Delete the widget @var{widget} and remove it from the buffer.
450The inserted text will be read-only.
451@end defun 527@end defun
452 528
453There is a standard widget keymap which you might find useful. 529@defun widget-children-value-delete widget
530Delete all children and buttons in widget @var{widget}.
454 531
455@findex widget-button-press 532This function does not delete @var{widget} itself, only the widgets
456@findex widget-button-click 533stored in the @code{:children} and @code{:buttons} properties. It
534also sets those properties to @code{nil}.
535@end defun
536
537As with the creation mechanism, the function stored in @code{:delete}
538controls the deletion mechanism for a widget.
539
540Additionally, the library provides a way to make a copy of a widget.
541
542@defun widget-copy widget
543Makes a copy of widget @var{widget} and returns it.
544
545It uses the function stored in the @code{:copy} property of @var{widget}
546and returns the widget that that function returns.
547@end defun
548
549As discussed, there is a conversion step when creating a widget. To
550do the conversion without actually creating the widget, you can use
551the @code{widget-convert} function.
552
553@defun widget-convert type &rest args
554Convert @var{type} to a widget object, using keyword arguments @var{args}.
555
556Returns a widget object, suitable for creation. It calls the function
557stored in the @code{:convert-widget} property, after putting into the
558@code{:args} property the arguments that the widget in question needs.
559If @var{type} has a @code{:value} property, either originally or after
560doing the conversion, this function converts the value stored in
561@code{:value} to the internal format, and stores it into @code{:value}.
562@end defun
563
564Apart from only creating widgets in the buffer, It's useful to have
565plain text. For inserting text, the recommended way is with the
566@code{widget-insert} function.
567
568@defun widget-insert &rest args
569Insert @var{args}, either strings or characters, at point.
570
571Uses @code{insert} to perform the insertion, passing @var{args} as
572argument. @xref{Insertion,,,elisp, the Emacs Lisp Reference Manual},
573for more information about @var{args}.
574
575The resulting text will be read-only.
576@end defun
577
578@node Working with Widgets
579@chapter Working with Widgets
580This section covers the more important functions needed to query and
581manipulate widgets in a generic way. Widgets may have additional
582functions for interacting with them, those are described in the
583description for each widget. @xref{Widget Gallery}.
584
585@defun widgetp widget
586Non-@code{nil} if @var{widget} is a widget.
587@end defun
588
589@defun widget-type widget
590Return the type of widget @var{widget}, a symbol.
591
592This function is useful to find out which kind of widget @var{widget}
593represents, i.e., the name of the widget type when the widget
594was created.
595@end defun
596
597@defun widget-member widget property
598Non-@code{nil} if widget @var{widget} has a value (even @code{nil}) for
599property @var{property}.
600@end defun
601
602@defun widget-get widget property
603For widget @var{widget}, return the value of the property @var{property}.
604
605@var{property} should be a keyword, and the value is what was last set by
606@code{widget-put} for @var{property}.
607@end defun
608
609@defun widget-put widget property value
610For widget @var{widget}, set the property @var{property} to @var{value}.
611@var{property} should be a keyword, while @var{value} can be anything.
612@end defun
613
614@defun widget-at &optional pos
615Return the widget at position @var{pos}, or at point if @var{pos} is @code{nil}.
616@end defun
617
618@defun widget-field-at pos
619Return the widget field at position POS, or @code{nil} if there is none.
620@end defun
621
622@defun widget-apply widget property &rest args
623Apply the function stored in @var{property} to @var{widget}, passing @var{args}
624as additional arguments to the function.
625
626Returns the result of that function call.
627@end defun
628
629@defun widget-value widget
630Return the current value contained in @var{widget}.
631
632Note that the value returned by this function might differ from what's
633stored in the @code{:value} property of @var{widget}. This is because
634this function extracts the current value of @var{widget} from the
635buffer, taking editions into account.
636
637The value returned is in the external format, after getting it with
638the @code{:value-get} function.
639
640It is an error to call this function on an uninitialized widget.
641@end defun
642
643@defun widget-value-set widget value
644Set the value contained in @var{widget} to @var{value}.
645
646Converts @var{value} to the internal format, and then sets it by
647applying the @code{:value-set} function.
648
649It is an error to call this function with an invalid @var{value}, that
650is, a value that @var{widget} cannot represent.
651@end defun
652
653@defun widget-default-get widget
654Return the default external value of widget @var{widget}.
655
656The default value is the one stored in @code{:value} or the result of
657applying the @code{:default-get} function to the arguments of
658@var{widget}, as stored in @code{:args}. A value of @code{nil} is
659ignored by default, so in order for a widget to respect @code{nil} as
660a value, it has to override the @code{:default-get} function.
661@end defun
662
663@defun widget-type-default-get widget
664Convert the @code{:type} attribute in @var{widget} and return its
665default value.
666@end defun
667
668@defun widget-child-value-get widget
669Return the value of the first member of @code{:children} in
670@var{widget}.
671@end defun
672
673@defun widget-child-value-inline widget
674Return the inline value of the first member of @code{:children} in
675@var{widget}.
676
677The inline value is whatever the function stored in
678@code{:value-inline} returns.
679@end defun
680
681@defun widget-type-value-create widget
682Create a child widget for @var{widget}, of type stored in
683@code{:type}.
684
685Creates the child widget taking the value from the @code{:value}
686property and stores the newly created widget in the @code{:children}
687property of @var{widget}.
688
689The value stored in @code{:type} should be an unconverted widget
690type.
691@end defun
692
693@defun widget-value-convert-widget widget
694Initializes the @code{:value} property of @var{widget} from
695@code{:args}.
696
697Sets @code{:args} to @code{nil} and returns the modified widget
698@var{widget}.
699@end defun
700
701@defun widget-value-value-get widget
702Return the value stored in @code{:value} for widget @var{widget}.
703
704This is different to getting the current value for @var{widget} with
705@code{widget-value}, since that function extracts the value from the
706buffer.
707@end defun
708
709@defun widget-apply-action widget &optional event
710Apply the function stored in @code{:action} to @var{widget}, in
711response to @var{event}.
712
713It is an error to call this function with an inactive widget.
714@end defun
715
716@defun widget-parent-action widget &optional event
717Tell @code{:parent} of @var{widget} to handle @var{event}.
718
719Optional @var{event} is the event that triggered the action.
720@end defun
721
722@defun widget-child-validate widget
723Check that the first member of @code{:children} in @var{widget} is valid.
724
725To be valid means that the widget value passes the checks that the
726function stored in @code{:validate} makes.
727@end defun
728
729@defun widget-children-validate widget
730Check that all @code{:children} in @var{widget} are valid.
731
732Returns @code{nil} on success, or the first child that isn't valid.
733@end defun
734
735@defun widget-type-match widget value
736Return non-@code{nil} if @var{VALUE} matches the value for the
737@code{:type} widget.
738
739As with the other type functions, the widget stored in @code{:type}
740should be an unconverted widget.
741@end defun
742
743@defun widget-types-copy widget
744Copy the @code{:args} value in @var{widget} and store them in @code{:args}.
745
746Makes the copies by calling @code{widget-copy} on each element present
747in @code{:args}. Returns the modified widget @var{widget}.
748@end defun
749
750@defun widget-types-convert-widget widget
751Convert the @code{:args} value in @var{widget} and store them in
752@code{args}.
753
754Returns the modified widget @var{widget}.
755@end defun
756
757@node Widgets and the Buffer
758@chapter Widgets and the Buffer
759This chapter describes commands that are specific to buffers that
760contain widgets.
761
762@cindex widget keybindings
457@defvr Const widget-keymap 763@defvr Const widget-keymap
458@key{TAB} and @kbd{C-@key{TAB}} are bound to @code{widget-forward} and 764Keymap containing useful bindings for buffers containing widgets.
459@code{widget-backward}, respectively. @key{RET} and @kbd{mouse-2} 765
460are bound to @code{widget-button-press} and 766Binds @key{TAB} and @kbd{C-@key{TAB}} to @code{widget-forward} and
461@code{widget-button-click}. 767@code{widget-backward}, respectively. It also binds @key{RET} to
768@code{widget-button-press} and @kbd{down-mouse-1} and
769@kbd{down-mouse-2} to @code{widget-button-click}.
462@end defvr 770@end defvr
463 771
772There's also a keymap for events that the Widget library doesn't need
773to handle.
774
464@defvar widget-global-map 775@defvar widget-global-map
465Keymap used by @code{widget-button-press} and @code{widget-button-click} 776Keymap used by @code{widget-button-press} and @code{widget-button-click}
466when not on a button. By default this is @code{global-map}. 777when not on a button. By default this is @code{global-map}.
467@end defvar 778@end defvar
468 779
469@node Basic Types 780In addition to these two keymaps, each widget might define a keymap of
470@chapter Basic Types 781its own, active when events happen at that widget.
782
783@cindex widget navigation
784The following navigation commands are available:
785
786@table @kbd
787@item @key{TAB}
788@deffn Command widget-forward &optional count
789Move point @var{count} buttons or editing fields forward.
790@end deffn
791@item @kbd{M-@key{TAB}}
792@itemx @kbd{S-@key{TAB}}
793@deffn Command widget-backward &optional count
794Move point @var{count} buttons or editing fields backward.
795@end deffn
796@end table
797
798
799When editing an @code{editable-field} widget, the following commands
800are available:
471 801
472This is the general syntax of a type specification: 802@table @kbd
803@item @key{C-e}
804@deffn Command widget-end-of-line
805Move point to the end of field or end of line, whichever is first.
806@end deffn
807
808@item @kbd{C-k}
809@deffn Command widget-kill-line
810Kill to end of field or end of line, whichever is first.
811@end deffn
812
813@item @kbd{M-TAB}
814@deffn Command widget-complete
815Complete the content of the editable field at point.
816@end deffn
817
818@item @kbd{C-m}
819@deffn Command widget-field-activate
820Invoke the editable field at point.
821@end deffn
822@end table
473 823
824The following two are commands that can execute widget actions.
825@table @kbd
826@item @key{RET}
827@findex widget-button-press
828@deffn Command widget-button-press @var{pos} &optional @var{event}
829Invoke the button at @var{pos}, defaulting to point.
830
831Invocation means to run the function stored in the @code{:action}
832property.
833
834If point is not located on a button, invoke the binding in
835@code{widget-global-map} (by default the global map).
836@end deffn
837
838@kindex mouse-2 @r{(on button widgets})
839@item mouse-2
840@findex widget-button-click
841@deffn Command widget-button-click @var{event}
842Invoke the button at the location of the mouse pointer.
843
844If the mouse pointer is located in an editable text field, invoke the
845binding in @code{widget-global-map} (by default the global map).
846
847In case the mouse-click is on a widget, calls the function stored in
848the @code{:mouse-down-action} property.
849@end deffn
850@end table
851
852@node Widget Gallery
853@chapter Widget Gallery
854@cindex widget syntax
855All widgets can be created from a type specification. The general
856syntax of a type specification is:
857
858@c FIXME: Add BNF reference here? If yes, what reference?
474@example 859@example
475@var{name} ::= (@var{name} [@var{keyword} @var{argument}]... @var{args}) 860@var{name} ::= (@var{name} [@var{keyword} @var{argument}]... @var{args})
476 | @var{name} 861 | @var{name}
477@end example 862@end example
478 863
479Where, @var{name} is a widget name, @var{keyword} is the name of a 864Where @var{name} is a widget name, as defined with
480property, @var{argument} is the value of the property, and @var{args} 865@code{define-widget}, @var{keyword} is the name of a property and
481are interpreted in a widget specific way. 866@var{argument} is the value for that property, and @var{args} are
867interpreted in a widget specific way. @xref{Defining New Widgets}.
868
869@menu
870* Basic Types::
871* Sexp Types::
872@end menu
873
874@node Basic Types
875@section Basic Types
876
877@menu
878* default::
879* item::
880* link::
881* url-link::
882* info-link::
883* function-link::
884* variable-link::
885* face-link::
886* file-link::
887* emacs-library-link::
888* emacs-commentary-link::
889* push-button::
890* editable-field::
891* text::
892* menu-choice::
893* radio-button-choice::
894* choice-item::
895* toggle::
896* radio-button-toggle::
897* checkbox::
898* checklist::
899* editable-list::
900* group::
901* documentation-string::
902@end menu
903
904@node default
905@subsection The @code{default} Widget
906@findex default@r{ widget}
907The most basic widget in the Widget Library is the @dfn{default}
908widget. It provides the basic behavior for all other widgets, and all
909its properties are present by default in derived widgets. You're
910seldom (if ever) going to effectively create a default widget, but
911here we describe its properties and behavior, so that we can describe
912other widgets only by mentioning the properties and behavior those
913other widgets specialize.
914
915@deffn Widget default
916Widget used as a base for other widgets.
917
918It provides most of the functionality that is referred to as ``by
919default'' in this text. If you want to define a new widget from
920scratch, use the @code{default} widget as its base.
921@end deffn
482 922
483@cindex keyword arguments 923@cindex keyword arguments
484The following keyword arguments apply to all widgets: 924The following keyword arguments apply to all widgets:
485 925
486@table @code 926@table @code
927@vindex create@r{ keyword}
928@item :create
929Function to create a widget from scratch.
930
931The function takes one argument, a widget type, and creates a widget
932of that type, inserts it in the buffer, and returns a widget object.
933
934By default, it inserts the widget at point, using the format provided
935in the @code{:format} property.
936
937@vindex delete@r{ keyword}
938@item :delete
939Function to delete a widget.
940
941The function should take one argument, a widget, and should remove all
942traces of the widget from the buffer.
943
944The default value is:
945
946@defun widget-default-delete widget
947Remove @var{widget} from the buffer.
948Delete all @code{:children} and @code{:buttons} in @var{widget}.
949@end defun
950
951In most cases you should not change this value, but instead use
952@code{:value-delete} to make any additional cleanup.
953
487@cindex internal format 954@cindex internal format
488@cindex external format 955@cindex external format
489@vindex value@r{ keyword} 956@vindex value@r{ keyword}
490@item :value 957@item :value
491The initial value for widgets of this type. Typically, a widget 958The initial value for widgets of this type.
492represents its value in two formats: external and internal. The 959
493external format is the value as the rest of Emacs sees it, and the 960Typically, a widget represents its value in two formats: external and
494internal format is a representation that the widget defines and uses 961internal. The external format is the value as the rest of Emacs sees
495in a widget specific way. 962it, and the internal format is a representation that the widget
963defines and uses in a widget specific way.
496 964
497Both formats might be the same for certain widgets and might differ 965Both formats might be the same for certain widgets and might differ
498for others, and there is no guarantee about which format the value 966for others, and there is no guarantee about which format the value
@@ -500,6 +968,68 @@ stored in the @code{:value} property has. However, when creating a
500widget or defining a new one (@pxref{Defining New Widgets}), the 968widget or defining a new one (@pxref{Defining New Widgets}), the
501@code{:value} should be in the external format. 969@code{:value} should be in the external format.
502 970
971@vindex value-to-internal@r{ keyword}
972@item :value-to-internal
973Function to convert the value to the internal format.
974
975The function takes two arguments, a widget and an external value, and
976returns the internal value. The function is called on the present
977@code{:value} when the widget is created, and on any value set later
978with @code{widget-value-set}.
979
980@vindex value-to-external@r{ keyword}
981@item :value-to-external
982Function to convert the value to the external format.
983
984The function takes two arguments, a widget and an internal value, and
985returns the value in the external format.
986
987@vindex value-create@r{ keyword}
988@item :value-create
989Function to expand the @samp{%v} escape in the format string.
990
991It will be called with the widget as its argument and should insert a
992representation of the widget's value in the buffer.
993
994@vindex value-delete@r{ keyword}
995@item :value-delete
996A function that should remove the representation of the widget's value
997from the buffer.
998
999It will be called with the widget as its argument. It doesn't have to
1000remove the text, but it should release markers and delete nested widgets
1001if these are not listed in @code{:children} or @code{:buttons}.
1002
1003By default, it's a no-op.
1004
1005@vindex value-get@r{ keyword}
1006@item :value-get
1007Function to extract the value of a widget, as it is displayed in the
1008buffer.
1009
1010@vindex value-set@r{ keyword}
1011@item :value-set
1012Function that takes a widget and a value as arguments, and recreates
1013it.
1014
1015The value must already be in the internal format for widget. By
1016default, it deletes the widget with the @code{:delete} function and
1017creates it again with the @code{:create} function.
1018
1019@vindex value-inline@r{ keyword}
1020@item :value-inline
1021Function that takes a widget and returns its value, inlined.
1022
1023Inlined means that if the widget is not inline (i.e., its
1024@code{:inline} property is @code{nil}), the return value is wrapped in
1025a list.
1026
1027@vindex default-get@r{ keyword}
1028@item :default-get
1029Function that takes a widget and returns its default value.
1030
1031By default, it just returns the value stored in @code{:value}.
1032
503@vindex format@r{ keyword} 1033@vindex format@r{ keyword}
504@item :format 1034@item :format
505This string will be inserted in the buffer when you create a widget. 1035This string will be inserted in the buffer when you create a widget.
@@ -513,14 +1043,6 @@ The text inside will be marked as a button.
513By default, the text will be shown in @code{widget-button-face}, and 1043By default, the text will be shown in @code{widget-button-face}, and
514surrounded by brackets. 1044surrounded by brackets.
515 1045
516@defopt widget-button-prefix
517String to prefix buttons.
518@end defopt
519
520@defopt widget-button-suffix
521String to suffix buttons.
522@end defopt
523
524@item %@{ 1046@item %@{
525@itemx %@} 1047@itemx %@}
526The text inside will be displayed with the face specified by 1048The text inside will be displayed with the face specified by
@@ -530,9 +1052,6 @@ The text inside will be displayed with the face specified by
530This will be replaced with the buffer representation of the widget's 1052This will be replaced with the buffer representation of the widget's
531value. What this is depends on the widget type. 1053value. What this is depends on the widget type.
532 1054
533@strong{Warning:} In an @code{editable-field} widget, the @samp{%v} escape
534must be preceded by some other text in the format string (if specified).
535
536@item %d 1055@item %d
537Insert the string specified by @code{:doc} here. 1056Insert the string specified by @code{:doc} here.
538 1057
@@ -561,6 +1080,11 @@ Face used to highlight text inside %[ %] in the format.
561@vindex button-suffix@r{ keyword} 1080@vindex button-suffix@r{ keyword}
562@item :button-prefix 1081@item :button-prefix
563@itemx :button-suffix 1082@itemx :button-suffix
1083Strings used as prefix and suffix for widgets that are buttons.
1084
1085By default, the values are @code{widget-button-prefix} and
1086@code{widget-button-suffix}.
1087
564Text around %[ %] in the format. 1088Text around %[ %] in the format.
565 1089
566These can be 1090These can be
@@ -594,10 +1118,11 @@ Emacsen that supports it.
594@item :help-echo 1118@item :help-echo
595Specifies how to display a message whenever you move to the widget with 1119Specifies how to display a message whenever you move to the widget with
596either @code{widget-forward} or @code{widget-backward} or move the mouse 1120either @code{widget-forward} or @code{widget-backward} or move the mouse
597over it (using the standard @code{help-echo} mechanism). The argument 1121over it (using the standard @code{help-echo} mechanism).
598is either a string to display, a function of one argument, the widget, 1122
599which should return a string to display, or a form that evaluates to 1123The value is either a string to display, or a function of one
600such a string. 1124argument, the widget. If a function, it should return a string to
1125display, or a form that evaluates to such a string.
601 1126
602@vindex follow-link@r{ keyword} 1127@vindex follow-link@r{ keyword}
603@item :follow-link 1128@item :follow-link
@@ -607,7 +1132,12 @@ Specifies how to interpret a @key{mouse-1} click on the widget.
607@vindex indent@r{ keyword} 1132@vindex indent@r{ keyword}
608@item :indent 1133@item :indent
609An integer indicating the absolute number of spaces to indent children 1134An integer indicating the absolute number of spaces to indent children
610of this widget. 1135of this widget. Its value might be @code{nil} too, which corresponds
1136to a value of 0.
1137
1138The default @code{:create} functions and the functions that create the
1139value per se use this property as a rudimentary layout mechanism for
1140the widgets.
611 1141
612@vindex offset@r{ keyword} 1142@vindex offset@r{ keyword}
613@item :offset 1143@item :offset
@@ -619,14 +1149,6 @@ grandchildren compared to this widget.
619An integer indicating how many extra spaces to add to the widget's 1149An integer indicating how many extra spaces to add to the widget's
620children compared to this widget. 1150children compared to this widget.
621 1151
622@vindex notify@r{ keyword}
623@item :notify
624A function called each time the widget or a nested widget is changed.
625The function is called with two or three arguments. The first argument
626is the widget itself, the second argument is the widget that was
627changed, and the third argument is the event leading to the change, if
628any.
629
630@vindex menu-tag@r{ keyword} 1152@vindex menu-tag@r{ keyword}
631@item :menu-tag 1153@item :menu-tag
632Tag used in the menu when the widget is used as an option in a 1154Tag used in the menu when the widget is used as an option in a
@@ -634,10 +1156,12 @@ Tag used in the menu when the widget is used as an option in a
634 1156
635@vindex menu-tag-get@r{ keyword} 1157@vindex menu-tag-get@r{ keyword}
636@item :menu-tag-get 1158@item :menu-tag-get
637Function used for finding the tag when the widget is used as an option 1159Function that takes a widget and returns the tag when the widget is
638in a @code{menu-choice} widget. By default, the tag used will be either the 1160used as an option in a @code{menu-choice} widget.
639@code{:menu-tag} or @code{:tag} property if present, or the @code{princ} 1161
640representation of the @code{:value} property if not. 1162By default, the tag used will be either the @code{:menu-tag} or
1163@code{:tag} property if present, or the @code{princ} representation of
1164the @code{:value} property if not.
641 1165
642@vindex match@r{ keyword} 1166@vindex match@r{ keyword}
643@item :match 1167@item :match
@@ -648,22 +1172,19 @@ represent the specified value.
648@vindex validate@r{ keyword} 1172@vindex validate@r{ keyword}
649@item :validate 1173@item :validate
650A function which takes a widget as an argument, and returns @code{nil} 1174A function which takes a widget as an argument, and returns @code{nil}
651if the widget's current value is valid for the widget. Otherwise it 1175if the widget's current value is valid for the widget.
652should return the widget containing the invalid data, and set that
653widget's @code{:error} property to a string explaining the error.
654 1176
655The following predefined function can be used: 1177Otherwise, it should return the widget containing the invalid data,
1178and set that widget's @code{:error} property to a string explaining
1179the error.
656 1180
657@defun widget-children-validate widget 1181By default, it always returns @code{nil}.
658All the @code{:children} of @var{widget} must be valid.
659@end defun
660 1182
661@vindex tab-order@r{ keyword} 1183@vindex tab-order@r{ keyword}
662@item :tab-order 1184@item :tab-order
663Specify the order in which widgets are traversed with 1185Specify the order in which widgets are traversed with
664@code{widget-forward} or @code{widget-backward}. This is only partially 1186@code{widget-forward} or @code{widget-backward}. This is only partially
665implemented. 1187implemented.
666
667@enumerate a 1188@enumerate a
668@item 1189@item
669Widgets with tabbing order @code{-1} are ignored. 1190Widgets with tabbing order @code{-1} are ignored.
@@ -690,39 +1211,208 @@ This keyword is only used for members of a @code{radio-button-choice} or
690arguments, which will be used when creating the @code{radio-button} or 1211arguments, which will be used when creating the @code{radio-button} or
691@code{checkbox} associated with this item. 1212@code{checkbox} associated with this item.
692 1213
1214@vindex completions-function@r{ keyword}
1215@item :completions-function
1216Function that takes a widget and returns completion data for that
1217widget, like @code{completion-at-point-functions} would.
1218@xref{Completion,,,elisp, the Emacs Lisp Reference Manual}. It's
1219used by @code{editable-field} widgets to provide completions.
1220
1221By default, it looks into the property @code{:completions}, which
1222should be a completion table. If @code{:completions} is @code{nil},
1223then it calls the function stored either in the @code{:complete} or
1224@code{:complete-function} property.
1225
1226@vindex format-handler@r{ keyword}
1227@item :format-handler
1228Function to handle unknown @samp{%} escapes in the format string.
1229
1230It takes a widget and the character that follows the @samp{%} as
1231arguments. You can set this to allow your widget to handle
1232non-standard escapes in your own specialized widgets.
1233
1234@findex widget-default-format-handler
1235You should end up calling @code{widget-default-format-handler} to handle
1236unknown escape sequences, which will handle the @samp{%h} and any future
1237escape sequences, as well as give an error for unknown escapes.
1238
1239@vindex button-face-get@r{ keyword}
1240@item :button-face-get
1241Function to return the face used to fontify a widget button.
1242
1243Takes a widget and returns an appropriate face for the widget. By
1244default, it either returns the face stored in the @code{:button-face}
1245property, or calls the @code{:button-face-get} function from the
1246parent of the widget, if it has one.
1247
1248@vindex mouse-face-get@r{ keyword}
1249@item :mouse-face-get
1250Function to return the face used to fontify a widget when the mouse
1251pointer hovers over it.
1252
1253Takes a widget and returns an appropriate face. By default, it either
1254returns the face stored in the @code{:mouse-face} property, or calls
1255the @code{:button-face-get} function from the parent of the widget, if
1256it has one.
1257
1258@vindex copy@r{ keyword}
1259@item :copy
1260Function to deep copy a widget type.
1261
1262It takes a shallow copy of the widget type as an argument (made by
1263@code{copy-sequence}), and returns a deep copy. The purpose of this
1264is to avoid having different instances of combined widgets share
1265nested attributes.
1266
1267Its value by default is @code{identity}.
1268
1269@vindex active@r{ keyword}
1270@item :active
1271Function that takes a widget and returns @code{t} if it is active.
1272
1273A widget might be effectively always active, if its
1274@code{:always-active} property is @code{t}.
1275
1276@cindex active widget
1277@cindex inactive widget
1278@cindex activate a widget
1279@cindex deactivate a widget
1280Widgets can be in two states: active, which means they are modifiable by
1281the user, or inactive, which means they cannot be modified by the user.
1282You can query or set the state with the following code:
1283
1284@lisp
1285;; Examine if @var{widget} is active or not.
1286(if (widget-apply @var{widget} :active)
1287 (message "Widget is active.")
1288 (message "Widget is inactive.")
1289
1290;; Make @var{widget} inactive.
1291(widget-apply @var{widget} :deactivate)
1292
1293;; Make @var{widget} active.
1294(widget-apply @var{widget} :activate)
1295@end lisp
1296
1297A widget is inactive if it, or any of its ancestors (found by
1298following the @code{:parent} link), have been deactivated. To make sure
1299a widget is really active, you must therefore activate both it and
1300all its ancestors.
1301
1302@lisp
1303(while widget
1304 (widget-apply widget :activate)
1305 (setq widget (widget-get widget :parent)))
1306@end lisp
1307
1308You can check if a widget has been made inactive by examining the value
1309of the @code{:inactive} keyword. If this is non-@code{nil}, the widget itself
1310has been deactivated. This is different from using the @code{:active}
1311keyword, in that the latter tells you if the widget @strong{or} any of
1312its ancestors have been deactivated. Do not attempt to set the
1313@code{:inactive} keyword directly. Use the @code{:activate}
1314@code{:deactivate} functions instead.
1315
1316@vindex activate@r{ keyword}
1317@item :activate
1318Function that takes a widget and makes it active for user
1319modifications.
1320
1321@vindex deactivate@r{ keyword}
1322@item :deactivate
1323Function that takes a widget and makes it inactive for user
1324modifications.
1325
1326@vindex action@r{ keyword}
1327@item :action
1328Function that takes a widget and optionally an event, and handles a
1329user initiated event.
1330
1331By default, uses the @code{:notify} function to notify the widget's
1332parent about the event.
1333
1334@vindex mouse-down-action@r{ keyword}
1335@item :mouse-down-action
1336Function that takes a widget and optionally an event, and handles a
1337mouse click on the widget.
1338
1339By default, it does nothing.
1340
1341@vindex notify@r{ keyword}
1342@item :notify
1343A function called each time the widget or a nested widget is changed.
1344
1345The function is called with two or three arguments. The first argument
1346is the widget itself, the second argument is the widget that was
1347changed, and the third argument is the event leading to the change, if
1348any.
1349
1350By default, it passes the notification to the widget's parent.
1351
1352@vindex prompt-value@r{ keyword}
1353@item :prompt-value
1354Function to prompt for a value in the minibuffer.
1355
1356The function should take four arguments, a widget, a prompt (a
1357string), a value and a boolean, and should return a value for the
1358widget, entered by the user.
1359
1360The prompt is the prompt to use. The value is the default value to
1361use, unless the fourtha argument is non-@code{nil}, in which case
1362there is no default value.
1363
1364The function should read the value using the method most natural for
1365this widget, and does not have to check that it matches.
693@end table 1366@end table
694 1367
695@deffn {User Option} widget-image-directory 1368@node item
696Directory where Widget should look for images. 1369@subsection The @code{item} Widget
697Widget will look here for a file with the same name as specified for the 1370@findex item@r{ widget}
698image, with either a @file{.xpm} (if supported) or @file{.xbm} extension.
699@end deffn
700 1371
701@deffn{User Option} widget-image-enable 1372Syntax:
702If non-@code{nil}, allow images to appear on displays where they are supported.
703@end deffn
704 1373
1374@example
1375@var{type} ::= (item [@var{keyword} @var{argument}]... @var{value})
1376@end example
705 1377
706@menu 1378A useful widget that holds a constant value, and can be included in
707* link:: 1379other widgets. Its super is the @code{default} widget.
708* url-link:: 1380
709* info-link:: 1381As can be seen in the syntax, the @code{item} widget is one of the
710* push-button:: 1382widget that handles the @var{args} argument to @code{widget-create} in
711* editable-field:: 1383a specific way. If present, @var{value} is used to initialize the
712* text:: 1384@code{:value} property. When created, it inserts the value as a
713* menu-choice:: 1385string in the buffer.
714* radio-button-choice:: 1386
715* item:: 1387By default, it has the following properties:
716* choice-item:: 1388
717* toggle:: 1389@table @code
718* checkbox:: 1390@item :convert-widget
719* checklist:: 1391The function that allows it to handle @var{value}.
720* editable-list:: 1392
721* group:: 1393@item :value-create
722@end menu 1394Prints the representation of @code{:value} in the buffer.
1395
1396@item :value-get
1397Returns the value stored in @code{:value}.
1398
1399@item :match
1400A value matches the @code{item} widget if it's @code{equal} to its
1401@code{:value}.
1402
1403@item :match-inline
1404Inline values match the @code{item} widget if @code{:value} is a
1405sublist of values.
1406
1407@item :action
1408The @code{item} widget notifies itself of an event.
1409
1410@item :format
1411By default, the @code{item} widget inserts its tag in the buffer.
1412@end table
723 1413
724@node link 1414@node link
725@section The @code{link} Widget 1415@subsection The @code{link} Widget
726@findex link@r{ widget} 1416@findex link@r{ widget}
727 1417
728Syntax: 1418Syntax:
@@ -731,22 +1421,42 @@ Syntax:
731@var{type} ::= (link [@var{keyword} @var{argument}]... [ @var{value} ]) 1421@var{type} ::= (link [@var{keyword} @var{argument}]... [ @var{value} ])
732@end example 1422@end example
733 1423
1424A widget to represent an embedded link. Its super is the @code{item}
1425widget.
1426
734The @var{value}, if present, is used to initialize the @code{:value} 1427The @var{value}, if present, is used to initialize the @code{:value}
735property. The value should be a string, which will be inserted in the 1428property. The value should be a string, which will be inserted in the
736buffer. 1429buffer.
737 1430
738By default the link will be shown in brackets. 1431By default, it has the following properties:
739 1432
740@defopt widget-link-prefix 1433@table @code
741String to prefix links. 1434@item :button-prefix
742@end defopt 1435The value of @code{widget-link-prefix}.
743 1436
744@defopt widget-link-suffix 1437@item :button-suffix
745String to suffix links. 1438The value of @code{widget-link-suffix}.
746@end defopt 1439
1440@item :keymap
1441A custom keymap for the link widget, so that it can respond to mouse clicks.
1442
1443@item :follow-link
1444This property allows the link to respect the value of
1445@code{mouse-1-click-follows-link}. @xref{Clickable Text,,,elisp, the Emacs Lisp Reference Manual}.
1446
1447@item :format
1448Buttonizes the link, to make it clickable.
1449
1450If you override this property, you should make sure to provide the
1451@samp{%[} and @samp{%]} escape sequences, so that the link is
1452clickable.
1453
1454@end table
1455
1456By default the link will be shown in brackets.
747 1457
748@node url-link 1458@node url-link
749@section The @code{url-link} Widget 1459@subsection The @code{url-link} Widget
750@findex url-link@r{ widget} 1460@findex url-link@r{ widget}
751 1461
752Syntax: 1462Syntax:
@@ -755,12 +1465,14 @@ Syntax:
755@var{type} ::= (url-link [@var{keyword} @var{argument}]... @var{url}) 1465@var{type} ::= (url-link [@var{keyword} @var{argument}]... @var{url})
756@end example 1466@end example
757 1467
758@findex browse-url-browser-function@r{, and @code{url-link} widget} 1468A widget to represent a link to a web page. Its super is the
759When this link is invoked, the @acronym{WWW} browser specified by 1469@code{link} widget.
760@code{browse-url-browser-function} will be called with @var{url}. 1470
1471It overrides the @code{:action} property to open up the @var{url}
1472specified.
761 1473
762@node info-link 1474@node info-link
763@section The @code{info-link} Widget 1475@subsection The @code{info-link} Widget
764@findex info-link@r{ widget} 1476@findex info-link@r{ widget}
765 1477
766Syntax: 1478Syntax:
@@ -769,11 +1481,104 @@ Syntax:
769@var{type} ::= (info-link [@var{keyword} @var{argument}]... @var{address}) 1481@var{type} ::= (info-link [@var{keyword} @var{argument}]... @var{address})
770@end example 1482@end example
771 1483
772When this link is invoked, the built-in Info reader is started on 1484A widget to represent a link to an info file. Its super is the
773@var{address}. 1485@code{link} widget.
1486
1487It overrides the @code{:action} property, to a function to start the
1488built-in Info reader on @var{address}, when invoked.
1489
1490@node function-link
1491@subsection The @code{function-link} Widget
1492@findex function-link@r{ widget}
1493Syntax:
1494
1495@example
1496@var{type} ::= (function-link [@var{keyword} @var{argument}]... @var{function})
1497@end example
1498
1499A widget to represent a link to an Emacs function. Its super is the
1500@code{link} widget.
1501
1502It overrides the @code{:action} property, to a function to describe
1503@var{function}.
1504
1505@node variable-link
1506@subsection The @code{variable-link} Widget
1507@findex variable-link@r{ widget}
1508Syntax:
1509
1510@example
1511@var{type} ::= (variable-link [@var{keyword} @var{argument}]... @var{var})
1512@end example
1513
1514A widget to represent a link to an Emacs variable. Its super is the
1515@code{link} widget.
1516
1517It overrides the @code{:action} property, to a function to describe
1518@var{var}.
1519
1520@node face-link
1521@subsection The @code{face-link} Widget
1522@findex face-link@r{ widget}
1523Syntax:
1524
1525@example
1526@var{type} ::= (face-link [@var{keyword} @var{argument}]... @var{face})
1527@end example
1528
1529A widget to represent a link to an Emacs face. Its super is the
1530@code{link} widget.
1531
1532It overrides the @code{:action} property, to a function to describe
1533@var{face}.
1534
1535@node file-link
1536@subsection The @code{file-link} Widget
1537@findex file-link@r{ widget}
1538Syntax:
1539
1540@example
1541@var{type} ::= (file-link [@var{keyword} @var{argument}]... @var{file})
1542@end example
1543
1544A widget to represent a link to a file. Its super is the
1545@code{link} widget.
1546
1547It overrides the @code{:action} property, to a function to find the file
1548@var{file}.
1549
1550@node emacs-library-link
1551@subsection The @code{emacs-library-link} Widget
1552@findex emacs-library-link@r{ widget}
1553Syntax:
1554
1555@example
1556@var{type} ::= (emacs-library-link [@var{keyword} @var{argument}]... @var{file})
1557@end example
1558
1559A widget to represent a link to an Emacs Lisp file. Its super is the
1560@code{link} widget.
1561
1562It overrides the @code{:action} property, to a function to find the file
1563@var{file}.
1564
1565@node emacs-commentary-link
1566@subsection The @code{emacs-commentary-link} Widget
1567@findex emacs-commentary-link@r{ widget}
1568Syntax:
1569
1570@example
1571@var{type} ::= (emacs-commentary-link [@var{keyword} @var{argument}]... @var{file})
1572@end example
1573
1574A widget to represent a link to the Comment section of an Emacs Lisp
1575file. Its super is the @code{link} widget.
1576
1577It overrides the @code{:action} property, to a function to find the file
1578@var{file} and put point in the Comment section.
774 1579
775@node push-button 1580@node push-button
776@section The @code{push-button} Widget 1581@subsection The @code{push-button} Widget
777@findex push-button@r{ widget} 1582@findex push-button@r{ widget}
778 1583
779Syntax: 1584Syntax:
@@ -782,22 +1587,37 @@ Syntax:
782@var{type} ::= (push-button [@var{keyword} @var{argument}]... [ @var{value} ]) 1587@var{type} ::= (push-button [@var{keyword} @var{argument}]... [ @var{value} ])
783@end example 1588@end example
784 1589
1590A widget that acts as a pushable button. Its super is the @code{item}
1591widget.
1592
785The @var{value}, if present, is used to initialize the @code{:value} 1593The @var{value}, if present, is used to initialize the @code{:value}
786property. The value should be a string, which will be inserted in the 1594property. The value should be a string, which will be inserted in the
787buffer. 1595buffer.
788 1596
789By default the tag will be shown in brackets. 1597By default, it has the following properties:
1598@table @code
1599@item :button-prefix
1600The empty string.
790 1601
791@defopt widget-push-button-prefix 1602@item :button-suffix
792String to prefix push buttons. 1603The empty string.
793@end defopt
794 1604
795@defopt widget-push-button-suffix 1605@item :value-create
796String to suffix push buttons. 1606Inserts a representation of the ``on'' and ``off'' states for the push
797@end defopt 1607button.
1608
1609The representation might be an image, stored in the @code{:tag-glyph}
1610property, or text. If it is text, it might be the value of the
1611@code{:tag} property, or the @code{:value} of the widget, surrounded
1612with @code{widget-push-button-prefix} and
1613@code{widget-push-button-suffix}. @xref{Customization}.
1614
1615@item :format
1616Buttonizes the widget, to make it clickable.
1617@end table
798 1618
799@node editable-field 1619@node editable-field
800@section The @code{editable-field} Widget 1620@subsection The @code{editable-field} Widget
801@findex editable-field@r{ widget} 1621@findex editable-field@r{ widget}
802 1622
803Syntax: 1623Syntax:
@@ -806,56 +1626,137 @@ Syntax:
806@var{type} ::= (editable-field [@var{keyword} @var{argument}]... [ @var{value} ]) 1626@var{type} ::= (editable-field [@var{keyword} @var{argument}]... [ @var{value} ])
807@end example 1627@end example
808 1628
1629A widget that can be edited by the user. Its super is the
1630@code{default} widget.
1631
809The @var{value}, if present, is used to initialize the @code{:value} 1632The @var{value}, if present, is used to initialize the @code{:value}
810property. The value should be a string, which will be inserted in the 1633property. The value should be a string, which will be inserted in the
811field. This widget will match all string values. 1634field. If not present, @code{:value} is the empty string.
812 1635
813The following extra properties are recognized: 1636@strong{Warning:} In an @code{editable-field} widget, the editable
1637field must not be adjacent to another widget---that won't work.
1638You must put some text in between. Either make this text part of
1639the @code{editable-field} widget itself, or insert it with
1640@code{widget-insert}.
1641
1642This widget either overrides or adds the following properties:
814 1643
815@table @code 1644@table @code
1645@item :convert-widget
1646Just like the @code{item} widget, this function allows it to
1647initialize @code{:value} from @var{value}.
1648
1649@vindex keymap@r{ keyword}
1650@vindex widget-field-keymap
1651@item :keymap
1652Keymap used in the editable field.
1653
1654The default value is @code{widget-field-keymap}, which allows the user
1655to use all the normal editing commands, even if the buffer's major
1656mode suppresses some of them. Pressing @key{RET} invokes the function
1657specified by @code{:action}.
1658
1659@item :format
1660By default, it specifies to insert only the widget's value.
1661
1662@strong{Warning:} In an @code{editable-field} widget, the @samp{%v} escape
1663must be preceded by some other text in the @code{:format} string (if
1664specified).
1665
816@vindex size@r{ keyword} 1666@vindex size@r{ keyword}
817@item :size 1667@item :size
818The width of the editable field.@* 1668The width of the editable field.
1669
819By default the field will reach to the end of the line. 1670By default the field will reach to the end of the line.
820 1671
821@vindex value-face@r{ keyword} 1672@vindex value-face@r{ keyword}
822@item :value-face 1673@item :value-face
823Face used for highlighting the editable field. Default is 1674Face used for highlighting the editable field.
824@code{widget-field-face}, see @ref{User Interface}. 1675
1676Default is @code{widget-field-face}, @pxref{User Interface}.
825 1677
826@vindex secret@r{ keyword} 1678@vindex secret@r{ keyword}
827@item :secret 1679@item :secret
828Character used to display the value. You can set this to, e.g., @code{?*} 1680Character used to display the value.
829if the field contains a password or other secret information. By 1681
830default, this is @code{nil}, and the value is not secret. 1682You can set this to, e.g., @code{?*} if the field contains a password
1683or other secret information. By default, this is @code{nil}, and the
1684value is not secret.
831 1685
832@vindex valid-regexp@r{ keyword} 1686@vindex valid-regexp@r{ keyword}
833@item :valid-regexp 1687@item :valid-regexp
834By default the @code{:validate} function will match the content of the 1688By default the @code{:validate} function will match the content of the
835field with the value of this attribute. The default value is @code{""} 1689field with the value of this attribute.
836which matches everything.
837 1690
838@vindex keymap@r{ keyword} 1691The default value is @code{""} which matches everything.
839@vindex widget-field-keymap 1692
840@item :keymap 1693@item :validate
841Keymap used in the editable field. The default value is 1694Returns @code{nil} if the current value of the widget matches the
842@code{widget-field-keymap}, which allows you to use all the normal 1695@code{:valid-regexp} value.
843editing commands, even if the buffer's major mode suppresses some of 1696
844them. Pressing @key{RET} invokes the function specified by 1697@item :prompt-internal
845@code{:action}. 1698A function to read a value for widget, used by the
1699@code{:prompt-value} function.
1700
1701@item :prompt-history
1702A variable that holds the history of field minibuffer edits.
1703
1704@item :prompt-value
1705A function that uses the @code{:prompt-internal} function and the
1706@code{:prompt-history} value to prompt for a string, and retun the
1707user response in the external format.
1708
1709@item :action
1710When invoked, moves point to the next field.
1711
1712@item :value-create
1713Function that takes care of creating the widget, respecting its
1714@code{:size} and @code{:value}.
1715
1716@item :value-set
1717Function to use to modify programatically the current value of the
1718widget.
1719
1720@item :value-delete
1721Function that removes the widget so it cannot be edited anymore.
1722
1723@item :value-get
1724Function to return the current text in the widget.
1725
1726It takes an optional argument, @var{no-truncate}. If
1727@var{no-truncate} is nil, truncates trailing spaces.
1728
1729@item :match
1730Function that makes the widget match any string value.
846@end table 1731@end table
847 1732
848@node text 1733@node text
849@section The @code{text} Widget 1734@subsection The @code{text} Widget
850@findex text@r{ widget} 1735@findex text@r{ widget}
851 1736
1737Syntax:
1738
1739@example
1740@var{type} ::= (text [@var{keyword} @var{argument}]... [ @var{value} ])
1741@end example
1742
1743A widget just like the @code{editable-field} widget, but intended for
1744multiline text fields. Its super is the @code{editable-field} widget.
1745
1746It overrides the following properties:
1747
1748@table @code
1749@item :format
1750By default, prints a tag and the value.
1751
852@vindex widget-text-keymap 1752@vindex widget-text-keymap
853This is just like @code{editable-field}, but intended for multiline text 1753@item :keymap
854fields. The default @code{:keymap} is @code{widget-text-keymap}, which 1754The default is @code{widget-text-keymap}, which does not rebind the
855does not rebind the @key{RET} key. 1755@key{RET} key.
1756@end table
856 1757
857@node menu-choice 1758@node menu-choice
858@section The @code{menu-choice} Widget 1759@subsection The @code{menu-choice} Widget
859@findex menu-choice@r{ widget} 1760@findex menu-choice@r{ widget}
860 1761
861Syntax: 1762Syntax:
@@ -864,21 +1765,37 @@ Syntax:
864@var{type} ::= (menu-choice [@var{keyword} @var{argument}]... @var{type} ... ) 1765@var{type} ::= (menu-choice [@var{keyword} @var{argument}]... @var{type} ... )
865@end example 1766@end example
866 1767
1768A widget to represent a menu of options. Its super is the
1769@code{default} widget.
1770
867The @var{type} argument represents each possible choice. The widget's 1771The @var{type} argument represents each possible choice. The widget's
868value will be that of the chosen @var{type} argument. This widget will 1772value will be that of the chosen @var{type} argument.
869match any value matching at least one of the specified @var{type} 1773
870arguments. 1774It either overrides or adds the following properties:
871 1775
872@table @code 1776@table @code
1777@item :convert-widget
1778A function that takes care of converting each possible choice.
1779
1780@item :copy
1781A function to copy each possible choice.
1782
1783@item :format
1784By default, buttonize the tag and show the value.
1785
873@vindex void@r{ keyword} 1786@vindex void@r{ keyword}
874@item :void 1787@item :void
875Widget type used as a fallback when the value does not match any of the 1788Widget type used as a fallback when the value does not match any of the
876specified @var{type} arguments. 1789specified @var{type} arguments.
877 1790
1791By default this is an @code{item} widget.
1792
878@vindex case-fold@r{ keyword} 1793@vindex case-fold@r{ keyword}
879@item :case-fold 1794@item :case-fold
880Set this to @code{nil} if you don't want to ignore case when prompting for a 1795If @code{nil} don't ignore case when prompting for a choice through
881choice through the minibuffer. 1796the minibuffer.
1797
1798By default, its value is @code{t}.
882 1799
883@vindex children@r{ keyword} 1800@vindex children@r{ keyword}
884@item :children 1801@item :children
@@ -892,10 +1809,54 @@ The current chosen type.
892@vindex args@r{ keyword} 1809@vindex args@r{ keyword}
893@item :args 1810@item :args
894The list of types. 1811The list of types.
1812
1813@item :value-create
1814The function that inserts the current value for the widget.
1815
1816It inserts the first choice that matches, as with the @code{:match}
1817function, the value of the widget.
1818
1819@item :value-get
1820Returns the value of the first child for the widget (see the
1821description for @code{:children} above).
1822
1823@item :value-inline
1824Returns the inline value of the first child for the widget.
1825
1826@item :default-get
1827The default value for this widget is the default value for the first
1828choice, in case @code{:value} is missing.
1829
1830This means that if you want a specific default value for the
1831@code{menu-choice} widget, you should either pass a @code{:value}
1832property when creating it, or arrange the choices so that the first
1833one can hold your desired default value.
1834
1835@item :mouse-down-action
1836A function that takes care of showing a menu, if possible and desired.
1837
1838@item :action
1839A function that takes care of getting a new choice for the widget.
1840
1841Depending on the number of choices available, it may show a menu or
1842just toggle the choices, or even do nothing at all.
1843
1844After getting the choice, it recreates the widget and notifies it.
1845
1846@item :validate
1847Returns @code{nil} if the widget's value is a valid choice.
1848
1849@item :match
1850This widget will match any value matching at least one of the
1851specified @var{type} arguments.
1852
1853@item :match-inline
1854A function that returns non-@code{nil} if the values match the widget,
1855taking into account the @code{:inline} property.
895@end table 1856@end table
896 1857
897@node radio-button-choice 1858@node radio-button-choice
898@section The @code{radio-button-choice} Widget 1859@subsection The @code{radio-button-choice} Widget
899@findex radio-button-choice@r{ widget} 1860@findex radio-button-choice@r{ widget}
900 1861
901Syntax: 1862Syntax:
@@ -904,14 +1865,28 @@ Syntax:
904@var{type} ::= (radio-button-choice [@var{keyword} @var{argument}]... @var{type} ... ) 1865@var{type} ::= (radio-button-choice [@var{keyword} @var{argument}]... @var{type} ... )
905@end example 1866@end example
906 1867
907The component types specify the choices, with one radio button for 1868A widget to represent a choice from multiple options. Its super is
1869the @code{default} widget.
1870
1871The component @var{types} specify the choices, with one radio button for
908each. The widget's value will be that of the chosen @var{type} 1872each. The widget's value will be that of the chosen @var{type}
909argument. This widget matches any value that matches at least one of 1873argument.
910the specified @var{type} arguments.
911 1874
912The following extra properties are recognized. 1875It overrides the following properties:
913 1876
914@table @code 1877@table @code
1878@item :convert-widget
1879As other composite widgets, a function that takes care of converting
1880each available choice.
1881
1882@item :copy
1883A function to copy each available choice.
1884
1885@item :action
1886A function that checks if any radio button was pressed and activates
1887the pressed one, possibly deactivating an old one. Then, it notifies
1888itself.
1889
915@vindex entry-format@r{ keyword} 1890@vindex entry-format@r{ keyword}
916@item :entry-format 1891@item :entry-format
917This string will be inserted for each entry in the list. 1892This string will be inserted for each entry in the list.
@@ -925,6 +1900,9 @@ Replace with the radio button.
925Insert a literal @samp{%}. 1900Insert a literal @samp{%}.
926@end table 1901@end table
927 1902
1903@item :format
1904By default, it inserts its value.
1905
928@vindex button-args@r{ keyword} 1906@vindex button-args@r{ keyword}
929@item :button-args 1907@item :button-args
930A list of keywords to pass to the radio buttons. Useful for setting, 1908A list of keywords to pass to the radio buttons. Useful for setting,
@@ -940,11 +1918,38 @@ The widgets representing each type.
940 1918
941@vindex choice@r{ keyword} 1919@vindex choice@r{ keyword}
942@item :choice 1920@item :choice
943The current chosen type 1921The current chosen type.
944 1922
945@vindex args@r{ keyword} 1923@vindex args@r{ keyword}
946@item :args 1924@item :args
947The list of types. 1925The list of types.
1926
1927@item :value-create
1928A function to insert all available choices.
1929
1930@item :value-get
1931Returns the value for the chosen widget.
1932
1933@item :value-set
1934A function to set the value to one of its available options.
1935
1936@item :value-inline
1937A function that returns the inline value of the child widget.
1938
1939@item :offset
1940By default, this widget has an offset of 4.
1941
1942@item :validate
1943The widget validates if the current value is valid for one of its
1944children.
1945
1946@item :match
1947This widget matches any value that matches at least one of
1948the specified @var{type} arguments.
1949
1950@item :match-inline
1951Like the @code{:match} function, but taking into account inline
1952values.
948@end table 1953@end table
949 1954
950You can add extra radio button items to a @code{radio-button-choice} 1955You can add extra radio button items to a @code{radio-button-choice}
@@ -960,22 +1965,8 @@ Please note that such items added after the @code{radio-button-choice}
960widget has been created will @strong{not} be properly destructed when 1965widget has been created will @strong{not} be properly destructed when
961you call @code{widget-delete}. 1966you call @code{widget-delete}.
962 1967
963@node item
964@section The @code{item} Widget
965@findex item@r{ widget}
966
967Syntax:
968
969@example
970@var{item} ::= (item [@var{keyword} @var{argument}]... @var{value})
971@end example
972
973The @var{value}, if present, is used to initialize the @code{:value}
974property. The value should be a string, which will be inserted in the
975buffer. This widget will only match the specified value.
976
977@node choice-item 1968@node choice-item
978@section The @code{choice-item} Widget 1969@subsection The @code{choice-item} Widget
979@findex choice-item@r{ widget} 1970@findex choice-item@r{ widget}
980 1971
981Syntax: 1972Syntax:
@@ -984,14 +1975,26 @@ Syntax:
984@var{item} ::= (choice-item [@var{keyword} @var{argument}]... @var{value}) 1975@var{item} ::= (choice-item [@var{keyword} @var{argument}]... @var{value})
985@end example 1976@end example
986 1977
1978A widget to represent a choice in a @code{menu-choice} widget. Its
1979super is the @code{item} widget.
1980
987The @var{value}, if present, is used to initialize the @code{:value} 1981The @var{value}, if present, is used to initialize the @code{:value}
988property. The value should be a string, which will be inserted in the 1982property.
989buffer as a button. Activating the button of a @code{choice-item} is 1983
990equivalent to activating the parent widget. This widget will only match 1984It overrides the following properties:
991the specified value. 1985
1986@table @code
1987@item :action
1988Activating the button of a @code{choice-item} is equivalent to
1989activating the parent widget.
1990
1991@item :format
1992By default, it buttonizes the tag (i.e., its value) and adds a newline
1993character at the end of the widget.
1994@end table
992 1995
993@node toggle 1996@node toggle
994@section The @code{toggle} Widget 1997@subsection The @code{toggle} Widget
995@findex toggle@r{ widget} 1998@findex toggle@r{ widget}
996 1999
997Syntax: 2000Syntax:
@@ -1000,43 +2003,136 @@ Syntax:
1000@var{type} ::= (toggle [@var{keyword} @var{argument}]...) 2003@var{type} ::= (toggle [@var{keyword} @var{argument}]...)
1001@end example 2004@end example
1002 2005
2006A widget that can toggle between two states. Its super is the
2007@code{item} widget.
2008
1003The widget has two possible states, @samp{on} and @samp{off}, which 2009The widget has two possible states, @samp{on} and @samp{off}, which
1004correspond to a @code{t} or @code{nil} value, respectively. 2010correspond to a @code{t} or @code{nil} value, respectively.
1005 2011
1006The following extra properties are recognized: 2012It either overrides or adds the following properties:
1007 2013
1008@table @code 2014@table @code
2015@item :format
2016By default, it buttonizes the value and adds a newline at the end of
2017the widget.
2018
1009@item :on 2019@item :on
1010A string representing the @samp{on} state. By default the string 2020A string representing the @samp{on} state. By default the string
1011@samp{on}. 2021@samp{on}.
2022
1012@item :off 2023@item :off
1013A string representing the @samp{off} state. By default the string 2024A string representing the @samp{off} state. By default the string
1014@samp{off}. 2025@samp{off}.
2026
1015@vindex on-glyph@r{ keyword} 2027@vindex on-glyph@r{ keyword}
1016@item :on-glyph 2028@item :on-glyph
1017Name of a glyph to be used instead of the @samp{:on} text string, on 2029Name of a glyph to be used instead of the @samp{:on} text string, on
1018emacsen that supports this. 2030emacsen that supports this.
2031
1019@vindex off-glyph@r{ keyword} 2032@vindex off-glyph@r{ keyword}
1020@item :off-glyph 2033@item :off-glyph
1021Name of a glyph to be used instead of the @samp{:off} text string, on 2034Name of a glyph to be used instead of the @samp{:off} text string, on
1022emacsen that supports this. 2035emacsen that supports this.
2036
2037@item :value-create
2038A function for creating the widget's value, according to its
2039@samp{:on} or @samp{:off} state.
2040
2041@item :action
2042Function to toggle the state of the widget. After toggling, it
2043notifies itself.
2044
2045@item :match
2046This widget matches anything.
2047@end table
2048
2049@node radio-button-toggle
2050@subsection The @code{radio-button-toggle} Widget
2051@findex radio-button-toggle@r{ widget}
2052Syntax:
2053
2054@example
2055@var{type} ::= (radio-button-toggle [@var{keyword} @var{argument}]...)
2056@end example
2057
2058A toggle to use in the @code{radio} widget.
2059
2060It overrides the following properties:
2061
2062@table @code
2063@item :button-prefix
2064The empty string.
2065
2066@item :button-suffix
2067The empty string.
2068
2069@item :on
2070The string ``(*)'', to represent the @samp{on} state.
2071
2072@item :off
2073The string ``( )'', to represent the @samp{off} state.
2074
2075@item :on-glyph
2076The name of an image to represent the @samp{on} state.
2077
2078@item :off-glpyh
2079The name of an image to represent the @samp{off} state.
2080
2081@item :format
2082By default, it buttonizes its value.
2083
2084@item :notify
2085A function to notify its parent.
1023@end table 2086@end table
1024 2087
1025@node checkbox 2088@node checkbox
1026@section The @code{checkbox} Widget 2089@subsection The @code{checkbox} Widget
1027@findex checkbox@r{ widget} 2090@findex checkbox@r{ widget}
1028 2091
1029This widget has two possible states, @samp{selected} and
1030@samp{unselected}, which corresponds to a @code{t} or @code{nil} value.
1031
1032Syntax: 2092Syntax:
1033 2093
1034@example 2094@example
1035@var{type} ::= (checkbox [@var{keyword} @var{argument}]...) 2095@var{type} ::= (checkbox [@var{keyword} @var{argument}]...)
1036@end example 2096@end example
1037 2097
2098A widget to represent a toggle widget, with a checkbox. Its super is
2099the @code{toggle} widget.
2100
2101This widget has two possible states, @samp{selected} and
2102@samp{unselected}, which corresponds to a @code{t} or @code{nil}
2103value, respectively.
2104
2105It either overrides or adds the following properties:
2106
2107@table @code
2108@item :button-prefix
2109The empty string.
2110
2111@item :button-suffix
2112The empty string.
2113
2114@item :format
2115By default, buttonizes the value.
2116
2117@item :on
2118By default, the string ``[X]''.
2119
2120@item :off
2121By default, the string ``[ ]''.
2122
2123@item :on-glyph
2124The name of the image to use when the state is @samp{on}.
2125
2126@item :off-glyph
2127The name of the image to use when the state is @samp{off}.
2128
2129@item :action
2130A function that toggles the checkbox, notifies the parents and in the
2131@samp{on} state, activates its siblings.
2132@end table
2133
1038@node checklist 2134@node checklist
1039@section The @code{checklist} Widget 2135@subsection The @code{checklist} Widget
1040@findex checklist@r{ widget} 2136@findex checklist@r{ widget}
1041 2137
1042Syntax: 2138Syntax:
@@ -1045,14 +2141,26 @@ Syntax:
1045@var{type} ::= (checklist [@var{keyword} @var{argument}]... @var{type} ... ) 2141@var{type} ::= (checklist [@var{keyword} @var{argument}]... @var{type} ... )
1046@end example 2142@end example
1047 2143
2144A widget to represent a multiplice choice. Its super is the
2145@code{default} widget.
2146
1048The @var{type} arguments represent each checklist item. The widget's 2147The @var{type} arguments represent each checklist item. The widget's
1049value will be a list containing the values of all checked @var{type} 2148value will be a list containing the values of all checked @var{type}
1050arguments. The checklist widget will match a list whose elements all 2149arguments.
1051match at least one of the specified @var{type} arguments.
1052 2150
1053The following extra properties are recognized: 2151It either overrides or adds the following properties:
1054 2152
1055@table @code 2153@table @code
2154@item :convert-widget
2155As other composite widgets, a function that takes care of converting
2156each checklist item.
2157
2158@item :copy
2159A function to copy each checklist item.
2160
2161@item :format
2162By default, it inserts its value.
2163
1056@vindex entry-format@r{ keyword} 2164@vindex entry-format@r{ keyword}
1057@item :entry-format 2165@item :entry-format
1058This string will be inserted for each entry in the list. 2166This string will be inserted for each entry in the list.
@@ -1066,14 +2174,6 @@ Replace with the checkbox.
1066Insert a literal @samp{%}. 2174Insert a literal @samp{%}.
1067@end table 2175@end table
1068 2176
1069@vindex greedy@r{ keyword}
1070@item :greedy
1071Usually a checklist will only match if the items are in the exact
1072sequence given in the specification. By setting @code{:greedy} to
1073non-@code{nil}, it will allow the items to come in any sequence.
1074However, if you extract the value they will be in the sequence given
1075in the checklist, i.e., the original sequence is forgotten.
1076
1077@vindex button-args@r{ keyword} 2177@vindex button-args@r{ keyword}
1078@item :button-args 2178@item :button-args
1079A list of keywords to pass to the checkboxes. Useful for setting, 2179A list of keywords to pass to the checkboxes. Useful for setting,
@@ -1090,10 +2190,35 @@ The widgets representing each type.
1090@vindex args@r{ keyword} 2190@vindex args@r{ keyword}
1091@item :args 2191@item :args
1092The list of types. 2192The list of types.
2193
2194@item :value-create
2195The function that takes care of inserting all values.
2196
2197@item :value-get
2198A function that returns all values of selected items.
2199
2200@item :validate
2201A function that ensures all selected children are valid.
2202
2203@item :match
2204The checklist widget will match a list whose elements all
2205match at least one of the specified @var{type} arguments.
2206
2207@item :match-inline
2208Like the @code{:match} function, but taking into account the
2209@code{:inline} property.
2210
2211@vindex greedy@r{ keyword}
2212@item :greedy
2213Usually a checklist will only match if the items are in the exact
2214sequence given in the specification. By setting @code{:greedy} to
2215non-@code{nil}, it will allow the items to come in any sequence.
2216However, if you extract the value they will be in the sequence given
2217in the checklist, i.e., the original sequence is forgotten.
1093@end table 2218@end table
1094 2219
1095@node editable-list 2220@node editable-list
1096@section The @code{editable-list} Widget 2221@subsection The @code{editable-list} Widget
1097@findex editable-list@r{ widget} 2222@findex editable-list@r{ widget}
1098 2223
1099Syntax: 2224Syntax:
@@ -1102,12 +2227,19 @@ Syntax:
1102@var{type} ::= (editable-list [@var{keyword} @var{argument}]... @var{type}) 2227@var{type} ::= (editable-list [@var{keyword} @var{argument}]... @var{type})
1103@end example 2228@end example
1104 2229
1105The value is a list, where each member represents one widget of type 2230A widget that can hold a variable list of widgets of the same type,
1106@var{type}. 2231represented by @var{type}. Its super is the @code{default} widget.
1107 2232
1108The following extra properties are recognized: 2233It either overrides or adds the following properties:
1109 2234
1110@table @code 2235@table @code
2236@item :convert-widget
2237As other composite widgets, a function that takes care of converting
2238each type in @var{type}.
2239
2240@item :copy
2241A function to copy the types given in @var{type}.
2242
1111@vindex entry-format@r{ keyword} 2243@vindex entry-format@r{ keyword}
1112@item :entry-format 2244@item :entry-format
1113This string will be inserted for each entry in the list. 2245This string will be inserted for each entry in the list.
@@ -1117,9 +2249,9 @@ The following @samp{%} escapes are available:
1117This will be replaced with the buffer representation of the @var{type} 2249This will be replaced with the buffer representation of the @var{type}
1118widget. 2250widget.
1119@item %i 2251@item %i
1120Insert the @b{[INS]} button. 2252Insert the @b{[INS]} button, a widget of type @code{insert-button}.
1121@item %d 2253@item %d
1122Insert the @b{[DEL]} button. 2254Insert the @b{[DEL]} button, a widget of type @code{delete-button}.
1123@item %% 2255@item %%
1124Insert a literal @samp{%}. 2256Insert a literal @samp{%}.
1125@end table 2257@end table
@@ -1140,6 +2272,18 @@ A list of keyword arguments to pass to the trailing insert button.
1140@item :buttons 2272@item :buttons
1141The widgets representing the insert and delete buttons. 2273The widgets representing the insert and delete buttons.
1142 2274
2275@item :format
2276By default, insert its value and at the and adds an insert button.
2277
2278This is useful so that new elements can be added to the list upon user
2279request.
2280
2281@item :format-handler
2282A function that recognize the escape for inserting an insert button.
2283
2284@item :offset
2285By default, this widget has an offset of 12.
2286
1143@vindex children@r{ keyword} 2287@vindex children@r{ keyword}
1144@item :children 2288@item :children
1145The widgets representing the elements of the list. 2289The widgets representing the elements of the list.
@@ -1147,24 +2291,124 @@ The widgets representing the elements of the list.
1147@vindex args@r{ keyword} 2291@vindex args@r{ keyword}
1148@item :args 2292@item :args
1149List whose @sc{car} is the type of the list elements. 2293List whose @sc{car} is the type of the list elements.
2294
2295@item :insert-before
2296Function to insert a new widget as a child of the @code{editable-list}
2297widget.
2298
2299This function inserts a recently deleted child, if there is one. That
2300is useful, so that the user can move elements in a list easily. If
2301there is not a recently deleted child, it inserts a child with its
2302default value.
2303
2304@item :delete-at
2305Function to delete a child from the widget, and store it into the
2306@code{:last-deleted} list, so that it can be reinserted when the
2307@code{:insert-before} function executes.
2308
2309@item :value-create
2310The function that takes care of inserting all values.
2311
2312@item :value-get
2313Function that returns a list with the value of the child widgets.
2314
2315@item :validate
2316This widget validates if all children validate.
2317
2318@item :match
2319To match, the value must be a list and all the list members must match
2320the specified @var{type}.
2321
2322@item :match-inline
2323Like the @code{:match} function, but taking into account inline
2324values and widgets.
1150@end table 2325@end table
1151 2326
1152@node group 2327@node group
1153@section The @code{group} Widget 2328@subsection The @code{group} Widget
1154@findex group@r{ widget} 2329@findex group@r{ widget}
1155 2330
1156This widget simply group other widgets together.
1157
1158Syntax: 2331Syntax:
1159 2332
1160@example 2333@example
1161@var{type} ::= (group [@var{keyword} @var{argument}]... @var{type}...) 2334@var{type} ::= (group [@var{keyword} @var{argument}]... @var{type}...)
1162@end example 2335@end example
1163 2336
1164The value is a list, with one member for each @var{type}. 2337A widget to group other widgets. Its super is the @code{default}
2338widget.
2339
2340Its value is a list, with one member for each @var{type}.
2341
2342It overrides the following properties:
2343
2344@table @code
2345@item :convert-widget
2346As other composite widgets, a function that takes care of converting
2347each widget in @var{type}.
2348
2349@item :copy
2350A function to copy the types given in @var{type}.
2351
2352@item :format
2353By default, displays a newline character and its value.
2354
2355@item :value-create
2356A function to create each of its components.
2357
2358@item :value-get
2359The same function used by the @code{editable-list} widget.
2360
2361@item :default-get
2362A function that returns a list whose members are the default values of
2363each widget it groups.
2364
2365@item :validate
2366This widget validates if all of its children validate.
2367
2368@item :match
2369This widget matches a value that matches each of its components.
2370
2371@item :match-inline
2372As @code{:match}, but taking into account widgets and values that are
2373inline.
2374@end table
2375
2376@node documentation-string
2377@subsection The @code{documentation-string} Widget
2378@findex documentation-string@r{ widget}
2379Syntax:
2380
2381@example
2382@var{type} ::= (documentation-string [@var{keyword} @var{argument}]... @var{value})
2383@end example
2384
2385A widget to represent a documentation string. Its super is the
2386@code{item} widget.
2387
2388It either overrides or adds the following properties:
2389
2390@table @code
2391@item :format
2392By default, insert its value.
2393
2394@item :value-create
2395Function to insert a documentation string, possibly hiding part of the
2396documentation if its large.
2397
2398To show or hide the rest of the documentation, uses a
2399@code{visibility} widget.
2400
2401@item :action
2402Function to toggle showing the documentation upon an event.
2403
2404@item :visibility-widget
2405A symbol, the type of the widget to use for the visibility widget.
2406
2407This is, by default, the symbol @code{visibility}.
2408@end table
1165 2409
1166@node Sexp Types 2410@node Sexp Types
1167@chapter Sexp Types 2411@section Sexp Types
1168@cindex sexp types 2412@cindex sexp types
1169 2413
1170A number of widgets for editing @dfn{s-expressions} (Lisp types), sexp 2414A number of widgets for editing @dfn{s-expressions} (Lisp types), sexp
@@ -1179,7 +2423,7 @@ categories described in this section.
1179@end menu 2423@end menu
1180 2424
1181@node constants 2425@node constants
1182@section The Constant Widgets 2426@subsection The Constant Widgets
1183@cindex constant widgets 2427@cindex constant widgets
1184 2428
1185The @code{const} widget can contain any Lisp expression, but the user is 2429The @code{const} widget can contain any Lisp expression, but the user is
@@ -1192,19 +2436,26 @@ The syntax for the @code{const} widget is:
1192@var{type} ::= (const [@var{keyword} @var{argument}]... [ @var{value} ]) 2436@var{type} ::= (const [@var{keyword} @var{argument}]... [ @var{value} ])
1193@end example 2437@end example
1194 2438
1195The @var{value}, if present, is used to initialize the @code{:value} 2439Its super is the @code{item} widget. The @var{value}, if present, is
1196property and can be any s-expression. 2440used to initialize the @code{:value} property and can be any
2441s-expression.
1197 2442
1198@deffn Widget const 2443@deffn Widget const
1199This will display any valid s-expression in an immutable part of the 2444This will display any valid s-expression in an immutable part of the
1200buffer. 2445buffer.
2446
2447It overrides the @code{:prompt-value} function, to avoid prompting and
2448just return the widget's value.
1201@end deffn 2449@end deffn
1202 2450
1203There are two variations of the @code{const} widget, namely 2451There are two variations of the @code{const} widget, namely
1204@code{variable-item} and @code{function-item}. These should contain a 2452@code{variable-item} and @code{function-item}. These should contain a
1205symbol with a variable or function binding. The major difference from 2453symbol with a variable or function binding, respectively. The major
1206the @code{const} widget is that they will allow the user to see the 2454difference from the @code{const} widget is that they will allow the
1207variable or function documentation for the symbol. 2455user to see the variable or function documentation for the symbol.
2456
2457This is accomplished via using the @samp{%h} format escape, and adding
2458an appropiate @code{:documentation-property} function for each widget.
1208 2459
1209@deffn Widget variable-item 2460@deffn Widget variable-item
1210An immutable symbol that is bound as a variable. 2461An immutable symbol that is bound as a variable.
@@ -1215,7 +2466,7 @@ An immutable symbol that is bound as a function.
1215@end deffn 2466@end deffn
1216 2467
1217@node generic 2468@node generic
1218@section Generic Sexp Widget 2469@subsection Generic Sexp Widget
1219@cindex generic sexp widget 2470@cindex generic sexp widget
1220 2471
1221The @code{sexp} widget can contain any Lisp expression, and allows the 2472The @code{sexp} widget can contain any Lisp expression, and allows the
@@ -1228,23 +2479,42 @@ The syntax for the @code{sexp} widget is:
1228@end example 2479@end example
1229 2480
1230@deffn Widget sexp 2481@deffn Widget sexp
1231This will allow you to edit any valid s-expression in an editable buffer 2482This widget represents an editable field that's useful to edit any
1232field. 2483valid s-expression.
1233 2484
1234The @code{sexp} widget takes the same keyword arguments as the 2485The @code{sexp} widget takes the same keyword arguments as the
1235@code{editable-field} widget. @xref{editable-field}. 2486@code{editable-field} widget. @xref{editable-field}.
2487
2488Its default value is @code{nil}.
2489@end deffn
2490
2491@deffn Widget restricted-sexp
2492A widget to edit Lisp expressions restricted to certain values or
2493types. Its super is the @code{sexp} widget.
2494
2495It works just like the sexp widget, but it overrides the @code{:match}
2496function to match for certain values. To use this widget, either you
2497must define a @code{:match} function or give a
2498@code{:match-alternatives} property. The @code{:match-alternatives}
2499property holds a list of predicate functions to call when checking if
2500a given value matches the widget. Each predicate function will be
2501called with one argument, the value to be matched, and should return
2502non-@code{nil} on success.
2503
2504As an example, the @code{integer} widget overrides
2505@code{:match-alternatives} to @code{(integerp)}.
1236@end deffn 2506@end deffn
1237 2507
1238@node atoms 2508@node atoms
1239@section Atomic Sexp Widgets 2509@subsection Atomic Sexp Widgets
1240@cindex atomic sexp widget 2510@cindex atomic sexp widget
1241 2511
1242The atoms are s-expressions that do not consist of other s-expressions. 2512The atoms are s-expressions that do not consist of other s-expressions.
1243For example, a string, a file name, or a symbol are atoms, while a list 2513For example, a string, a file name, or a symbol are atoms, while a list
1244is a composite type. You can edit the value of an atom with the 2514is a composite type. You can edit the value of an atom with the
1245following widgets. 2515widgets described in this section.
1246 2516
1247The syntax for all the atoms are: 2517The syntax for all the atoms is:
1248 2518
1249@example 2519@example
1250@var{type} ::= (@var{construct} [@var{keyword} @var{argument}]... [ @var{value} ]) 2520@var{type} ::= (@var{construct} [@var{keyword} @var{argument}]... [ @var{value} ])
@@ -1252,68 +2522,151 @@ The syntax for all the atoms are:
1252 2522
1253The @var{value}, if present, is used to initialize the @code{:value} 2523The @var{value}, if present, is used to initialize the @code{:value}
1254property and must be an expression of the same type as the widget. 2524property and must be an expression of the same type as the widget.
1255That is, the string widget can only be initialized with a string. 2525That is, for example, the string widget can only be initialized with a
2526string.
1256 2527
1257All the atom widgets take the same keyword arguments as the 2528All the atom widgets take the same keyword arguments as the
1258@code{editable-field} widget. @xref{editable-field}. 2529@code{editable-field} widget. @xref{editable-field}.
1259 2530
1260@deffn Widget string 2531@deffn Widget string
1261Allows you to edit a string in an editable field. 2532An editable field widget that can represent any Lisp string.
2533
2534It offers completion via the ispell library and the @code{:complete}
2535property.
1262@end deffn 2536@end deffn
1263 2537
1264@deffn Widget regexp 2538@deffn Widget regexp
1265Allows you to edit a regular expression in an editable field. 2539An editable field widget that can represent a regular expression.
2540
2541Overrides the @code{:match} and the @code{:validate} properties to
2542check that the value is a valid regexp.
1266@end deffn 2543@end deffn
1267 2544
1268@deffn Widget character 2545@deffn Widget character
1269Allows you to enter a character in an editable field. 2546An editable field widget that can represent a character.
2547
2548The character widget represents some characters (like the newline
2549character) in a special manner, to make it easier for the user to see
2550what's the content of the character field.
1270@end deffn 2551@end deffn
1271 2552
1272@deffn Widget file 2553@deffn Widget file
1273Allows you to edit a file name in an editable field. 2554A widget for editing file names.
1274 2555
1275Keywords: 2556Keywords:
1276@table @code 2557@table @code
2558@item :completions
2559Offers file name completion to the user.
2560
2561@item :prompt-value
2562A function to read a file name from the minibuffer.
2563
1277@vindex must-match@r{ keyword} 2564@vindex must-match@r{ keyword}
1278@item :must-match 2565@item :must-match
1279If this is set to non-@code{nil}, only existing file names will be 2566If this is set to non-@code{nil}, only existing file names are allowed
1280allowed in the minibuffer. 2567when prompting for a value in the minibuffer.
2568
2569@item :match
2570The widget matches if the value is a string, and the file whose name
2571is that string is an existing file, or if @code{:must-match} is
2572@code{nil}.
2573
2574@item :validate
2575The widget is valid if its value matches.
2576
1281@end table 2577@end table
1282@end deffn 2578@end deffn
1283 2579
1284@deffn Widget directory 2580@deffn Widget directory
1285Allows you to edit a directory name in an editable field. 2581A widget for editing directory names.
1286Similar to the @code{file} widget. 2582
2583Its super is the @code{file} widget, and it overrides the
2584@code{:completions} property, to offer completions only for
2585directories.
1287@end deffn 2586@end deffn
1288 2587
1289@deffn Widget symbol 2588@deffn Widget symbol
1290Allows you to edit a Lisp symbol in an editable field. 2589A widget for editing a Lisp symbol.
2590
2591Its value by default is @code{nil}.
1291@end deffn 2592@end deffn
1292 2593
1293@deffn Widget function 2594@deffn Widget function
1294Allows you to edit a lambda expression, or a function name with completion. 2595A widget for editing a lambda expression, or a function name, offering
2596completion. Its super is the @code{restricted-sexp} widget.
1295@end deffn 2597@end deffn
1296 2598
1297@deffn Widget variable 2599@deffn Widget variable
1298Allows you to edit a variable name, with completion. 2600A widget for editing variable names, offering completion. Its super
2601is the @code{symbol} widget.
1299@end deffn 2602@end deffn
1300 2603
1301@deffn Widget integer 2604@deffn Widget integer
1302Allows you to edit an integer in an editable field. 2605A widget for editing integers in an editable field. Its super is the
2606@code{restricted-sexp} widget.
2607
2608It has a default @code{:value} of 0.
2609@end deffn
2610
2611@deffn Widget natnum
2612A widget for editing non-negative integers. Its super is the
2613@code{restricted-sexp} widget.
2614
2615It has a default @code{:value} of 0.
2616@end deffn
2617
2618@deffn Widget float
2619A widget for editing a floating point number. Its super is the
2620@code{restricted-sexp} widget.
2621
2622It has a default @code{:value} of 0.0.
1303@end deffn 2623@end deffn
1304 2624
1305@deffn Widget number 2625@deffn Widget number
1306Allows you to edit a number in an editable field. 2626A widget for editing a number, either floating point or integer. Its
2627super is the @code{restricted-sexp} widget.
2628
2629It has a default @code{:value} of 0.0.
1307@end deffn 2630@end deffn
1308 2631
1309@deffn Widget boolean 2632@deffn Widget boolean
1310Allows you to edit a boolean. In Lisp this means a variable which is 2633A widget for editing a boolean value. Its super is the @code{toggle}
1311either @code{nil} meaning false, or non-@code{nil} meaning true. 2634widget.
2635
2636Its value may be @code{nil}, meaning false, or non-@code{nil}, meaning
2637true.
2638@end deffn
2639
2640@deffn Widget color
2641A widget to edit a color name.
2642
2643In addition, shows a sample that shows the selected color, if any.
1312@end deffn 2644@end deffn
1313 2645
2646@deffn Widget other
2647A widget useful as the last item in a @code{choice} widget, since it
2648matches any value.
2649
2650Its super is the @code{sexp} widget, and its @code{:value} is
2651@code{other}, by default.
2652@end deffn
2653
2654@deffn Widget coding-system
2655A widget that can represent a coding system name, offering
2656completions. @xref{Coding Systems,,,elisp, the Emacs Lisp Reference
2657Manual}. Its super is the @code{symbol} widget.
2658
2659It has a default value of @code{undecided}.
2660@end deffn
2661
2662@deffn Widget key
2663A widget to represent a key sequence.
2664
2665It uses a special keymap as the @code{:keymap}.
2666@end deffn
1314 2667
1315@node composite 2668@node composite
1316@section Composite Sexp Widgets 2669@subsection Composite Sexp Widgets
1317@cindex composite sexp widgets 2670@cindex composite sexp widgets
1318 2671
1319The syntax for the composite widget construct is: 2672The syntax for the composite widget construct is:
@@ -1327,6 +2680,9 @@ where each @var{component} must be a widget type. Each component widget
1327will be displayed in the buffer, and will be editable by the user. 2680will be displayed in the buffer, and will be editable by the user.
1328 2681
1329@deffn Widget cons 2682@deffn Widget cons
2683A widget to edit cons-cell values. Its super is the @code{group}
2684widget.
2685
1330The value of a @code{cons} widget must be a cons-cell whose @sc{car} 2686The value of a @code{cons} widget must be a cons-cell whose @sc{car}
1331and @sc{cdr} have two specified types. It uses this syntax: 2687and @sc{cdr} have two specified types. It uses this syntax:
1332 2688
@@ -1336,8 +2692,10 @@ and @sc{cdr} have two specified types. It uses this syntax:
1336@end deffn 2692@end deffn
1337 2693
1338@deffn Widget choice 2694@deffn Widget choice
1339The value matched by a @code{choice} widget must have one of a fixed 2695A widget to hold a value of one of a fixed set of types. Its super is
1340set of types. The widget's syntax is as follows: 2696the @code{menu-choice} widget.
2697
2698The widget's syntax is as follows:
1341 2699
1342@example 2700@example
1343@var{type} ::= (choice [@var{keyword} @var{argument}]... @var{type} ... ) 2701@var{type} ::= (choice [@var{keyword} @var{argument}]... @var{type} ... )
@@ -1345,9 +2703,19 @@ set of types. The widget's syntax is as follows:
1345 2703
1346The value of a @code{choice} widget can be anything that matches any of the 2704The value of a @code{choice} widget can be anything that matches any of the
1347@var{types}. 2705@var{types}.
2706
2707This widget only displays the widget that corresponds to the current
2708choice.
2709@end deffn
2710
2711@deffn Widget radio
2712A widget to hold a value of one of a fixed set of options. Its super is
2713the @code{radio-button-choice} widget.
1348@end deffn 2714@end deffn
1349 2715
1350@deffn Widget list 2716@deffn Widget list
2717A widget to edit a list value. Its super is the @code{group} widget.
2718
1351The value of a @code{list} widget must be a list whose element types 2719The value of a @code{list} widget must be a list whose element types
1352match the specified component types: 2720match the specified component types:
1353 2721
@@ -1355,15 +2723,18 @@ match the specified component types:
1355@var{type} ::= (list [@var{keyword} @var{argument}]... @var{component-type}...) 2723@var{type} ::= (list [@var{keyword} @var{argument}]... @var{component-type}...)
1356@end example 2724@end example
1357 2725
1358Thus, @code{(list string number)} matches lists of two elements, 2726Thus, for example, @code{(list string number)} matches lists of two
1359the first being a string and the second being a number. 2727elements, the first being a string and the second being a number.
1360@end deffn 2728@end deffn
1361 2729
1362@deffn Widget vector 2730@deffn Widget vector
2731A widget to edit a vector value. Its super is the @code{group}
2732widget.
2733
1363The @code{vector} widget is like the @code{list} widget but matches 2734The @code{vector} widget is like the @code{list} widget but matches
1364vectors instead of lists. Thus, @code{(vector string number)} matches 2735vectors instead of lists. Thus, for example, @code{(vector string
1365vectors of two elements, the first being a string and the second being 2736number)} matches vectors of two elements, the first being a string and
1366a number. 2737the second being a number.
1367@end deffn 2738@end deffn
1368 2739
1369The above suffice for specifying fixed size lists and vectors. To get 2740The above suffice for specifying fixed size lists and vectors. To get
@@ -1393,8 +2764,12 @@ trying to explain it here, I'll just suggest you meditate over it for
1393a while. 2764a while.
1394 2765
1395@deffn Widget set 2766@deffn Widget set
1396Specifies a type whose values are the lists whose elements all belong 2767A widget to hold a list of members from a fixed set. Its super is the
1397to a given set. The order of elements of the list is not significant. 2768@code{checklist} widget.
2769
2770Its value is a list where the elements all belong to a given set. The
2771order of elements of the list is not significant.
2772
1398Here's the syntax: 2773Here's the syntax:
1399 2774
1400@example 2775@example
@@ -1407,111 +2782,55 @@ Use @code{const} to specify each permitted element, like this:
1407 2782
1408@deffn Widget repeat 2783@deffn Widget repeat
1409Specifies a list of any number of elements that fit a certain type. 2784Specifies a list of any number of elements that fit a certain type.
2785Its super is the @code{editable-list} widget.
1410 2786
1411@example 2787@example
1412@var{type} ::= (repeat [@var{keyword} @var{argument}]... @var{type}) 2788@var{type} ::= (repeat [@var{keyword} @var{argument}]... @var{type})
1413@end example 2789@end example
1414@end deffn 2790@end deffn
1415 2791
1416@node Widget Properties 2792@deffn Widget plist
1417@chapter Properties 2793A widget to edit property lists. Its super is the @code{list} widget.
1418@cindex properties of widgets
1419@cindex widget properties
1420
1421You can examine or set the value of a widget by using the widget object
1422that was returned by @code{widget-create}.
1423
1424@defun widget-value widget
1425Return the current value contained in @var{widget}.
1426It is an error to call this function on an uninitialized widget.
1427@end defun
1428
1429@defun widget-value-set widget value
1430Set the value contained in @var{widget} to @var{value}.
1431It is an error to call this function with an invalid @var{value}.
1432@end defun
1433
1434@strong{Important:} You @emph{must} call @code{widget-setup} after
1435modifying the value of a widget before the user is allowed to edit the
1436widget again. It is enough to call @code{widget-setup} once if you
1437modify multiple widgets. This is currently only necessary if the widget
1438contains an editing field, but may be necessary for other widgets in the
1439future.
1440
1441If your application needs to associate some information with the widget
1442objects, for example a reference to the item being edited, it can be
1443done with @code{widget-put} and @code{widget-get}. The property names
1444must begin with a @samp{:}.
1445
1446@defun widget-put widget property value
1447In @var{widget} set @var{property} to @var{value}.
1448@var{property} should be a symbol, while @var{value} can be anything.
1449@end defun
1450
1451@defun widget-get widget property
1452In @var{widget} return the value for @var{property}.
1453@var{property} should be a symbol, the value is what was last set by
1454@code{widget-put} for @var{property}.
1455@end defun
1456
1457@defun widget-member widget property
1458Non-@code{nil} if @var{widget} has a value (even @code{nil}) for
1459property @var{property}.
1460@end defun
1461
1462@defun widget-apply widget property &rest args
1463Apply the value of @var{property} to @var{widget}, passing @var{args}
1464as additional arguments to the function. Return the result of that
1465function call.
1466@end defun
1467 2794
1468Occasionally it can be useful to know which kind of widget you have, 2795It recognizes the following properties:
1469i.e., the name of the widget type you gave when the widget was created.
1470 2796
1471@defun widget-type widget 2797@table @code
1472Return the name of @var{widget}, a symbol. 2798@item :options
1473@end defun 2799A given set of recommended key-value values for the @code{plist}
1474 2800widget. Each option shows up as a checklist item.
1475@cindex active widget
1476@cindex inactive widget
1477@cindex activate a widget
1478@cindex deactivate a widget
1479Widgets can be in two states: active, which means they are modifiable by
1480the user, or inactive, which means they cannot be modified by the user.
1481You can query or set the state with the following code:
1482 2801
1483@lisp 2802@item :key-type
1484;; Examine if @var{widget} is active or not. 2803The widget type to use for the plist keys. By default, it uses the
1485(if (widget-apply @var{widget} :active) 2804@code{symbol} widget.
1486 (message "Widget is active.")
1487 (message "Widget is inactive.")
1488 2805
1489;; Make @var{widget} inactive. 2806@item :value-type
1490(widget-apply @var{widget} :deactivate) 2807The widget type to use for the plist values. By default, it uses the
2808@code{sexp} widget.
2809@end table
2810@end deffn
1491 2811
1492;; Make @var{widget} active. 2812@deffn Widget alist
1493(widget-apply @var{widget} :activate) 2813A widget to edit association lists. Its super is the @code{list}
1494@end lisp 2814widget.
1495 2815
1496A widget is inactive if it, or any of its ancestors (found by 2816It recognizes the same properties that the @code{plist} widget, with
1497following the @code{:parent} link), have been deactivated. To make sure 2817the difference that the @code{:key-type} uses by default a @code{sexp}
1498a widget is really active, you must therefore activate both it and 2818widget.
1499all its ancestors. 2819@end deffn
1500 2820
1501@lisp 2821Most composite widgets do not allow for recursion. That is, none of
1502(while widget 2822the contained widgets may be of the same type that is currently being
1503 (widget-apply widget :activate) 2823defined. To allow for this kind of widgets, there's the @code{lazy}
1504 (setq widget (widget-get widget :parent))) 2824widget.
1505@end lisp
1506 2825
1507You can check if a widget has been made inactive by examining the value 2826@deffn Widget lazy
1508of the @code{:inactive} keyword. If this is non-@code{nil}, the widget itself 2827A base widget for recursive data structures. Its super is the
1509has been deactivated. This is different from using the @code{:active} 2828@code{default} widget.
1510keyword, in that the latter tells you if the widget @strong{or} any of
1511its ancestors have been deactivated. Do not attempt to set the
1512@code{:inactive} keyword directly. Use the @code{:activate}
1513@code{:deactivate} keywords instead.
1514 2829
2830When instantiated, it contains a single inferior widget of the widget
2831type specified in the @code{:type} property. Its value is the same as
2832the value of this inferior widget.
2833@end deffn
1515 2834
1516@node Defining New Widgets 2835@node Defining New Widgets
1517@chapter Defining New Widgets 2836@chapter Defining New Widgets
@@ -1520,19 +2839,27 @@ its ancestors have been deactivated. Do not attempt to set the
1520 2839
1521You can define specialized widgets with @code{define-widget}. It allows 2840You can define specialized widgets with @code{define-widget}. It allows
1522you to create a shorthand for more complex widgets, including specifying 2841you to create a shorthand for more complex widgets, including specifying
1523component widgets and new default values for the keyword 2842component widgets and new default values for the keyword arguments.
1524arguments.
1525 2843
1526@defun define-widget name class doc &rest args 2844@defun define-widget name class doc &rest args
1527Define a new widget type named @var{name} from @code{class}. 2845Define a new widget type named @var{name} that derives from @var{class}.
1528 2846
1529@var{name} and class should both be symbols, @code{class} should be one 2847@var{name} and @var{class} should both be symbols, and @var{class}
1530of the existing widget types. 2848should be one of the existing widget types.
1531 2849
1532The third argument @var{doc} is a documentation string for the widget. 2850The third argument @var{doc} is a documentation string for the widget.
1533 2851
1534After the new widget has been defined, the following two calls will 2852@var{args} should be key-value pairs, overriding keyword values of
1535create identical widgets: 2853@var{class}, or adding new recognized keywords for @var{name}.
2854
2855Usually, you'll want to derive from an existing widget type, like the
2856@code{editable-field} widget, or the @code{default} widget, but it's
2857also possible to derive from nothing, by passing a value of @code{nil}
2858as @var{class}. Note that if you do this, you're entirely responsible
2859for defining a whole new default behavior for your widgets.
2860
2861After using this function, the following two calls will create
2862identical widgets:
1536 2863
1537@itemize @bullet 2864@itemize @bullet
1538@item 2865@item
@@ -1555,170 +2882,67 @@ in the @code{widget-type} property of @var{name}, which is what
1555If you only want to specify defaults for keywords with no complex 2882If you only want to specify defaults for keywords with no complex
1556conversions, you can use @code{identity} as your conversion function. 2883conversions, you can use @code{identity} as your conversion function.
1557 2884
1558The following additional keyword arguments are useful when defining new 2885When defining new widgets, the @code{:convert-widget} property might
1559widgets: 2886be useful:
2887
1560@table @code 2888@table @code
1561@vindex convert-widget@r{ keyword} 2889@vindex convert-widget@r{ keyword}
1562@item :convert-widget 2890@item :convert-widget
1563Function to convert a widget type before creating a widget of that 2891Function to convert a widget type before creating a widget of that
1564type. It takes a widget type as an argument, and returns the converted 2892type.
1565widget type. When a widget is created, this function is called for the
1566widget type and all the widget's parent types, most derived first.
1567
1568The following predefined functions can be used here:
1569
1570@defun widget-types-convert-widget widget
1571Convert @code{:args} as widget types in @var{widget}.
1572@end defun
1573
1574@defun widget-value-convert-widget widget
1575Initialize @code{:value} from @code{:args} in @var{widget}.
1576@end defun
1577
1578@vindex copy@r{ keyword}
1579@item :copy
1580Function to deep copy a widget type. It takes a shallow copy of the
1581widget type as an argument (made by @code{copy-sequence}), and returns a
1582deep copy. The purpose of this is to avoid having different instances
1583of combined widgets share nested attributes.
1584
1585The following predefined functions can be used here:
1586
1587@defun widget-types-copy widget
1588Copy @code{:args} as widget types in @var{widget}.
1589@end defun
1590
1591@vindex value-to-internal@r{ keyword}
1592@item :value-to-internal
1593Function to convert the value to the internal format. The function
1594takes two arguments, a widget and an external value, and returns the
1595internal value. The function is called on the present @code{:value}
1596when the widget is created, and on any value set later with
1597@code{widget-value-set}.
1598
1599@vindex value-to-external@r{ keyword}
1600@item :value-to-external
1601Function to convert the value to the external format. The function
1602takes two arguments, a widget and an internal value, and returns the
1603external value.
1604
1605@vindex create@r{ keyword}
1606@item :create
1607Function to create a widget from scratch. The function takes one
1608argument, a widget type, and creates a widget of that type, inserts it
1609in the buffer, and returns a widget object.
1610
1611@vindex delete@r{ keyword}
1612@item :delete
1613Function to delete a widget. The function takes one argument, a widget,
1614and should remove all traces of the widget from the buffer.
1615 2893
1616The default value is: 2894It takes a widget type as an argument, and returns the converted
2895widget type. When a widget is created, this function is called for
2896the widget type and all the widget's parent types, most derived first.
1617 2897
1618@defun widget-default-delete widget 2898The predefined functions @code{widget-types-convert-widget} and
1619Remove @var{widget} from the buffer. 2899@code{widget-value-convert-widget} can be used here.
1620Delete all @code{:children} and @code{:buttons} in @var{widget}.
1621@end defun
1622
1623In most cases you should not change this value, but instead use
1624@code{:value-delete} to make any additional cleanup.
1625
1626@vindex value-create@r{ keyword}
1627@item :value-create
1628Function to expand the @samp{%v} escape in the format string. It will
1629be called with the widget as its argument and should insert a
1630representation of the widget's value in the buffer.
1631
1632Nested widgets should be listed in @code{:children} or @code{:buttons}
1633to make sure they are automatically deleted.
1634
1635@vindex value-delete@r{ keyword}
1636@item :value-delete
1637Should remove the representation of the widget's value from the buffer.
1638It will be called with the widget as its argument. It doesn't have to
1639remove the text, but it should release markers and delete nested widgets
1640if these are not listed in @code{:children} or @code{:buttons}.
1641
1642@vindex value-get@r{ keyword}
1643@item :value-get
1644Function to extract the value of a widget, as it is displayed in the
1645buffer.
1646
1647The following predefined function can be used here:
1648
1649@defun widget-value-value-get widget
1650Return the @code{:value} property of @var{widget}.
1651@end defun
1652
1653@vindex format-handler@r{ keyword}
1654@item :format-handler
1655Function to handle unknown @samp{%} escapes in the format string. It
1656will be called with the widget and the character that follows the
1657@samp{%} as arguments. You can set this to allow your widget to handle
1658non-standard escapes.
1659
1660@findex widget-default-format-handler
1661You should end up calling @code{widget-default-format-handler} to handle
1662unknown escape sequences, which will handle the @samp{%h} and any future
1663escape sequences, as well as give an error for unknown escapes.
1664
1665@vindex action@r{ keyword}
1666@item :action
1667Function to handle user initiated events. By default, @code{:notify}
1668the parent.
1669
1670The following predefined function can be used here:
1671
1672@defun widget-parent-action widget &optional event
1673Tell @code{:parent} of @var{widget} to handle the @code{:action}.
1674Optional @var{event} is the event that triggered the action.
1675@end defun
1676
1677@vindex prompt-value@r{ keyword}
1678@item :prompt-value
1679Function to prompt for a value in the minibuffer. The function should
1680take four arguments, @var{widget}, @var{prompt}, @var{value}, and
1681@var{unbound} and should return a value for widget entered by the user.
1682@var{prompt} is the prompt to use. @var{value} is the default value to
1683use, unless @var{unbound} is non-@code{nil}, in which case there is no default
1684value. The function should read the value using the method most natural
1685for this widget, and does not have to check that it matches.
1686@end table 2900@end table
1687 2901
1688If you want to define a new widget from scratch, use the @code{default} 2902@node Inspecting Widgets
1689widget as its base. 2903@chapter Inspecting Widgets
1690
1691@deffn Widget default
1692Widget used as a base for other widgets.
1693
1694It provides most of the functionality that is referred to as ``by
1695default'' in this text.
1696@end deffn
1697
1698@node Widget Browser
1699@chapter Widget Browser
1700@cindex widget browser 2904@cindex widget browser
1701 2905
1702There is a separate package to browse widgets. This is intended to help 2906There is a separate package to browse widgets, in
1703programmers who want to examine the content of a widget. The browser 2907@samp{wid-browse.el}. This is intended to help programmers who want
1704shows the value of each keyword, but uses links for certain keywords 2908to examine the content of a widget. The browser shows the value of
1705such as @samp{:parent}, which avoids printing cyclic structures. 2909each keyword, but uses links for certain keywords such as
2910@samp{:parent}, which avoids printing cyclic structures.
1706 2911
1707@deffn Command widget-browse @var{widget} 2912@deffn Command widget-browse @var{widget}
1708Create a widget browser for @var{widget}. 2913Create a widget browser for @var{widget}.
2914
1709When called interactively, prompt for @var{widget}. 2915When called interactively, prompt for @var{widget}.
1710@end deffn 2916@end deffn
1711 2917
1712@deffn Command widget-browse-other-window @var{widget} 2918@deffn Command widget-browse-other-window @var{widget}
1713Create a widget browser for @var{widget} and show it in another window. 2919Create a widget browser for @var{widget} and show it in another window.
2920
1714When called interactively, prompt for @var{widget}. 2921When called interactively, prompt for @var{widget}.
1715@end deffn 2922@end deffn
1716 2923
1717@deffn Command widget-browse-at @var{pos} 2924@deffn Command widget-browse-at @var{pos}
1718Create a widget browser for the widget at @var{pos}. 2925Create a widget browser for the widget at @var{pos}.
2926
1719When called interactively, use the position of point. 2927When called interactively, use the position of point.
1720@end deffn 2928@end deffn
1721 2929
2930In addition, there's a function to describe the widget at point.
2931
2932@deffn Command widget-describe &optional widget-or-pos
2933Describe the widget at point.
2934
2935When called from Lisp, @var{widget-or-pos} might be the widget to
2936describe or a buffer position where a widget is present. If
2937@var{widget-or-pos} is @code{nil}, the widget to describe is the
2938widget at point.
2939
2940This command sets up a help buffer for providing information about the
2941widget, mainly its @code{:action} and @code{:mouse-down-action}
2942functions, and provides links to describe it in more detail using the
2943@code{widget-browse} commands described above.
2944@end deffn
2945
1722@node Widget Minor Mode 2946@node Widget Minor Mode
1723@chapter Widget Minor Mode 2947@chapter Widget Minor Mode
1724@cindex widget minor mode 2948@cindex widget minor mode
@@ -1740,14 +2964,24 @@ Keymap used in @code{widget-minor-mode}.
1740@chapter Utilities 2964@chapter Utilities
1741@cindex utility functions for widgets 2965@cindex utility functions for widgets
1742 2966
2967Here we describe some utility functions that don't really have a place
2968earlier in this manual.
2969
1743@defun widget-prompt-value widget prompt [ value unbound ] 2970@defun widget-prompt-value widget prompt [ value unbound ]
1744Prompt for a value matching @var{widget}, using @var{prompt}. 2971Prompt for a value matching @var{widget}, using @var{prompt}.
1745The current value is assumed to be @var{value}, unless @var{unbound} is 2972The current value is assumed to be @var{value}, unless @var{unbound} is
1746non-@code{nil}. 2973non-@code{nil}.
2974
2975Converts @var{widget} before prompting, and for prompting it uses the
2976@code{:prompt-value} function. This function returns the user
2977``answer'', and it's an error if that answer doesn't match the widget,
2978as with the @code{:match} function.
2979
2980If the answer matches the widget, returns the answer.
1747@end defun 2981@end defun
1748 2982
1749@defun widget-get-sibling widget 2983@defun widget-get-sibling widget
1750Get the item which @var{widget} is assumed to toggle. 2984Get the item which @var{widget} should toggle.
1751This is only meaningful for radio buttons or checkboxes in a list. 2985This is only meaningful for radio buttons or checkboxes in a list.
1752@end defun 2986@end defun
1753 2987
@@ -1773,6 +3007,142 @@ the form (@var{name} . @var{value}) (i.e., the simplified format),
1773then the return value is the @var{value} of the chosen element. 3007then the return value is the @var{value} of the chosen element.
1774@end defun 3008@end defun
1775 3009
3010@defun widget-image-find image
3011Create a graphical button from @var{image}, an image or a file name
3012sans extension.
3013
3014If @var{image} is a file name, the file should be in
3015@code{widget-image-directory}, or in a place where @code{find-image}
3016will find it.
3017@end defun
3018
3019@defun widget-image-insert widget tag image
3020As part of @var{widget}, insert the text @var{tag} or, if supported,
3021the image @var{image}.
3022
3023@var{image} should be as described in @code{widget-image-find}.
3024@end defun
3025
3026@defun widget-echo-help pos
3027Display help-echo text for the widget at @var{pos}.
3028
3029Uses the value of @code{:help-echo}. If it is a function, it calls it
3030to get a string. Otherwise, it @code{eval}s it.
3031@end defun
3032
3033@node Customization
3034@chapter Customization
3035This chapter is about the customization options for the Widget
3036library, for the end user.
3037
3038@deffn Face widget-field-face
3039Face used for other editing fields.
3040@end deffn
3041
3042@deffn Face widget-button-face
3043Face used for buttons.
3044@end deffn
3045
3046@defopt widget-mouse-face
3047Face used for highlighting a button when the mouse pointer moves
3048across it.
3049
3050The default value is @code{highlight}.
3051@end defopt
3052
3053@defopt widget-image-directory
3054Directory where Widget should look for images.
3055
3056Widget will look here for a file with the same name as specified for the
3057image, with either a @file{.xpm} (if supported) or @file{.xbm} extension.
3058@end defopt
3059
3060@defopt widget-image-enable
3061If non-@code{nil}, allow images to appear on displays where they are supported.
3062@end defopt
3063
3064@defopt widget-image-conversion
3065An alist to convert symbols from image formats to file name suffixes.
3066
3067Each element is a cons cell (@var{format} . @var{suffix}), where
3068@var{format} is a symbol that represents an image format and
3069@var{suffix} is its correspondent suffix.
3070@end defopt
3071
3072@defopt widget-button-prefix
3073String to prefix buttons.
3074@end defopt
3075
3076@defopt widget-button-suffix
3077String to suffix buttons.
3078@end defopt
3079
3080@defopt widget-push-button-prefix
3081String to prefix push buttons.
3082@end defopt
3083
3084@defopt widget-push-button-suffix
3085String to suffix push buttons.
3086@end defopt
3087
3088@defopt widget-link-prefix
3089String to prefix links.
3090@end defopt
3091
3092@defopt widget-link-suffix
3093String to suffix links.
3094@end defopt
3095
3096@defopt widget-choice-toggle
3097If non-@code{nil}, toggle when there are just two options.
3098
3099By default, its value is @code{nil}.
3100@end defopt
3101
3102@defopt widget-documentation-links
3103If non-@code{nil}, add hyperlinks to documentation strings.
3104@end defopt
3105
3106@defopt widget-documentation-link-regexp
3107A regexp that matches potential links in documentation strings. The
3108link itself should match to the first group.
3109@end defopt
3110
3111@defopt widget-documentation-link-p
3112A predicate function to test if a string is useful as a link. The
3113function is called with one argument, a string, and should return
3114non-@code{nil} if there should be a link for that string.
3115
3116By default, the value is @code{intern-soft}.
3117@end defopt
3118
3119@defopt widget-documentation-link-type
3120A symbol that represents a widget type to use for links in
3121documentation strings.
3122
3123By default, the value is @code{documentation-link}.
3124@end defopt
3125
3126@defopt widget-menu-max-size
3127Maximum size for a popup menu. By default, its value is 40.
3128
3129If a function ask you to choose from a menu that is larger than this
3130value, it will use the minibuffer.
3131@end defopt
3132
3133@defopt widget-menu-max-shortcuts
3134Largest number of items for which it works to choose one with a
3135character.
3136
3137For a larger number, use the minibuffer.
3138@end defopt
3139
3140@defopt widget-menu-minibuffer-flag
3141Whether to use the minibuffer to ask for a choice.
3142
3143If @code{nil}, the default, read a single character.
3144@end defopt
3145
1776@node Widget Wishlist 3146@node Widget Wishlist
1777@chapter Wishlist 3147@chapter Wishlist
1778@cindex todo 3148@cindex todo
@@ -1809,15 +3179,6 @@ Find a way to disable mouse highlight for inactive widgets.
1809Find a way to make glyphs look inactive. 3179Find a way to make glyphs look inactive.
1810 3180
1811@item 3181@item
1812Add @code{property-list} widget.
1813
1814@item
1815Add @code{association-list} widget.
1816
1817@item
1818Add @code{key-binding} widget.
1819
1820@item
1821Add @code{widget} widget for editing widget specifications. 3182Add @code{widget} widget for editing widget specifications.
1822 3183
1823@item 3184@item