+ (let* ((active-attributes
+ (find-attribute description 'active-attributes))
+ (attributes (when active-attributes
+ (ignore-errors (attribute-value active-attributes)))))
+ (remove-if-not
+ (lambda (attribute)
+ (and attribute
+ (attribute-active-p attribute)
+ (some #'layer-active-p
+ (mapcar #'find-layer
+ (slot-definition-layers
+ (attribute-effective-attribute-definition attribute))))))
+ (if attributes
+ (mapcar (lambda (spec)
+ (find-attribute
+ description
+ (if (listp spec)
+ (car spec)
+ spec)))
+ attributes)
+ (description-attributes description))))))
+
+
+(defun funcall-with-described-object (function object description &rest args)
+ (setf description (or description (description-of object)))
+ (let ((*description* description)
+ (*object* object))
+ (dletf (((described-object *description*) object))
+ (funcall-with-layer-context
+ (modify-layer-context
+ (if (standard-description-p *description*)
+ (adjoin-layer *description* (current-layer-context))
+ (current-layer-context))
+ :activate (description-active-descriptions *description*)
+ :deactivate (description-inactive-descriptions *description*))
+ (lambda () (contextl::funcall-with-special-initargs
+ (loop
+ :for (key val) :on args :by #'cddr
+ :collect (list (find key (description-attributes *description*)
+ :key #'attribute-keyword)
+ :value val))
+ (lambda ()
+ (contextl::funcall-with-special-initargs
+ (let ((attribute (ignore-errors (find-attribute *description* 'active-attributes))))
+ (when attribute
+ (loop for spec in (attribute-value attribute)
+ if (listp spec)
+ collect (cons (or
+ (find-attribute *description* (car spec))
+ (error "No attribute matching ~A" (car spec)))
+ (cdr spec)))))
+ function))))))))
+
+
+(defmacro with-described-object ((object description &rest args)
+ &body body)
+ `(funcall-with-described-object
+ (lambda () ,@body)
+ ,object
+ ,description
+ ,@args))
+