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 (defun make-display-function (component object
16 &key type
(line #'line-in
)
18 "returns a function that expects a 3 argument function as its argument
20 The function (which is usually display-using-description) will be called with the proper environment for display all set up nice n pretty like."
23 (let* ((description (find-occurence object
)))
26 (dletf (((description.type description
) type
)
27 ((attributes description
) (or
28 (attributes description
)
29 (list-slots object
))))
30 ;; apply the default line to the description
31 (funcall-with-description
34 ;; apply the passed in arguments and call display-using-description
36 (funcall-with-description
39 function description object component
))))
40 (error "no description for ~A" object
)))))
42 (define-layered-function display
(component object
&rest args
)
44 "Displays OBJECT in COMPONENT."))
46 (define-layered-method display
((component t
) (object t
)
48 &key type
(line #'line-in
)
50 " The default display dispatch method
52 DISPLAY takes two required arguments,
53 COMPONENT : The component to display FROM (not neccesarily 'in')
54 OBJECT : The 'thing' we want to display... in this case it's the component
56 DISPLAY also takes keywords arguments which modify the DESCRIPTION,
57 that is to say the parameters that come together to create the output.
59 The default display calls out via FUNCALL-WITH-LAYERS to tche DISPLAY-USING-DESCRIPTION method."
61 (let* ((description (find-occurence object
)))
64 (dletf (((description.type description
) type
)
65 ((attributes description
) (or
66 (attributes description
)
67 (list-slots object
))))
68 ;; apply the default line to the description
69 (funcall-with-description
72 ;; apply the passed in arguments and call display-using-description
74 (funcall-with-description
77 #'display-using-description description object component
))))
78 (error "no description for ~A" object
))))
83 (defun funcall-with-description (description properties function
&rest args
)
86 (dletf* (((description.type description
) (or
87 (getf properties
:type
)
88 (description.type description
)))
90 ((description.layers description
) (append
91 (description.layers description
)
92 (getf properties
:layers
)))
93 ((description.properties description
) (append (description.properties description
) properties
)))
95 (description.layers description
)
97 (contextl::funcall-with-special-initargs
98 (list (cons description properties
))
100 (apply function args
))))))
101 (apply function args
)))
103 (defmacro with-description
((description &rest properties
) &body body
)
104 `(funcall-with-description ,description
(if ',(cdr properties
)
110 (define-layered-function find-do-attributes
(desc))
112 (define-layered-method find-do-attributes
((description description
))
116 :in
(attributes description
)
117 :collect
(let ((default (find (car (ensure-list att
))
118 (default-attributes description
)
122 (defmacro do-attributes
((var description
&optional
(attributes `(find-do-attributes ,description
))) &body body
)
123 (with-unique-names (att properties type
)
124 `(dolist* (,att
,attributes
)
125 (let* ((,att
(ensure-list ,att
))
126 (,properties
(rest ,att
))
127 (,type
(getf ,properties
:type
))
128 (,var
(let ((a (find-attribute ,description
(first ,att
))))
130 (apply #'make-attribute
:name
(first ,att
) :type
,type
,properties
)
131 (if a a
(make-attribute :name
(first ,att
) :slot-name
(first ,att
)))))))
132 (funcall-with-description ,var
,properties
136 (defmacro with-component
((component) &body body
)
137 `(let ((self ,component
))
138 (declare (ignorable self
))
139 (flet ((display* (thing &rest args
)
140 (apply #'display
,component thing args
))
141 (display-attribute (attribute obj
&optional props
)
143 (funcall-with-description
145 #'display-using-description attribute obj
,component
)
146 (display-using-description attribute obj
,component
))))
147 (declare (ignorable #'display
* #'display-attribute
))
150 (defmacro defdisplay
(&body body
)
151 (loop with in-layerp
= (eq (car body
) :in-layer
)
152 with layer
= (if in-layerp
(cadr body
) 't
)
153 for tail on
(if in-layerp
(cddr body
) body
)
154 until
(listp (car tail
))
155 collect
(car tail
) into qualifiers
157 (when (member :in-layer qualifiers
)
158 (error "Incorrect occurrence of :in-layer in defdisplay. Must occur before qualifiers."))
160 (destructuring-bind (description &optional object component
) (car tail
)
161 (with-unique-names (d c
)
162 (let (standard-description-p)
163 `(define-layered-method
164 display-using-description
169 (setf object description
)
174 (setf d
(car description
))
178 (setf standard-description-p t
)
185 (setf c
(car component
))