Skip to content
Snippets Groups Projects
stream.lisp 39.7 KiB
Newer Older
ram's avatar
ram committed
(defun indenting-out (stream char)
  (let ((sub-stream (indenting-stream-stream stream)))
    (funcall (stream-out sub-stream) sub-stream char)
    (if (char= char #\newline)
	(indenting-indent stream sub-stream))))

;;; Indenting-Sout writes a string to an indenting stream.

(defun indenting-sout (stream string start end)
  (declare (simple-string string) (fixnum start end))
  (do ((i start)
       (sub-stream (indenting-stream-stream stream)))
      ((= i end))
    (let ((newline (position #\newline string :start i :end end)))
      (cond (newline
	     (funcall (stream-sout sub-stream) sub-stream string i (1+ newline))
	     (indenting-indent stream sub-stream)
	     (setq i (+ newline 1)))
	    (t
	     (funcall (stream-sout sub-stream) sub-stream string i end)
	     (setq i end))))))

;;; Indenting-Misc just treats just the :Line-Length message differently.
;;; Indenting-Charpos says the charpos is the charpos of the base stream minus
;;; the stream's indentation.

(defun indenting-misc (stream operation &optional arg1 arg2)
  (let* ((sub-stream (indenting-stream-stream stream))
	 (method (stream-misc sub-stream)))
    (case operation
      (:line-length
       (let ((line-length (funcall method sub-stream operation)))
	 (if line-length
	     (- line-length (indenting-stream-indentation stream)))))
      (:charpos
       (let* ((sub-stream (indenting-stream-stream stream))
	      (charpos (funcall method sub-stream operation)))
	 (if charpos
	     (- charpos (indenting-stream-indentation stream)))))       
      (t
       (funcall method sub-stream operation arg1 arg2)))))

(proclaim '(notinline read-char unread-char read-byte listen))