e7c5f95a |
1 | (in-package :lisp-on-lines) |
2 | |
b1c8f43b |
3 | |
e7c5f95a |
4 | (defvar *display*) |
b1c8f43b |
5 | |
6de8d300 |
6 | |
e7c5f95a |
7 | (define-layered-function display-using-description (description display object &rest args) |
8 | (:documentation |
9 | "Displays OBJECT via description using/in/with/on display")) |
10 | |
b7657b86 |
11 | |
12 | |
13 | (defun modify-layer-context (context &key activate deactivate) |
14 | (dolist (d deactivate) |
15 | (setf context (remove-layer (find-description d) |
16 | context))) |
17 | (dolist (d activate context) |
18 | (setf context (adjoin-layer (find-description d) |
19 | context)))) |
b7657b86 |
20 | |
f56d6e7e |
21 | (defun funcall-with-attribute-context (attribute thunk) |
22 | (funcall-with-layer-context |
23 | (modify-layer-context (current-layer-context) |
24 | :activate (attribute-active-descriptions attribute) |
25 | :deactivate (attribute-inactive-descriptions attribute)) |
26 | thunk)) |
b7657b86 |
27 | |
f56d6e7e |
28 | (defmacro with-attribute-context ((attribute) &body body) |
29 | `(funcall-with-attribute-context ,attribute (lambda () ,@body))) |
30 | |
31 | |
b7657b86 |
32 | (defun display (display object &rest args &key deactivate activate &allow-other-keys) |
46440824 |
33 | |
b7657b86 |
34 | (funcall-with-layer-context |
35 | (modify-layer-context (current-layer-context) |
36 | :activate activate |
37 | :deactivate deactivate) |
38 | (lambda () |
39 | (apply #'display-using-description (description-of object) display object args)))) |
e7c5f95a |
40 | |
41 | (define-layered-method display-using-description |
42 | :around (description display object &rest args) |
4358148e |
43 | (declare (ignorable args)) |
46440824 |
44 | #+nil (break "Entering DISPLAY for ~A on ~A using ~A" object display description) |
b1c8f43b |
45 | (let ((*display* display)) |
46 | (apply #'funcall-with-described-object |
47 | (lambda () |
48 | (call-next-method)) |
49 | object description args))) |
b7657b86 |
50 | |
51 | |
52 | |
4271ab0b |
53 | (defun display/d (&rest args) |
54 | (apply #'display-using-description args)) |
55 | |
e7c5f95a |
56 | (define-layered-method display-using-description (description display object &rest args) |
57 | (error "No DISPLAY-USING-DESCRIPTION methods are specified for: ~% DESCRIPTION: ~A ~% DISPLAY: ~A ~% OBJECT: ~A ~% ARGS: ~S |
58 | |
59 | OMGWTF! If you didn't do this, it's a bug!" description display object args)) |
60 | |
e7c5f95a |
61 | (defmacro define-display (&body body) |
4358148e |
62 | (loop with in-descriptionp = (eq (car body) :in-description) |
63 | with description = (if in-descriptionp (cadr body) 't) |
64 | for tail on (if in-descriptionp (cddr body) body) |
e7c5f95a |
65 | until (listp (car tail)) |
66 | collect (car tail) into qualifiers |
67 | finally |
4358148e |
68 | (when (member :in-description qualifiers) |
69 | (error "Incorrect occurrence of :in-description in defdisplay. Must occur before qualifiers.")) |
e7c5f95a |
70 | (return |
71 | (destructuring-bind (description-spec &optional (display-spec (gensym)) (object-spec (gensym))) |
72 | (car tail) |
b1c8f43b |
73 | `(define-layered-method |
e7c5f95a |
74 | display-using-description |
4358148e |
75 | :in-layer ,(if (eq t description) |
76 | t |
77 | (defining-description description)) |
e7c5f95a |
78 | ,@qualifiers |
79 | (,(if (listp description-spec) |
80 | (list (first description-spec) |
81 | (if (eq 'description (second description-spec)) |
82 | 'description |
83 | (defining-description (second description-spec))))) |
84 | ,display-spec |
85 | ,object-spec &rest args) |
86 | (declare (ignorable args)) |
87 | ,@(cdr tail)))))) |
88 | |
89 | |
90 | |
91 | |