You can examine or set the value of a widget by using the widget object
that was returned by widget-create
.
Important: You must call widget-setup
after
modifying the value of a widget before the user is allowed to edit the
widget again. It is enough to call widget-setup
once if you
modify multiple widgets. This is currently only necessary if the widget
contains an editing field, but may be necessary for other widgets in the
future.
If your application needs to associate some information with the widget
objects, for example a reference to the item being edited, it can be
done with widget-put
and widget-get
. The property names
must begin with a `:'.
widget-put
for property.
Occasionally it can be useful to know which kind of widget you have, i.e. the name of the widget type you gave when the widget was created.
Widgets can be in two states: active, which means they are modifiable by the user, or inactive, which means they cannot be modified by the user. You can query or set the state with the following code:
;; Examine if widget is active or not. (if (widget-apply widget :active) (message "Widget is active.") (message "Widget is inactive.") ;; Make widget inactive. (widget-apply widget :deactivate) ;; Make widget active. (widget-apply widget :activate)
A widget is inactive if itself, or any of its ancestors (found by
following the :parent
link) have been deactivated. To make sure
a widget is really active, you must therefore activate both itself, and
all its ancestors.
(while widget (widget-apply widget :activate) (setq widget (widget-get widget :parent)))
You can check if a widget has been made inactive by examining the value
of :inactive
keyword. If this is non-nil, the widget itself has
been deactivated. This is different from using the :active
keyword, in that the later tell you if the widget or any of its
ancestors have been deactivated. Do not attempt to set the
:inactive
keyword directly. Use the :activate
:deactivated
keywords instead.
Go to the first, previous, next, last section, table of contents.