1 (in-package :lisp-on-lines
)
3 (define-layered-function display-using-description
(description object component
)
4 ; (:argument-precedence-order )
5 (:method-combination wrapping-standard
)
7 "Render the object in component,
8 using DESCRIPTION, which is an occurence, an attribute, or something else entirely."))
10 (define-layered-method
11 display-using-description
(d o c
)
12 (<:as-html
"default :" o
))
14 (defmethod find-layer-for-type (type)
18 (define-layered-function display
(component object
&rest args
)
20 "Displays OBJECT in COMPONENT."))
22 (define-layered-method display
((component t
) (object t
)
24 &key type
(line #'line-in
)
26 " The default display dispatch method
28 DISPLAY takes two required arguments,
29 COMPONENT : The component to display FROM (not neccesarily 'in')
30 OBJECT : The 'thing' we want to display... in this case it's the component
32 DISPLAY also takes keywords arguments which modify the DESCRIPTION,
33 that is to say the parameters that come together to create the output.
35 The default display calls out via FUNCALL-WITH-LAYERS to tche DISPLAY-USING-DESCRIPTION method."
37 (let* ((description (find-occurence object
)))
40 (dletf (((description.type description
) type
)
41 ((attributes description
) (or
42 (attributes description
)
43 (list-slots object
))))
44 ;; apply the default line to the description
45 (funcall-with-description
48 ;; apply the passed in arguments and call display-using-description
50 (funcall-with-description
53 #'display-using-description description object component
))))
54 (error "no description for ~A" object
))))
59 (defun funcall-with-description (description properties function
&rest args
)
62 (dletf* (((description.type description
) (or
63 (getf properties
:type
)
64 (description.type description
)))
66 ((description.layers description
) (append
67 (description.layers description
)
68 (getf properties
:layers
)))
69 ((description.properties description
) (append (description.properties description
) properties
)))
71 (description.layers description
)
73 (contextl::funcall-with-special-initargs
74 (list (cons description properties
))
76 (apply function args
))))))
77 (apply function args
)))
81 (defmacro with-description
((description &rest properties
) &body body
)
82 `(funcall-with-description ,description
(if ',(cdr properties
)
88 (define-layered-function find-do-attributes
(desc))
90 (define-layered-method find-do-attributes
((description description
))
94 :in
(attributes description
)
95 :collect
(let ((default (find (car (ensure-list att
))
96 (default-attributes description
)
100 (defmacro do-attributes
((var description
&optional
(attributes `(find-do-attributes ,description
))) &body body
)
101 (with-unique-names (att properties type
)
102 `(dolist* (,att
,attributes
)
103 (let* ((,att
(ensure-list ,att
))
104 (,properties
(rest ,att
))
105 (,type
(getf ,properties
:type
))
106 (,var
(let ((a (find-attribute ,description
(first ,att
))))
108 (apply #'make-attribute
:name
(first ,att
) :type
,type
,properties
)
109 (if a a
(make-attribute :name
(first ,att
) :slot-name
(first ,att
)))))))
110 (funcall-with-description ,var
,properties
114 (defmacro with-component
((component) &body body
)
115 `(let ((self ,component
))
116 (declare (ignorable self
))
117 (flet ((display* (thing &rest args
)
118 (apply #'display
,component thing args
))
119 (display-attribute (attribute obj
&optional props
)
121 (funcall-with-description
123 #'display-using-description attribute obj
,component
)
124 (display-using-description attribute obj
,component
))))
125 (declare (ignorable #'display
* #'display-attribute
))
128 (defmacro defdisplay
(&body body
)
129 (loop with in-layerp
= (eq (car body
) :in-layer
)
130 with layer
= (if in-layerp
(cadr body
) 't
)
131 for tail on
(if in-layerp
(cddr body
) body
)
132 until
(listp (car tail
))
133 collect
(car tail
) into qualifiers
135 (when (member :in-layer qualifiers
)
136 (error "Incorrect occurrence of :in-layer in defdisplay. Must occur before qualifiers."))
138 (destructuring-bind (description &optional object component
) (car tail
)
139 (with-unique-names (d c
)
140 (let (standard-description-p)
141 `(define-layered-method
142 display-using-description
147 (setf object description
)
152 (setf d
(car description
))
156 (setf standard-description-p t
)
163 (setf c
(car component
))