home *** CD-ROM | disk | FTP | other *** search
- ; fmtio.l - Copyright (c) 1984 by David Morein.
- ; this file contains miscellaneous formatted i/o routines.
- ;
- ; note - this is an initialization file, see the manual for more info.
- ;
- ; global functions:
- ;
- (global 'pp 'ppdef)
- ;
- ; load in the pretty-printer:
- ;
- ; public function pp:
- ;
- (defun pp (x)
- (progn
- (*pp1 x 0 t)
- (terpri)
- t))
- ;
- ; private function *pp1:
- ;
- (defun *pp1 (exp column newline &optional tblank
- &aux new1 new2 new3 entrycol)
- (progn
- (cond (newline (progn (terpri) (space_to_col column))))
- (setq entrycol column) ;save entry value column.
- (cond
- ((atom exp) ;exp is atomic
- (prin1 exp)
- (if tblank (princ " "))
- (setq column (+ column (length exp))))
-
- ((not (listp (cdr exp))) ;exp is a dotted pair
- (princ "(")
- (prin1 (car exp))
- (princ " . ")
- (prin1 (cdr exp))
- (princ ")")
- (if tblank (princ " "))
- (setq column (+ column (flatsize exp))))
-
- (t ;exp is a list
- (cond
- ((eq (car exp) 'backquote)
- (princ "`") (*pp1 (cadr exp) column nil tblank))
- ((eq (car exp) 'comma)
- (princ ",") (*pp1 (cadr exp) column nil tblank))
- ((eq (car exp) 'comma-at)
- (princ ",@") (*pp1 (cadr exp) column nil tblank))
- ((eq (car exp) 'quote)
- (princ "'") (*pp1 (cadr exp) column nil tblank))
- (t
- (setq new1 ;set new1 if (car exp)
- (cond ; is a special form.
- ((consp exp) (isspecial (car exp)))
- (t nil)))
-
- (setq new2 ;set new2 if
- (>= ; exp won't fit on
- (+ 8 (flatsize exp)) ; a single line.
- (- conwidth column))) ;
-
- (princ "(")
- (setq column (+ column 1))
- (setq column (*pp1 (car exp) column nil t))
- (cond
- ((cdr exp)
- (setq new3 (isspecial (cadr exp)))
- (setq column (+ column 1)) ;increment column
- (setq column ;print 2nd element
- (*pp1 (cadr exp) column (or new1 new2 new3) t))
- ;
- ; the following call to MAPCAR should be replaced with a DO.
- ;
- (mapcar ;and then rest of list.
- '(lambda (exp) (*pp1 exp (+ entrycol 2) new2 t))
- (cddr exp))))
- (princ ")") ;print right paren.
- (if tblank (princ " "))
- (setq column (+ column 1))))))) ;increment column.
- column) ;return current column.
- ;
- ; isspecial - recognizes special forms:
- ;
- (defun isspecial (exp)
- (cond
- ((eql exp 'prog) t)
- ((eql exp 'progn) t)
- ((eql exp 'cond) t)
- (t nil)))
- ;
- ;
- ; space_to_col - forces the cursor to an x-position on the current line,
- ; filling with spaces as necessary.
- ;
- (defun space_to_col (x)
- (prog ()
- (loop
- (cond
- ((< (+ (status x_position) 8) x) (princ " "))
- ((< (+ (status x_position) 4) x) (princ " "))
- ((< (status x_position) x) (princ " "))
- (t (return t))))))
- ;
- ; ppdef - pretty-prints the function definition cell of an atom:
- ;
- (defun ppdef (x)
- (cond
- ((fboundp x) (pp (getd x)))
- (t (err "***> PPDEF: arg not bound as a function."))))
- ;
- ;
- ;end of file