(symbolp (car widget))
(get (car widget) 'widget-type))))
+;;;###autoload
+(defun widget-put (widget property value)
+ "In WIDGET, set PROPERTY to VALUE.
+The value can later be retrieved with `widget-get'."
+ (setcdr widget (plist-put (cdr widget) property value)))
+
+;;;###autoload
+(defun widget-get (widget property)
+ "In WIDGET, get the value of PROPERTY.
+The value could either be specified when the widget was created, or
+later with `widget-put'."
+ (let (tmp)
+ (catch 'found
+ (while widget
+ (cond ((and (setq tmp (plist-member (cdr widget) property))
+ (consp tmp))
+ (throw 'found (cadr tmp)))
+ ((setq tmp (widget-type widget))
+ (setq widget (get tmp 'widget-type)))
+ (t
+ (throw 'found nil)))))))
+
(defun widget-get-indirect (widget property)
"In WIDGET, get the value of PROPERTY.
If the value is a symbol, return its binding.
(widget-member (get (car widget) 'widget-type) property))
(t nil)))
+;;;###autoload
+(defun widget-apply (widget property &rest args)
+ "Apply the value of WIDGET's PROPERTY to the widget itself.
+Return the result of applying the value of PROPERTY to WIDGET.
+ARGS are passed as extra arguments to the function."
+ (apply (widget-get widget property) widget args))
+
(defun widget-value (widget)
"Extract the current value of WIDGET."
(widget-apply widget
return feature;
}
-\f
-/* Primitives for work of the "widget" library.
- In an ideal world, this section would not have been necessary.
- However, lisp function calls being as slow as they are, it turns
- out that some functions in the widget library (wid-edit.el) are the
- bottleneck of Widget operation. Here is their translation to C,
- for the sole reason of efficiency. */
-
-DEFUN ("widget-put", Fwidget_put, Swidget_put, 3, 3, 0,
- doc: /* In WIDGET, set PROPERTY to VALUE.
-The value can later be retrieved with `widget-get'. */)
- (Lisp_Object widget, Lisp_Object property, Lisp_Object value)
-{
- CHECK_CONS (widget);
- XSETCDR (widget, plist_put (XCDR (widget), property, value));
- return value;
-}
-
-DEFUN ("widget-get", Fwidget_get, Swidget_get, 2, 2, 0,
- doc: /* In WIDGET, get the value of PROPERTY.
-The value could either be specified when the widget was created, or
-later with `widget-put'. */)
- (Lisp_Object widget, Lisp_Object property)
-{
- Lisp_Object tmp;
-
- while (1)
- {
- if (NILP (widget))
- return Qnil;
- CHECK_CONS (widget);
- tmp = plist_member (XCDR (widget), property);
- if (CONSP (tmp))
- {
- tmp = XCDR (tmp);
- return CAR (tmp);
- }
- tmp = XCAR (widget);
- if (NILP (tmp))
- return Qnil;
- widget = Fget (tmp, Qwidget_type);
- }
-}
-
-DEFUN ("widget-apply", Fwidget_apply, Swidget_apply, 2, MANY, 0,
- doc: /* Apply the value of WIDGET's PROPERTY to the widget itself.
-Return the result of applying the value of PROPERTY to WIDGET.
-ARGS are passed as extra arguments to the function.
-usage: (widget-apply WIDGET PROPERTY &rest ARGS) */)
- (ptrdiff_t nargs, Lisp_Object *args)
-{
- Lisp_Object widget = args[0];
- Lisp_Object property = args[1];
- Lisp_Object propval = Fwidget_get (widget, property);
- Lisp_Object trailing_args = Flist (nargs - 2, args + 2);
- Lisp_Object result = CALLN (Fapply, propval, widget, trailing_args);
- return result;
-}
+\f
#ifdef HAVE_LANGINFO_CODESET
#include <langinfo.h>
#endif
defsubr (&Srequire);
defsubr (&Sprovide);
defsubr (&Splist_member);
- defsubr (&Swidget_put);
- defsubr (&Swidget_get);
- defsubr (&Swidget_apply);
defsubr (&Sbase64_encode_region);
defsubr (&Sbase64_decode_region);
defsubr (&Sbase64_encode_string);
(require 'ert)
(require 'wid-edit)
+(ert-deftest widget-test-editable-field-widget-get/put ()
+ (with-temp-buffer
+ (let ((widget (widget-create 'editable-field
+ :size 13
+ :format "Name: %v "
+ "My Name")))
+ (should (eq (widget-get widget :size) 13))
+ (should (equal (widget-get widget :format) "Name: %v "))
+ (widget-put widget :size 1)
+ (widget-put widget :format "foo")
+ (should (eq (widget-get widget :size) 1))
+ (should (equal (widget-get widget :format) "foo")))))
+
(ert-deftest widget-at ()
- "Test `widget-at' behavior."
(with-temp-buffer
(should-not (widget-at))
(let ((marco (widget-create 'link "link widget"))