+(defun widget-path (widget)
+ (let ((subpath (list (if (and
+ (slot-boundp widget 'name)
+ (not (zerop (length (widget-name widget)))))
+ (widget-name widget)
+ (type-of widget)))))
+ (if (slot-boundp widget 'parent)
+ (nconc (widget-path (widget-parent widget)) subpath)
+ subpath)))
+
+(defun widget-class-path (widget)
+ (let ((subpath (list (type-of widget))))
+ (if (slot-boundp widget 'parent)
+ (nconc (widget-class-path (widget-parent widget)) subpath)
+ subpath)))
+
+
+(defun widget-path-lookup (path &optional (root (nreverse (window-list-toplevels))) (error-p t))
+ (let ((component (first path)))
+ (loop
+ for widget in (mklist root)
+ do (when (or
+ (and
+ (stringp component) (slot-boundp widget 'name)
+ (string= component (widget-name widget)))
+ (and
+ (symbolp component) (typep widget component)))
+ (cond
+ ((endp (rest path)) (return widget))
+ ((typep widget 'container)
+ (let ((descendant (widget-path-lookup (rest path) (container-children widget) nil)))
+ (when descendant
+ (return descendant))))))))
+ (when error-p
+ (error "Widget not found: ~A" path)))
+
+
+(defun widget-find (name &optional (root (nreverse (window-list-toplevels))) (error-p t))
+ "Search for a widget with the given name. ROOT should be a container
+widget or a list of containers."
+ (loop
+ for widget in (mklist root)
+ do (cond
+ ((and (slot-boundp widget 'name) (string= name (widget-name widget)))
+ (return-from widget-find widget))
+ ((typep widget 'container)
+ (let ((descendant (widget-find name (container-children widget) nil)))
+ (when descendant
+ (return-from widget-find descendant))))))
+ (when error-p
+ (error "Widget not found: ~A" name)))