r5373: Auto commit for Debian build
[lml2.git] / htmlgen.lisp
index 6a3650d69c84ca434533bcf6ab7c08ae179ed88a..39f979f7c7c832ba067aa59cd39ec58e8f4f7d17 100644 (file)
@@ -1,6 +1,6 @@
 ;; -*- mode: common-lisp; package: lml2 -*-
 ;;
-;; $Id: htmlgen.lisp,v 1.16 2003/07/15 21:49:36 kevin Exp $
+;; $Id: htmlgen.lisp,v 1.19 2003/07/21 18:10:00 kevin Exp $
 ;;
 ;; copyright (c) 1986-2000 Franz Inc, Berkeley, CA 
 ;; copyright (c) 2003 Kevin Rosenberg
   )
 
 (defmacro html (&rest forms &environment env)
-  ;; just emit html to the current stream
-  (process-html-forms forms env))
+  (post-process-html-forms
+   (process-html-forms forms env)))
+
+(defun post-process-html-forms (input-forms)
+  "KMR: Walk through forms and combine write-strings"
+  (let (res strs last-stream)
+    (flet ((flush-strings ()
+            (when strs
+              (push `(write-string ,strs ,last-stream) res)
+              (setq strs nil)
+              (setq last-stream nil))))             
+      (do* ((forms input-forms (cdr forms))
+           (form (car forms) (car forms)))
+          ((null forms)
+           (flush-strings)
+           (nreverse res))
+       (cond
+         ((atom form)
+          (flush-strings)
+          (push form res))
+         ((and (eq (car form) 'cl:write-string)
+               (stringp (cadr form)))
+          (if strs
+              (if (eq last-stream (third form))
+                  (setq strs (concatenate 'string strs (second form)))
+                  (progn
+                    (flush-strings)
+                    (setq strs (second form))
+                    (setq last-stream (third form))))
+              (progn
+                (setq strs (second form))
+                (setq last-stream (third form)))))
+         (t
+          (flush-strings)
+          (push (post-process-html-forms form) res)))))))
+  
 
 (defmacro html-out-stream-check (stream)
   ;; ensure that a real stream is passed to this function
     (named-function html-write-string-function
       (lambda (ent args argsp body)
        (declare (ignore ent args argsp))
-       `(progn ,@(mapcar #'(lambda (bod)
-                             `(write-string ,bod *html-stream*))
-                         body))))
+       (if (= (length body) 1)
+           `(write-string ,(car body) *html-stream*)
+         `(progn ,@(mapcar #'(lambda (bod)
+                               `(write-string ,bod *html-stream*))
+                           body)))))
   
   (named-function html-write-string-print-function
     (lambda (ent cmd args form subst unknown stream)