X-Git-Url: https://git.hcoop.net/clinton/lisp-on-lines.git/blobdiff_plain/e7c5f95a989882cabc1f4b6ea4598565ea317952..f56d6e7e926f9c3f968325e244794ff748435ac3:/src/display.lisp diff --git a/src/display.lisp b/src/display.lisp index 91cbd06..6078e83 100644 --- a/src/display.lisp +++ b/src/display.lisp @@ -1,44 +1,80 @@ (in-package :lisp-on-lines) -(defvar *object*) + (defvar *display*) + (define-layered-function display-using-description (description display object &rest args) (:documentation "Displays OBJECT via description using/in/with/on display")) -(defun display (display object &rest args) - (display-using-description (description-of object) display object args)) + + +(defun modify-layer-context (context &key activate deactivate) + (dolist (d deactivate) + (setf context (remove-layer (find-description d) + context))) + (dolist (d activate context) + (setf context (adjoin-layer (find-description d) + context)))) + +(defun funcall-with-attribute-context (attribute thunk) + (funcall-with-layer-context + (modify-layer-context (current-layer-context) + :activate (attribute-active-descriptions attribute) + :deactivate (attribute-inactive-descriptions attribute)) + thunk)) + +(defmacro with-attribute-context ((attribute) &body body) + `(funcall-with-attribute-context ,attribute (lambda () ,@body))) + + +(defun display (display object &rest args &key deactivate activate &allow-other-keys) + + (funcall-with-layer-context + (modify-layer-context (current-layer-context) + :activate activate + :deactivate deactivate) + (lambda () + (apply #'display-using-description (description-of object) display object args)))) (define-layered-method display-using-description :around (description display object &rest args) - (let ((*display* display) - (*object* object)) - (call-next-method))) + (declare (ignorable args)) +#+nil (break "Entering DISPLAY for ~A on ~A using ~A" object display description) + (let ((*display* display)) + (apply #'funcall-with-described-object + (lambda () + (call-next-method)) + object description args))) + + + +(defun display/d (&rest args) + (apply #'display-using-description args)) (define-layered-method display-using-description (description display object &rest args) (error "No DISPLAY-USING-DESCRIPTION methods are specified for: ~% DESCRIPTION: ~A ~% DISPLAY: ~A ~% OBJECT: ~A ~% ARGS: ~S OMGWTF! If you didn't do this, it's a bug!" description display object args)) -(defun display-attribute (attribute) - (display-using-description attribute *display* *object*)) - (defmacro define-display (&body body) - (loop with in-layerp = (eq (car body) :in-layer) - with layer = (if in-layerp (cadr body) 't) - for tail on (if in-layerp (cddr body) body) + (loop with in-descriptionp = (eq (car body) :in-description) + with description = (if in-descriptionp (cadr body) 't) + for tail on (if in-descriptionp (cddr body) body) until (listp (car tail)) collect (car tail) into qualifiers finally - (when (member :in-layer qualifiers) - (error "Incorrect occurrence of :in-layer in defdisplay. Must occur before qualifiers.")) + (when (member :in-description qualifiers) + (error "Incorrect occurrence of :in-description in defdisplay. Must occur before qualifiers.")) (return (destructuring-bind (description-spec &optional (display-spec (gensym)) (object-spec (gensym))) (car tail) - `(define-layered-method + `(define-layered-method display-using-description - :in-layer ,layer + :in-layer ,(if (eq t description) + t + (defining-description description)) ,@qualifiers (,(if (listp description-spec) (list (first description-spec)