836a43cac97bd011fee9942fb96557f28ee927e5
[hyperobject.git] / views.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          views.lisp
6 ;;;; Purpose:       View methods for Hyperobjects
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Apr 2000
9 ;;;;
10 ;;;; $Id: views.lisp,v 1.55 2003/06/17 04:56:02 kevin Exp $
11 ;;;;
12 ;;;; This file is Copyright (c) 2000-2003 by Kevin M. Rosenberg
13 ;;;; *************************************************************************
14  
15 (in-package #:hyperobject)
16
17
18 (defclass object-view ()
19   ((object-class-name :initform nil :initarg :object-class-name
20                       :accessor object-class-name
21                  :documentation "Name of class of object to be viewed.")
22    (object-class :initform nil :initarg :object-class
23                  :accessor object-class
24                  :documentation "Class of object to be viewed.")
25    (slots :initform nil :initarg :slots :accessor slots
26           :documentation "List of effective slots for object to be viewed.")
27    (name :initform nil :initarg :name :accessor name
28          :documentation "Name for this view.")
29    (category :initform nil :initarg :category :accessor category
30              :documentation "Category for view. Helpful when want to find a view corresponding to a particular category.")
31    (source-code :initform nil :initarg :source-code :accessor source-code 
32                 :documentation "Source code for generating view.")
33    (country-language :initform :en :initarg :country-language
34                      :documentation "Country's Language for this view.")
35    ;;
36    (file-start-str :type (or string null) :initform nil :initarg :file-start-str
37                    :accessor file-start-str)
38    (file-end-str :type (or string null) :initform nil :initarg :file-end-str
39                  :accessor file-end-str)
40    (list-start-printer :type (or string function null) :initform nil
41                            :initarg :list-start-printer
42                       :accessor list-start-printer)
43    (list-start-indent :initform nil :initarg :list-start-indent
44                       :accessor list-start-indent)
45    (list-end-printer :type (or string function null) :initform nil
46                          :initarg :list-end-printer
47                     :accessor list-end-printer)
48    (list-end-indent :initform nil :initarg :list-end-indent
49                     :accessor list-end-indent)
50    (obj-start-printer :type (or string function null) :initform nil :initarg :obj-start-printer
51                      :accessor obj-start-printer)
52    (obj-start-indent :initform nil :initarg :obj-start-indent
53                      :accessor obj-start-indent)
54    (obj-end-printer :type (or string function null) :initform nil :initarg :obj-end-printer
55                    :accessor obj-end-printer)
56    (obj-end-indent :initform nil :initarg :obj-end-indent
57                    :accessor obj-end-indent)
58    (obj-data-indent :initform nil :initarg :obj-data-indent
59                     :accessor obj-data-indent)
60    (obj-data-printer :type (or function null) :initform nil
61                         :initarg :obj-data-printer
62                         :accessor obj-data-printer)
63    (obj-data-print-code :type (or function null) :initform nil
64                   :initarg :obj-data-print-code
65                   :accessor obj-data-print-code)
66    (obj-data-end-str :type (or string null) :initform nil
67                         :initarg :obj-data-end-str
68                         :accessor obj-data-end-str)
69    (link-slots :type list :initform nil
70                :documentation "List of slot names that have hyperlinks"
71                :accessor link-slots)
72    (link-page :type (or string null) :initform nil
73                       :initarg :link-page
74                       :accessor link-page)
75    (link-href-start :type (or string null) :initform nil :initarg :link-href-start
76                     :accessor link-href-start)
77    (link-href-end :type (or string null) :initform nil :initarg :link-href-end
78                   :accessor link-href-end)
79    (link-ampersand :type (or string null) :initform nil :initarg :link-ampersand
80                    :accessor link-ampersand))
81   (:default-initargs :link-page "disp-func1")
82   (:documentation "View class for a hyperobject"))
83
84
85 (defun get-category-view (obj category &optional slots)
86   "Find or make a category view for an object"
87   (let ((obj-class (class-of obj)))
88     (if (null category)
89         (default-view obj-class)
90         (aif (find category (views obj-class) :key #'category)
91              it
92              (let ((view
93                     (make-instance 'object-view
94                                    :object-class-name (class-name obj-class)
95                                    :object-class obj-class
96                                    :category category
97                                    :slots slots)))
98                (push view (views obj-class))
99                view)))))
100                              
101 ;;;; *************************************************************************
102 ;;;;  Metaclass Intialization
103 ;;;; *************************************************************************
104
105 (defun finalize-views (cl)
106   "Finalize all views that are given on a objects initialization"
107   (unless (default-print-slots cl)
108     (setf (default-print-slots cl)
109           (mapcar #'slot-definition-name (class-slots cl))))
110   (let ((views '()))
111     (dolist (view-def (views cl))
112       (push (make-object-view cl view-def) views))
113     (setf (views cl) (nreverse views)))
114   (cond
115     ((default-view cl)
116      (setf (default-view cl) (make-object-view cl (default-view cl))))
117     ((car (views cl))
118      (setf (default-view cl) (make-object-view cl (car (views cl)))))
119     (t
120      (setf (default-view cl) (make-object-view cl :default)))))
121
122 (defun make-object-view (cl view-def)
123   "Make an object view from a definition. Do nothing if a class is passed so that reinitialization will be a no-op"
124   (cond
125     ((typep view-def 'object-view)
126      view-def)
127     ((eq view-def :default)
128      (let* ((name (class-name cl))
129             (view (make-instance 'object-view :name "automatic"
130                                  :object-class-name name
131                                  :object-class cl
132                                  :category :compact-text)))
133        view))
134     ((consp view-def)
135      (apply #'make-instance 'object-view view-def))
136     (t
137      (error "Invalid parameter to make-object-view: ~S" view-def))))
138
139 (defmethod initialize-instance :after ((view object-view)
140                                        &rest initargs &key &allow-other-keys)
141   (initialize-view (object-class view) view))
142   
143 (defun initialize-view (obj-cl view)
144   "Calculate all view slots for a hyperobject class"
145   (cond
146     ((category view)
147      (initialize-view-by-category obj-cl view))
148     ((source-code view)
149      (initialize-view-by-source-code obj-cl view))
150     (t
151      (setf (category view) :compact-text)
152      (initialize-view-by-category obj-cl view))))
153
154 (defun initialize-view-by-source-code (obj-cl view)
155   "Initialize a view based upon a source code"
156   (let ((source-code (source-code view)))
157     (error "not implemented")
158     )
159   )
160
161 (defmacro write-simple (v s)
162   `(typecase ,v
163     (string
164      (write-string ,v ,s))
165     #+allegro
166     (fixnum
167      (excl::print-fixnum ,s 10 ,v)) 
168     (symbol
169      (write-string (symbol-name ,v) ,s))
170     (t
171      (write-string (write-to-string ,v) ,s))))
172
173 (defun write-ho-value (obj name type formatter cdata strm)
174   (declare (ignorable type))
175   (let* ((slot-data (slot-value obj name))
176          (fmt-data (if formatter
177                        (funcall formatter slot-data)
178                        slot-data)))
179     (if cdata
180         (write-xml-cdata fmt-data strm)
181         (write-simple fmt-data strm))))
182
183 (defun ppfc-html (title name type formatter cdata print-func)
184   (vector-push-extend '(write-string "<span class=\"" s) print-func)
185   (vector-push-extend `(write-string ,title s) print-func)
186   (vector-push-extend '(write-string "\">" s) print-func)
187   (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
188   (vector-push-extend '(write-string "</span>" s) print-func))
189
190 (defun ppfc-xml (tag name type formatter cdata print-func)
191   (vector-push-extend '(write-char #\< s) print-func)
192   (vector-push-extend `(write-string ,tag s) print-func)
193   (vector-push-extend '(write-char #\> s) print-func)
194   (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
195   (vector-push-extend '(write-string "</" s) print-func)
196   (vector-push-extend `(write-string ,tag s) print-func)
197   (vector-push-extend '(write-char #\> s) print-func))
198
199 (defun ppfc-html-labels (label name type formatter cdata print-func)
200   (vector-push-extend '(write-string "<span class=\"label\">" s) print-func)
201   (vector-push-extend `(write-string ,label s) print-func)
202   (vector-push-extend '(write-string "</span> " s) print-func)
203   (ppfc-html label name type formatter cdata print-func))
204
205 (defun ppfc-xhtml-labels (label tag name type formatter cdata print-func)
206   (vector-push-extend '(write-string "<span class=\"label\">" s) print-func)
207   (vector-push-extend `(write-string ,label s) print-func)
208   (vector-push-extend '(write-string "</span> " s) print-func)
209   (ppfc-html tag name type formatter cdata print-func))
210
211 (defun ppfc-xml-labels (label tag name type formatter cdata print-func)
212   (vector-push-extend '(write-string "<label>" s) print-func)
213   (vector-push-extend `(write-string ,label s) print-func)
214   (vector-push-extend '(write-string "</label> " s) print-func)
215   (ppfc-xml tag name type formatter cdata print-func))
216
217 (defun ppfc-html-link (name type formatter cdata nlink print-func)
218   (declare (fixnum nlink))
219   (vector-push-extend '(write-char #\< s) print-func)
220   (vector-push-extend `(write-string (nth ,(+ nlink nlink) links) s) print-func) 
221   (vector-push-extend '(write-char #\> s) print-func)
222   (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
223   (vector-push-extend '(write-string "</" s) print-func)
224   (vector-push-extend `(write-string (nth ,(+ nlink nlink 1) links) s) print-func) 
225   (vector-push-extend '(write-char #\> s) print-func))
226
227 (defun ppfc-html-link-labels (label name type formatter cdata nlink print-func)
228   (vector-push-extend '(write-string "<span class=\"label\">" s) print-func)
229   (vector-push-extend `(write-string ,label s) print-func)
230   (vector-push-extend '(write-string "</span> " s) print-func)
231   (ppfc-html-link name type formatter cdata nlink print-func))
232
233 (defun push-print-fun-code (category slot nlink print-func)
234   (let* ((formatter (esd-print-formatter slot))
235          (name (slot-definition-name slot))
236          (user-name (esd-user-name slot))
237          (xml-user-name (escape-xml-string user-name))
238          (xml-tag (escape-xml-string user-name))
239          (type (slot-value slot 'type))
240          (cdata (not (null
241                       (and (in category :xml :xhtml :xml-link :xhtml-link
242                                :xml-labels :ie-xml-labels
243                                :xhtml-link-labels :xml-link-labels :ie-xml-link
244                                :ie-xml-link-labels)
245                            (or formatter
246                                (lisp-type-is-a-string type))))))
247          (hyperlink (esd-hyperlink slot)))
248     
249     (case category
250       (:compact-text
251        (vector-push-extend
252         `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func))
253       (:compact-text-labels
254        (vector-push-extend `(write-string ,user-name s) print-func)
255        (vector-push-extend '(write-char #\space s) print-func)
256        (vector-push-extend
257         `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func))
258       ((or :html :xhtml)
259        (ppfc-html user-name name type formatter cdata print-func))
260       (:xml
261        (ppfc-xml xml-tag name type formatter cdata print-func))
262       (:html-labels
263        (ppfc-html-labels user-name name type formatter cdata print-func))
264       (:xhtml-labels
265        (ppfc-xhtml-labels xml-user-name user-name name type formatter cdata print-func))
266       (:xml-labels
267        (ppfc-xml-labels xml-user-name xml-tag name type formatter cdata print-func))
268       ((or :html-link :xhtml-link)
269        (if hyperlink
270            (ppfc-html-link name type formatter cdata nlink print-func)
271            (ppfc-html user-name name type formatter cdata print-func)))
272       ((or :xml-link :ie-xml-link)
273        (if hyperlink
274            (ppfc-html-link name type formatter cdata nlink print-func)
275            (ppfc-xml xml-tag name type formatter cdata print-func)))
276       (:html-link-labels
277        (if hyperlink
278            (ppfc-html-link-labels user-name name type formatter cdata nlink
279                                   print-func)
280            (ppfc-html-labels user-name name type formatter cdata print-func)))
281       (:xhtml-link-labels
282        (if hyperlink
283            (ppfc-html-link-labels xml-user-name name type formatter cdata nlink
284                                   print-func)
285            (ppfc-xhtml-labels xml-tag user-name name type formatter cdata
286                               print-func)))
287       ((or :xml-link-labels :ie-xml-link-labels)
288        (if hyperlink
289            (ppfc-html-link-labels xml-user-name name type formatter cdata nlink
290                                   print-func)
291            (ppfc-xml-labels xml-tag user-name name type formatter cdata
292                             print-func))))))
293
294
295 (defun view-has-links-p (view)
296   (in (category view) :html-link :xhtml-link :xml-link :ie-xml-link
297       :html-link-labels :xhtml-link-labels :xml-link-labels
298       :ie-xml-link-labels))
299
300 (defun initialize-view-by-category (obj-cl view)
301   "Initialize a view based upon a preset category"
302   (unless (in (category view) :compact-text :compact-text-labels
303               :html :html-labels :html-link-labels
304               :xhtml :xhtml-labels :xhtml-link-labels
305               :xhtml-link :html-link
306               :xml :xml-labels :xml-link :ie-xml-link
307               :xml-link-labels :ie-xml-link-labels)
308     (error "Unknown view category ~A" (category view)))
309   
310   (unless (slots view) (setf (slots view) (default-print-slots obj-cl)))
311
312   (let ((links '())
313         (print-func (make-array 10 :fill-pointer 0 :adjustable t)))
314
315     (do* ((slots (slots view) (cdr slots))
316           (slot-name (car slots) (car slots))
317           (slot (find-slot-by-name obj-cl slot-name)
318                 (find-slot-by-name obj-cl slot-name)))
319          ((null slots))
320       (unless slot
321         (error "Slot ~A is not found in class ~S" slot-name obj-cl))
322       
323       (push-print-fun-code (category view) slot (length links) print-func)
324       (when (> (length slots) 1)
325         (vector-push-extend '(write-char #\space s) print-func))
326
327       (when (and (view-has-links-p view) (esd-hyperlink slot))
328         (push (slot-definition-name slot) links)))
329
330     (vector-push-extend 'x print-func) ;; return object
331     (setf (obj-data-print-code view) `(lambda (x s links)
332                                        (declare (ignorable s links))
333                                        ,@(map 'list #'identity print-func)))
334     (setf (obj-data-printer view)
335           (compile nil (eval (obj-data-print-code view))))
336     
337     (setf (link-slots view) (nreverse links)))
338
339   (finalize-view-by-category view)
340   view)
341
342 (defun finalize-view-by-category (view)
343   (case (category view)
344     ((or :compact-text :compact-text-labels)
345      (initialize-text-view view))
346     ((or :html :xhtml :html-labels :xhtml-labels)
347      (initialize-html-view view))
348     ((or :xml :xml-labels)
349      (initialize-xml-view view))
350     ((or :html-link :html-link-labels)
351      (initialize-html-view view)
352      (setf (link-href-start view) "a href=")
353      (setf (link-href-end view) "a")
354      (setf (link-ampersand view) "&"))
355     ((or :xhtml-link :xhtml-link-labels)
356      (initialize-html-view view)
357      (setf (link-href-start view) "a href=")
358      (setf (link-href-end view) "a")
359      (setf (link-ampersand view) "&amp;"))
360     ((or :xml-link :xml-link-labels)
361      (initialize-xml-view view)
362      (setf (link-href-start view)
363            "xmllink xlink:type=\"simple\" xlink:href=")
364      (setf (link-href-end view) "xmllink")
365      (setf (link-ampersand view) "&amp;"))
366     ((or :ie-xml-link :ie-xml-link-labels)
367      (initialize-xml-view view)
368      (setf (link-href-start view) "html:a href=")
369      (setf (link-href-end view) "html:a")
370      (setf (link-ampersand view) "&amp;"))))
371
372
373 ;;;; *************************************************************************
374 ;;;;  View Data Format Section
375 ;;;; *************************************************************************
376
377 (defun class-name-of (obj)
378   (string-downcase (class-name (class-of obj))))
379
380 (defvar +newline-string+ (format nil "~%"))
381
382 (defun write-user-name-maybe-plural (obj nitems strm)
383   (write-string
384    (if (> nitems 1)
385        (hyperobject-class-user-name-plural obj)
386        (hyperobject-class-user-name obj))
387    strm))
388
389 (defun initialize-text-view (view)
390   (setf (list-start-printer view)
391         (compile nil
392                  (eval '(lambda (obj nitems strm)
393                          (write-user-name-maybe-plural obj nitems strm)
394                          (write-char #\: strm)
395                          (write-char #\Newline strm)))))
396   (setf (list-start-indent view) t)
397   (setf (obj-data-indent view) t)
398   (setf (obj-data-end-str view) +newline-string+))
399
400 (defun html-list-start-func (obj nitems strm)
401   (write-string "<div class=\"ho-username\">" strm)
402   (write-user-name-maybe-plural obj nitems strm)
403   (write-string "</div><div class=\"" strm)
404   (write-string (class-name-of obj) strm)
405   (write-string "\"><ul>" strm)
406   (write-char #\newline strm))
407
408 (defun initialize-html-view (view)
409   (initialize-text-view view)
410   (setf (file-start-str view) (format nil "<html><body>~%"))
411   (setf (file-end-str view) (format nil "</body><html>~%"))
412   (setf (list-start-indent view) t)
413   (setf (list-start-printer view) #'html-list-start-func)
414   (setf (list-end-printer view) (format nil "</ul></div>~%"))
415   (setf (list-end-indent view) t)
416   (setf (obj-start-indent view) t)
417   (setf (obj-start-printer view) "<li>")
418   (setf (obj-end-indent view)  t)
419   (setf (obj-end-printer view)  (format nil "</li>~%"))
420   (setf (obj-data-indent view) nil))
421
422 (defun initialize-xhtml-view (view)
423   (initialize-text-view view)
424   (setf (file-start-str view) (format nil "<html><body>~%"))
425   (setf (file-end-str view) (format nil "</body><html>~%"))
426   (setf (list-start-indent view) t)
427   (setf (list-start-printer view) #'html-list-start-func)
428   (setf (list-end-printer view) (format nil "</ul></div>~%"))
429   (setf (list-end-indent view) t)
430   (setf (obj-start-indent view) t)
431   (setf (obj-start-printer view) "<li>")
432   (setf (obj-end-indent view)  t)
433   (setf (obj-end-printer view) (format nil "</li>~%"))
434   (setf (obj-data-indent view) nil))
435
436 (defun xmlformat-list-end-func (x strm)
437   (write-string "</" strm)
438   (write-string (class-name-of x) strm)
439   (write-string "list" strm)
440   (write-string ">" strm)
441   (write-char #\newline strm))
442
443 (defun xmlformat-list-start-func (x nitems strm)
444   (write-char #\< strm)
445   (write-string (class-name-of x) strm)
446   (write-string "list><title>" strm)
447   (write-user-name-maybe-plural x nitems strm)
448   (write-string ":</title>" strm)
449   (write-char #\newline strm))
450
451 (defun initialize-xml-view (view)
452   (initialize-text-view view)
453   (setf (file-start-str view) "") ; (std-xml-header)
454   (setf (list-start-indent view)  t)
455   (setf (list-start-printer view) #'xmlformat-list-start-func)
456   (setf (list-end-indent view) t)
457   (setf (list-end-printer view) #'xmlformat-list-end-func)
458   (setf (obj-start-printer view) (format nil "<~(~a~)>" (object-class-name view)))
459   (setf (obj-start-indent view) t)
460   (setf (obj-end-printer view) (format nil "</~(~a~)>~%" (object-class-name view)))
461   (setf (obj-end-indent view) nil)
462   (setf (obj-data-indent view) nil))
463
464
465 ;;; File Start and Ends
466
467 (defun fmt-file-start (view strm)
468   (awhen (file-start-str view)
469          (write-string it strm)))
470
471 (defun fmt-file-end (view strm)
472   (awhen (file-end-str view)
473          (write-string it strm)))
474
475 ;;; List Start and Ends
476
477 (defun fmt-list-start (obj view strm indent num-items)
478   (when (list-start-indent view)
479     (indent-spaces indent strm))
480   (awhen (list-start-printer view)
481          (if (stringp it)
482              (write-string it strm)
483              (funcall it obj num-items strm))))
484
485 (defun fmt-list-end (obj view strm indent num-items)
486   (declare (ignore num-items))
487   (when (list-end-indent view)
488       (indent-spaces indent strm))
489   (awhen (list-end-printer view)
490          (if (stringp it)
491              (write-string it strm)
492              (funcall it obj strm))))
493
494 ;;; Object Start and Ends
495
496 (defun fmt-obj-start (obj view strm indent)
497   (when (obj-start-indent view)
498     (indent-spaces indent strm))
499   (awhen (obj-start-printer view)
500          (if (stringp it)
501              (write-string it strm)
502              (funcall it obj strm))))
503
504 (defun fmt-obj-end (obj view strm indent)
505   (when (obj-end-indent view)
506     (indent-spaces indent strm))
507   (awhen (obj-end-printer view)
508          (if (stringp it)
509              (write-string it strm)
510              (funcall it obj strm))))
511   
512 ;;; Object Data 
513
514
515 (defun make-link-start (view fieldfunc fieldvalue refvars link-printer)
516   (with-output-to-string (s)
517     (write-string (link-href-start view) s)
518     (write-char #\" s)
519     (let ((link-page (link-page view)))
520       (cond
521         ((null link-printer)
522          (write-string (make-url link-page) s)
523          (write-string "?func=" s)
524          (write-simple fieldfunc s)
525          (write-string (link-ampersand view) s)
526          (write-string "key=" s)
527          (write-simple fieldvalue s)
528          (dolist (var refvars)
529            (write-string (link-ampersand view) s)
530            (write-simple (car var) s)
531            (write-char #\= s)
532            (write-simple (cdr var) s)))
533         (link-printer
534          (funcall link-printer link-page fieldfunc fieldvalue refvars s))))
535     (write-char #\" s)))
536   
537 (defun make-link-end (obj view fieldname)
538   (declare (ignore obj fieldname))
539   (link-href-end view))
540
541 (defun fmt-obj-data (obj view strm indent refvars link-printer)
542   (when (obj-data-indent view)
543     (indent-spaces indent strm))
544   (if (link-slots view)
545       (fmt-obj-data-with-link obj view strm refvars link-printer)
546       (fmt-obj-data-plain obj view strm))
547   (awhen (obj-data-end-str view)
548          (write-string it strm)))
549
550 (defun fmt-obj-data-plain (obj view strm)
551   (awhen (obj-data-printer view)
552          (funcall it obj strm nil)))
553
554 (defun fmt-obj-data-with-link (obj view strm refvars link-printer)
555   (let ((refvalues '()))
556     (declare (dynamic-extent refvalues))
557     ;; make list of hyperlink link fields for printing to refstr template
558     (dolist (name (link-slots view))
559       (awhen (find name (hyperobject-class-hyperlinks obj) :key #'name)
560              (push (make-link-start view (lookup it) (slot-value obj name)
561                                     (append (link-parameters it) refvars)
562                                     link-printer)
563                    refvalues)
564              (push (make-link-end obj view name) refvalues)))
565     (funcall (obj-data-printer view) obj strm (nreverse refvalues))))
566
567 (defun obj-data (obj view)
568   "Returns the objects data as a string. Used by common-graphics outline function"
569   (with-output-to-string (s) (fmt-obj-data-plain obj view s)))
570
571 ;;; Display method for objects
572
573
574 (defun load-all-subobjects (objs)
575   "Load all subobjects if they have not already been loaded."
576   (dolist (obj (mklist objs))
577     (dolist (subobj (hyperobject-class-subobjects obj))
578       (awhen (slot-value obj (name-slot subobj))
579              (load-all-subobjects it))))
580   objs)
581
582 (defun view-hyperobject (objs view category strm &optional (indent 0) filter
583                          subobjects refvars link-printer)
584   "Display a single or list of hyperobject-class instances and their subobjects"
585   (let-when (objlist (mklist objs))
586     (let ((nobjs (length objlist))
587           (*print-pretty* nil)
588           (*print-circle* nil)
589           (*print-escape* nil)
590           (*print-readably* nil)
591           (*print-length* nil)
592           (*print-level* nil))
593       (fmt-list-start (car objlist) view strm indent nobjs)
594       (dolist (obj objlist)
595         (unless (and filter (not (funcall filter obj)))
596           (fmt-obj-start obj view strm indent)
597           (fmt-obj-data obj view strm (1+ indent) refvars link-printer)
598           (when (and subobjects (hyperobject-class-subobjects obj))
599             (dolist (subobj (hyperobject-class-subobjects obj))
600               (aif (slot-value obj (name-slot subobj))
601                    (view-hyperobject it
602                                      (get-category-view (car (mklist it))
603                                                         category)
604                                      category strm (1+ indent) filter
605                                      subobjects refvars link-printer))))
606           (fmt-obj-end obj view strm indent)))
607       (fmt-list-end (car objlist) view strm indent nobjs)))
608   objs)
609
610
611 (defun view (objs &key (stream *standard-output*) category view
612              filter subobjects refvars file-wrapper link-printer)
613   "EXPORTED Function: prints hyperobject-class objects. Calls view-hyperobject"
614   (let-when (objlist (mklist objs))
615     (when category
616       (setq view (get-category-view (car objlist) category)))
617     (unless view
618       (setq view (default-view (class-of (car objlist)))))
619     (when file-wrapper
620       (fmt-file-start view stream))
621     (view-hyperobject objlist view category stream 0 filter subobjects refvars
622                       link-printer)
623     (when file-wrapper
624       (fmt-file-end view stream)))
625   objs)
626
627
628 ;;; Misc formatting
629
630 (defun fmt-comma-integer (i)
631   (format nil "~:d" i))