Made attribute class layered
[clinton/lisp-on-lines.git] / src / display.lisp
1 (in-package :lisp-on-lines)
2
3 (defvar *description*)
4 (defvar *display*)
5 (defvar *object*)
6
7 (deflayer display-layer)
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 &key attributes )
14 (let ((*display-attributes* attributes))
15 (display-using-description (description-of object) display object args)))
16
17 (define-layered-method display-using-description
18 :around (description display object &rest args)
19 (declare (ignorable args))
20 (let ((*description* description)
21 (*display* display)
22 (*object* object))
23 (call-next-method)))
24
25 (defun display/d (&rest args)
26 (apply #'display-using-description args))
27
28
29
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
33 OMGWTF! If you didn't do this, it's a bug!" description display object args))
34
35
36
37 (defmacro define-display (&body body)
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)
41 until (listp (car tail))
42 collect (car tail) into qualifiers
43 finally
44 (when (member :in-description qualifiers)
45 (error "Incorrect occurrence of :in-description in defdisplay. Must occur before qualifiers."))
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
51 :in-layer ,(if (eq t description)
52 t
53 (defining-description description))
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