(in-package :lisp-on-lines)
(define-layered-function display-using-description (description object component)
-; (:argument-precedence-order )
+ (:method-combination wrapping-standard)
(:documentation
"Render the object in component,
using DESCRIPTION, which is an occurence, an attribute, or something else entirely."))
display-using-description (d o c)
(<:as-html "default :" o))
-(defmethod find-layer-for-type (type)
- type)
+(defun make-display-function (component object
+ &rest properties
+ &key type (line #'line-in)
+ &allow-other-keys)
+ "returns a function that expects a 3 argument function as its argument
+The function (which is usually display-using-description) will be called with the proper environment for display all set up nice n pretty like."
-(define-layered-function display (component object &rest args)
- (:documentation
- "Displays OBJECT in COMPONENT."))
+ (lambda (function)
+ (let* ((description (find-occurence object)))
-(define-layered-method display ((component t) (object t)
- &rest properties
- &key type
- &allow-other-keys)
- "The default display calls out via FUNCALL-WITH-LAYERS to tche DISPLAY-USING-DESCRIPTION method."
-
- (let* ((occurence (find-occurence object))
- (description (or (find-display-attribute
- occurence
- (setf type (or type (description.type occurence))))
- occurence)))
(if description
- (dletf (((description.type occurence) type)
- ((description.layers description) (append `(+
-
- ;;find-layer-for-type is a
- ;; backwards compat thing
- ,(find-layer-for-type
- type))
- (description.layers description)))
+ (dletf (((description-type description) type)
((attributes description) (or
(attributes description)
- (list-slots object))))
+ (list-attributes description))))
+ ;; apply the default line to the description
(funcall-with-description
- description properties
- #'display-using-description description object component))
- (error "no description for ~A" object))))
+ description
+ (funcall line object)
+ ;; apply the passed in arguments and call display-using-description
+ #'(lambda ()
+ (funcall-with-description
+ description
+ properties
+ function description object component))))
+ (error "no description for ~A" object)))))
+
+(define-layered-function display (component object &rest args)
+ (:documentation
+ "Displays OBJECT in COMPONENT."))
+
+(define-layered-method display ((component t) (object t)
+ &rest properties)
+ " The default display dispatch method
+
+ DISPLAY takes two required arguments,
+ COMPONENT : The component to display FROM (not neccesarily 'in')
+ OBJECT : The 'thing' we want to display... in this case it's the component
+
+ DISPLAY also takes keywords arguments which modify the DESCRIPTION,
+ that is to say the parameters that come together to create the output.
+
+The default display calls out via FUNCALL-WITH-LAYERS to tche DISPLAY-USING-DESCRIPTION method."
+ (funcall (apply 'make-display-function component object properties)
+ 'display-using-description))
;;;;; Macros
(defun funcall-with-description (description properties function &rest args)
+
(if description
- (dletf* (((description.type description) (or
+ (dletf* (((description-type description) (or
(getf properties :type)
- (description.type description)))
+ (description-type description)))
- ((description.layers description) (append
- (description.layers description)
+ ((description-layers description) (append
+ (description-layers description)
(getf properties :layers)))
- ((description.properties description) properties))
+ ((description-properties description) (append (description-properties description) properties)))
(funcall-with-layers
- (description.layers description)
+ (description-layers description)
#'(lambda ()
(contextl::funcall-with-special-initargs
(list (cons description properties))
(apply function args))))))
(apply function args)))
-
-
(defmacro with-description ((description &rest properties) &body body)
`(funcall-with-description ,description (if ',(cdr properties)
(list ,@properties)
#'(lambda ()
,@body)))
-(defmacro do-attributes ((var description &optional (attributes `(attributes ,description))) &body body)
+(define-layered-function find-do-attributes (desc))
+
+(define-layered-method find-do-attributes ((description description))
+
+ (loop
+ :for att
+ :in (attributes description)
+ :collect (let ((default (find (car (ensure-list att))
+ (default-attributes description)
+ :key #'car)))
+ (or default att))))
+
+(defmacro do-attributes ((var description &optional (attributes `(find-do-attributes ,description))) &body body)
(with-unique-names (att properties type)
`(dolist* (,att ,attributes)
- (let* ((,att (ensure-list ,att))
- (,properties (rest ,att))
- (,type (getf ,properties :type))
- (,var (let ((a (find-attribute ,description (first ,att))))
- (if ,type
- (apply #'make-attribute :name (first ,att) :type ,type ,properties)
- (if a a (make-attribute :name (first ,att) :slot-name (first ,att)))))))
- (funcall-with-description ,var ,properties
- #'(lambda () ,@body))))))
+ (let* ((,att (ensure-list ,att))
+ (,properties (rest ,att))
+ (,type (getf ,properties :type))
+ (,var (let ((a (find-attribute ,description (first ,att))))
+ (if ,type
+ (apply #'make-attribute :name (first ,att) :type ,type ,properties)
+ (if a a (make-attribute :name (first ,att) :slot-name (first ,att)))))))
+ (funcall-with-description ,var ,properties
+ #'(lambda ()
+ ,@body))))))
(defmacro with-component ((component) &body body)
`(let ((self ,component))
(declare (ignorable self))
(flet ((display* (thing &rest args)
(apply #'display ,component thing args))
- (display-attribute (attribute obj &optional props)
+ (display-attribute (attribute obj &rest
+ props)
(if props
(funcall-with-description
attribute props
(when (member :in-layer qualifiers)
(error "Incorrect occurrence of :in-layer in defdisplay. Must occur before qualifiers."))
(return
- (destructuring-bind (description object &optional component) (car tail)
+ (destructuring-bind (description &optional object component) (car tail)
(with-unique-names (d c)
(let (standard-description-p)
`(define-layered-method
display-using-description
:in-layer ,layer
,@qualifiers
-
+
+ ,@(unless object
+ (setf object description)
+ (setf description d)
+ nil)
(,(cond
((listp description)
(setf d (car description))
component)
(t
(setf c component)
- `(,c component))))
+ `(,c t))))
(with-component (,c)
,@(cdr tail)))))))))