added ROFL test cases + extra formatting hooks for attributes
[clinton/lisp-on-lines.git] / src / standard-descriptions / t.lisp
... / ...
CommitLineData
1(in-package :lisp-on-lines)
2
3(define-description T ()
4 ((identity :label nil :function #'identity)
5 (type :label "Type of" :function #'type-of)
6 (class :label "Class" :function #'class-of)
7 (active-attributes :label "Attributes"
8 :value nil
9 :activep nil
10 :keyword :attributes)
11 (attribute-delimiter :label "Attribute Delimiter"
12 :value "~%"
13 :activep nil
14 :keyword :delimter)
15 (active-descriptions :label "Active Descriptions"
16 :value nil
17 :activep nil
18 :keyword :activate)
19 (inactive-descriptions :label "Inactive Descriptions"
20 :value nil
21 :activep nil
22 :keyword :deactivate)
23 (label-formatter :value (curry #'format nil "~A "))
24 (value-formatter :value (curry #'format nil "~A"))))
25
26(define-layered-method description-of (any-lisp-object)
27 (find-description 't))
28
29(define-layered-function display-attribute (attribute)
30 (:method (attribute)
31 (display-using-description attribute *display* (attribute-object attribute))))
32
33(define-layered-function display-attribute-label (attribute)
34 (:method (attribute)
35 (princ (funcall (attribute-label-formatter attribute) (attribute-label attribute))
36 *display*)))
37
38
39(define-layered-function display-attribute-value (attribute)
40 (:method (attribute)
41 (flet ((disp (val &rest args)
42 (apply #'display *display* val
43 :activate (attribute-active-descriptions attribute)
44 :deactivate (attribute-inactive-descriptions attribute)
45 args)))
46
47 (let ((val (attribute-value attribute)))
48 (if (eql val (attribute-object attribute))
49 (generic-format *display* (funcall (attribute-value-formatter attribute) val))
50 (with-active-descriptions (inline)
51 (if (slot-boundp attribute 'active-attributes)
52 (disp val :attributes (slot-value attribute 'active-attributes))
53 (disp val))))))))
54
55(define-layered-method display-using-description
56 ((attribute standard-attribute) display object &rest args)
57 (declare (ignore args))
58 (when (attribute-label attribute)
59 (display-attribute-label attribute))
60 (display-attribute-value attribute))
61
62(define-display ((description t))
63 (let ((attributes (attributes description)))
64 (display-attribute (first attributes))
65 (dolist (attribute (rest attributes))
66 (generic-format *display*
67 (attribute-value
68 (find-attribute description 'attribute-delimiter)))
69 (display-attribute attribute))))
70
71
72(define-display :around ((description t) (display null))
73 (with-output-to-string (*display*)
74 (print (call-next-method) *display*)))
75
76
77
78