1 (in-package :lisp-on-lines
)
3 (define-description T
()
5 :function
(lambda (object)
7 (substitute #\Space
#\-
11 (identity :label nil
:function
#'identity
)
12 (type :label
"Type" :function
#'type-of
)
13 (class :label
"Class" :function
#'class-of
)
14 (active-attributes :label
"Attributes"
18 (attribute-delimiter :label
"Attribute Delimiter"
22 (active-descriptions :label
"Active Descriptions"
26 (inactive-descriptions :label
"Inactive Descriptions"
30 (label-formatter :value
(lambda (label)
31 (generic-format *display
* "~A:" label
))
33 (value-formatter :value
(curry #'format nil
"~A")
36 (define-layered-method description-of
(any-lisp-object)
37 (find-description 't
))
39 (define-layered-function display-attribute
(attribute)
41 (display-using-description attribute
*display
* (attribute-object attribute
))))
44 (define-layered-function display-attribute-label
(attribute)
46 (funcall (attribute-label-formatter attribute
) (attribute-label attribute
))))
48 (define-layered-function display-attribute-value
(attribute)
50 (flet ((disp (val &rest args
)
51 (apply #'display
*display
* val
52 :activate
(attribute-active-descriptions attribute
)
53 :deactivate
(attribute-inactive-descriptions attribute
)
56 (let ((val (attribute-value attribute
)))
57 (if (and (not (slot-boundp attribute
'active-attributes
))
58 (eql val
(attribute-object attribute
)))
59 (generic-format *display
* (funcall (attribute-value-formatter attribute
) val
))
60 (with-active-descriptions (inline)
61 (cond ((slot-value attribute
'value-formatter
)
62 (generic-format *display
* (funcall (attribute-value-formatter attribute
) val
)))
63 ((slot-boundp attribute
'active-attributes
)
64 (disp val
:attributes
(slot-value attribute
'active-attributes
)))
68 (define-layered-method display-using-description
69 ((attribute standard-attribute
) display object
&rest args
)
70 (declare (ignore args
))
71 (when (attribute-label attribute
)
72 (display-attribute-label attribute
))
73 (display-attribute-value attribute
))
75 (define-layered-method display-attribute
:around
76 ((attribute standard-attribute
))
77 (funcall-with-layer-context
78 (modify-layer-context (current-layer-context)
79 :activate
(attribute-active-descriptions attribute
)
80 :deactivate
(attribute-inactive-descriptions attribute
))
84 (define-layered-method display-attribute
:before
85 ((attribute standard-attribute
))
88 (define-display ((description t
))
89 (let ((attributes (attributes description
)))
90 (display-attribute (first attributes
))
91 (dolist (attribute (rest attributes
) (values))
92 (generic-format *display
*
94 (find-attribute description
'attribute-delimiter
)))
95 (display-attribute attribute
))))
98 (define-display :around
((description t
) (display null
) object
)
99 (with-output-to-string (*standard-output
*)
100 (call-next-layered-method description t object
))