checkpoint.. nothing to see here.
[clinton/lisp-on-lines.git] / src / display.lisp
CommitLineData
e7c5f95a 1(in-package :lisp-on-lines)
2
4358148e 3(defvar *description*)
e7c5f95a 4(defvar *display*)
4358148e 5(defvar *object*)
6
7(deflayer display-layer)
e7c5f95a 8
9(define-layered-function display-using-description (description display object &rest args)
10 (:documentation
11 "Displays OBJECT via description using/in/with/on display"))
12
4271ab0b 13(defun display (display object &rest args &key attributes )
14 (let ((*display-attributes* attributes))
15 (display-using-description (description-of object) display object args)))
e7c5f95a 16
17(define-layered-method display-using-description
18 :around (description display object &rest args)
4358148e 19 (declare (ignorable args))
20 (let ((*description* description)
21 (*display* display)
e7c5f95a 22 (*object* object))
23 (call-next-method)))
24
4271ab0b 25(defun display/d (&rest args)
26 (apply #'display-using-description args))
27
4358148e 28
29
e7c5f95a 30(define-layered-method display-using-description (description display object &rest args)
31 (error "No DISPLAY-USING-DESCRIPTION methods are specified for: ~% DESCRIPTION: ~A ~% DISPLAY: ~A ~% OBJECT: ~A ~% ARGS: ~S
32
33OMGWTF! If you didn't do this, it's a bug!" description display object args))
34
4358148e 35
e7c5f95a 36
37(defmacro define-display (&body body)
4358148e 38 (loop with in-descriptionp = (eq (car body) :in-description)
39 with description = (if in-descriptionp (cadr body) 't)
40 for tail on (if in-descriptionp (cddr body) body)
e7c5f95a 41 until (listp (car tail))
42 collect (car tail) into qualifiers
43 finally
4358148e 44 (when (member :in-description qualifiers)
45 (error "Incorrect occurrence of :in-description in defdisplay. Must occur before qualifiers."))
e7c5f95a 46 (return
47 (destructuring-bind (description-spec &optional (display-spec (gensym)) (object-spec (gensym)))
48 (car tail)
49 `(define-layered-method
50 display-using-description
4358148e 51 :in-layer ,(if (eq t description)
52 t
53 (defining-description description))
e7c5f95a 54 ,@qualifiers
55 (,(if (listp description-spec)
56 (list (first description-spec)
57 (if (eq 'description (second description-spec))
58 'description
59 (defining-description (second description-spec)))))
60 ,display-spec
61 ,object-spec &rest args)
62 (declare (ignorable args))
63 ,@(cdr tail))))))
64
65
66
67