| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You can define specialized widgets with define-widget. It allows
you to create a shorthand for more complex widgets, including specifying
component widgets and new default values for the keyword
arguments.
class.
name and class should both be symbols, class should 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 only 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-widget
widget-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:
:args in widget from a widget type
to a widget.
:value from (car :args) in widget, and
reset :args.
:copy
copy-sequence), and returns a
deep copy. The purpose of this is to avoid having different instances
of combined widgets share nested attributes. Any member of the
widget which might be changed in place (rather than replaced) should be
copied by this method. (widget-copy uses copy-sequence to
ensure that the top-level list is a copy.) This particularly applies to
child widgets.
The following predefined functions can be used here:
:args as widget types in widget.
: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.
:create
widget-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
The default value is:
:children and :buttons in widget.
In most cases you should not change this value, but instead use
:value-delete to make any additional cleanup.
:value-create
Nested widgets should be listed in :children or :buttons
to make sure they are automatically deleted.
:value-delete
:children or :buttons.
:value-get
The following predefined function can be used here:
:value property of widget.
:format-handler
You 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:
:parent of widget to handle the :action.:prompt-value
nil, in which case there is no default
value. The function should read the value using the method most natural
for this widget and does not have to check whether it matches.
If you want to define a new widget from scratch, use the default
widget as its base.
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 1.4 Basic Types.
:widget-convert
method is applied to the optional keyword arguments from args.
The widget's :args property 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 :args property whose cdr is not
a keyword. Keyword arguments from args are set, and the
:value property (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.
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |