You can define specialized widgets with define-widget. It allows
you to create a shorthand for more complex widgets. This includes
specifying component widgets and new default values for the keyword
arguments.
Define a new widget type named name from
class.name and class should both be symbols,
classshould be one of the existing widget types.The third argument DOC is a documentation string for the widget.
After the new widget has been defined the following two calls will create identical widgets:
(widget-create name) (apply widget-create class args)
Using define-widget just stores the definition of the widget type
in the widget-type property of name, which is what
widget-create uses.
If you just want to specify defaults for keywords with no complex
conversions, you can use identity as your :convert-widget
function.
The following additional keyword arguments are useful when defining new widgets:
:convert-widgetwidget-convert. Typical operations
include converting types of child widgets to widget instances and
converting values from external format (i.e., as expected by the
calling code) to internal format (which is often different for the
convenience of widget manipulation). It takes a widget type as an
argument, and returns the converted widget type. When a widget is
created, the value of this property is called for the widget type, then
for all the widget's parent types, most derived first. (The property is
reevaluated for each parent type.)
The following predefined functions can be used here:
Convert each member of
:argsin widget from a widget type to a widget.
Initialize
:valuefrom(car :args)in widget, and reset:args.
:copywidget-copy uses copy-sequence to
ensure that the top-level list is a copy.) This particularly applies to
child widgets.
:value-to-internal:value
when the widget is created, and on any value set later with
widget-value-set.
:value-to-external:value
when the widget is created, and on any value set later with
widget-value-set.
:createwidget-create or related
functions, which take a type argument, (usually) convert it to a widget,
call the :create function to insert it in the buffer, and then
return the (possibly converted) widget.
The default, widget-default-create, is invariably appropriate.
(None of the standard widgets specify :create.)
:delete:value-create:value-deleteThe following predefined function can be used here:
:value-getThe following predefined function can be used here:
:format-handlerYou should end up calling widget-default-format-handler to handle
unknown escape sequences. It will handle the ‘%h’ and any future
escape sequences as well as give an error for unknown escapes.
:action:notify
the parent. Actions normally do not include mere edits, but refer to
things like invoking buttons or hitting enter in an editable field. To
watch for any change, redefine the :notify callback.
The following predefined function can be used here:
Tell
:parentof widget to handle the:action.
Optional event is the event that triggered the action.
:prompt-valueIf you want to define a new widget from scratch, use the default
widget as its base.
Widget used as a base for other widgets.
It provides most of the functionality that is referred to as “by default” in this text.
In implementing complex hierarchical widgets (e.g., using the ‘group’ widget), the following functions may be useful. The syntax for the type arguments to these functions is described in Basic Types.
As a child of parent, create a widget with type type and value value. type is copied, and the
:widget-contvertmethod is applied to the optional keyword arguments from args.
As a child of parent, create a widget with type type. type is copied, but no conversion method is applied.
As a child of parent, create a widget with type type and value value. type is copied, but no conversion method is applied.
Convert type to a widget without inserting it in the buffer. The optional args are additional keyword arguments.
The widget's
:argsproperty is set from the longest tail of args whose ‘cdr’ is not a keyword, or if that is null, from the longest tail of type's:argsproperty whose cdr is not a keyword. Keyword arguments from args are set, and the:valueproperty (if any) is converted from external to internal format.
widget-convert is typically not called from user code; rather it
is called implicitly through the ‘widget-create*’ functions.