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 | |
13 | (defun display (display object &rest args) |
14 | (display-using-description (description-of object) display object args)) |
15 | |
16 | (define-layered-method display-using-description |
17 | :around (description display object &rest args) |
4358148e |
18 | (declare (ignorable args)) |
19 | (let ((*description* description) |
20 | (*display* display) |
e7c5f95a |
21 | (*object* object)) |
4358148e |
22 | |
e7c5f95a |
23 | (call-next-method))) |
24 | |
4358148e |
25 | |
26 | |
e7c5f95a |
27 | (define-layered-method display-using-description (description display object &rest args) |
28 | (error "No DISPLAY-USING-DESCRIPTION methods are specified for: ~% DESCRIPTION: ~A ~% DISPLAY: ~A ~% OBJECT: ~A ~% ARGS: ~S |
29 | |
30 | OMGWTF! If you didn't do this, it's a bug!" description display object args)) |
31 | |
4358148e |
32 | |
e7c5f95a |
33 | |
34 | (defmacro define-display (&body body) |
4358148e |
35 | (loop with in-descriptionp = (eq (car body) :in-description) |
36 | with description = (if in-descriptionp (cadr body) 't) |
37 | for tail on (if in-descriptionp (cddr body) body) |
e7c5f95a |
38 | until (listp (car tail)) |
39 | collect (car tail) into qualifiers |
40 | finally |
4358148e |
41 | (when (member :in-description qualifiers) |
42 | (error "Incorrect occurrence of :in-description in defdisplay. Must occur before qualifiers.")) |
e7c5f95a |
43 | (return |
44 | (destructuring-bind (description-spec &optional (display-spec (gensym)) (object-spec (gensym))) |
45 | (car tail) |
46 | `(define-layered-method |
47 | display-using-description |
4358148e |
48 | :in-layer ,(if (eq t description) |
49 | t |
50 | (defining-description description)) |
e7c5f95a |
51 | ,@qualifiers |
52 | (,(if (listp description-spec) |
53 | (list (first description-spec) |
54 | (if (eq 'description (second description-spec)) |
55 | 'description |
56 | (defining-description (second description-spec))))) |
57 | ,display-spec |
58 | ,object-spec &rest args) |
59 | (declare (ignorable args)) |
60 | ,@(cdr tail)))))) |
61 | |
62 | |
63 | |
64 | |