Add validation code.
[clinton/lisp-on-lines.git] / src / display.lisp
CommitLineData
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))))
20
21
22
23
24(defun display (display object &rest args &key deactivate activate &allow-other-keys)
25 (funcall-with-layer-context
26 (modify-layer-context (current-layer-context)
27 :activate activate
28 :deactivate deactivate)
29 (lambda ()
30 (apply #'display-using-description (description-of object) display object args))))
e7c5f95a 31
32(define-layered-method display-using-description
33 :around (description display object &rest args)
4358148e 34 (declare (ignorable args))
b1c8f43b 35 (let ((*display* display))
36 (apply #'funcall-with-described-object
37 (lambda ()
38 (call-next-method))
39 object description args)))
b7657b86 40
41
42
6de8d300 43
e7c5f95a 44
4271ab0b 45(defun display/d (&rest args)
46 (apply #'display-using-description args))
47
e7c5f95a 48(define-layered-method display-using-description (description display object &rest args)
49 (error "No DISPLAY-USING-DESCRIPTION methods are specified for: ~% DESCRIPTION: ~A ~% DISPLAY: ~A ~% OBJECT: ~A ~% ARGS: ~S
50
51OMGWTF! If you didn't do this, it's a bug!" description display object args))
52
e7c5f95a 53(defmacro define-display (&body body)
4358148e 54 (loop with in-descriptionp = (eq (car body) :in-description)
55 with description = (if in-descriptionp (cadr body) 't)
56 for tail on (if in-descriptionp (cddr body) body)
e7c5f95a 57 until (listp (car tail))
58 collect (car tail) into qualifiers
59 finally
4358148e 60 (when (member :in-description qualifiers)
61 (error "Incorrect occurrence of :in-description in defdisplay. Must occur before qualifiers."))
e7c5f95a 62 (return
63 (destructuring-bind (description-spec &optional (display-spec (gensym)) (object-spec (gensym)))
64 (car tail)
b1c8f43b 65 `(define-layered-method
e7c5f95a 66 display-using-description
4358148e 67 :in-layer ,(if (eq t description)
68 t
69 (defining-description description))
e7c5f95a 70 ,@qualifiers
71 (,(if (listp description-spec)
72 (list (first description-spec)
73 (if (eq 'description (second description-spec))
74 'description
75 (defining-description (second description-spec)))))
76 ,display-spec
77 ,object-spec &rest args)
78 (declare (ignorable args))
79 ,@(cdr tail))))))
80
81
82
83