Use CLOSER-COMMON-LISP package to resolve conflicts between CL and C2MOP
[clinton/lisp-on-lines.git] / src / display.lisp
1 (in-package :lisp-on-lines)
2
3
4 (defvar *display*)
5
6
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
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))))
20
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))
27
28 (defmacro with-attribute-context ((attribute) &body body)
29 `(funcall-with-attribute-context ,attribute (lambda () ,@body)))
30
31
32 (defun display (display object &rest args &key deactivate activate &allow-other-keys)
33
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))))
40
41 (define-layered-method display-using-description
42 :around ((description standard-description-object) display object &rest args)
43 (declare (ignorable args))
44 #+nil (break "Entering DISPLAY for ~A on ~A using ~A" object display description)
45 (let ((*display* display))
46 (apply #'funcall-with-described-object
47 (lambda ()
48 (call-next-method))
49 object description args)))
50
51
52
53
54 (defun display/d (&rest args)
55 (apply #'display-using-description args))
56
57 (define-layered-method display-using-description (description display object &rest args)
58 (error "No DISPLAY-USING-DESCRIPTION methods are specified for: ~% DESCRIPTION: ~A ~% DISPLAY: ~A ~% OBJECT: ~A ~% ARGS: ~S
59
60 OMGWTF! If you didn't do this, it's a bug!" description display object args))
61
62 (defmacro define-display (&body body)
63 (loop with in-descriptionp = (eq (car body) :in-description)
64 with description = (if in-descriptionp (cadr body) 't)
65 for tail on (if in-descriptionp (cddr body) body)
66 until (listp (car tail))
67 collect (car tail) into qualifiers
68 finally
69 (when (member :in-description qualifiers)
70 (error "Incorrect occurrence of :in-description in defdisplay. Must occur before qualifiers."))
71 (return
72 (destructuring-bind (description-spec &optional (display-spec (gensym)) (object-spec (gensym)))
73 (car tail)
74 `(define-layered-method
75 display-using-description
76 :in-layer ,(if (eq t description)
77 t
78 (defining-description description))
79 ,@qualifiers
80 (,(if (listp description-spec)
81 (list (first description-spec)
82 (if (eq 'description (second description-spec))
83 'description
84 (contextl::defining-layer (defining-description (second description-spec))))))
85 ,display-spec
86 ,object-spec &rest args)
87 (declare (ignorable args))
88 ,@(cdr tail))))))
89
90
91
92