(setq SCCS-editor "@(#)editor.l 1.1 10/2/80")
; editor from bbn-lisp c. 1968
; (transcribed by R. Fateman for UNIX LISP, Oct., 1977)
; (modified and enhanced by P. Pifer, May, 1978)
; (corrected again by R. Fateman for VAX Unix Lisp, Dec., 1978)
; (cleaned up, commented and compiled by J. Foderaro, Aug., 1979)
; ( ... fixed bug in ^ command)
(declare (special edok em pf pl l))
(setq supereditflg t)(setq printflag t)(setq edrptcnt nil)
;--- remedit - removes all traces of the editor from the oblist.
; Note that if the editor is compiled, the code space
(mapc (function (lambda (x) (set x nil)))
'(editmacros findflag supereditflg edrptcnt
printflag printlevel maxlevel))
(mapc (function (lambda (x) (putd x nil)))
'(editf editv tconc eprint eprint1 printlevel dsubst
editcoms edit1f edit2f edit2af edit4e
editqf edit4e edit4f edit4f1 editnth bpnt
bpnt0 subpair subpr ri ro li lo bi bo
ldiff nthcdr attach edite editcom editdefault
; substitute a for b in c
(t (cons (subst a b (car c)) (subst a b (cdr c)))))))
(rplacd p (car (rplaca p (list x)))))
(t (rplacd p (cdr (rplacd (cdr p) (list x))))))))
;--- printlevel - x : new value
; set the printlevel to x and return the old value
; [change this to prog1 ]
;--- editf - funcname : name of function to edit
; - [cmds] : commands to apply right away
; This is the starting point in the editor. You specify the
; file you wish to edit and perhaps some initial commands to
; the editor. If the function is not machine coded you
(cond ((or (null a) (bcdp a))
(return '(not editable))))
(putd (car x) (car (edite a (cdr x) nil)))
(cond ((null z) (return z))
((equal y (car z)) (rplaca z x) (go l)))
(cond ((null (atom (car z))) (dsubst x y (car z))))
; directly substitutes all occurances of x in form z with y.
; It uses rplaca and does not copy the structure.
(t (dsubst x y (car z)))))
(def editcoms (lambda (c) (mapc (function editcom) c)))
(cond ((null (cdr l)) (err nil))
(cond ((greaterp c (length (car l))) (err nil))
(t (cons (car (nthcdr (sub1 c) (car l) )) l))))
((greaterp (times c -1) (length (car l)))
(t (cons (car (nthcdr (plus (length (car l)) c) (car l) ))
(cond ((greaterp (car c) 0)
(cond ((greaterp (car c) (length (car l)))
(t (rplaca l (edit2af (sub1 (car c))
(greaterp (times -1 (car c)) (length (car l))))
(t (rplaca l (edit2af (sub1 (times -1 (car c)))
(cond ((null (equal n 0))
(rplacd (nthcdr (sub1 n) x)
(t (nthcdr (add1 n) x ))))))
(rplacd x (nconc (cdr r) (cdr x))))
(rplacd x (nconc (cdr r) (cdr x))))
((edit4e (car x) (car y))
(edit4e (cdr x) (cdr y)))))))
(return (cond ((setq q1 (member s (cdar l)))
(setq l (cons (caar l) l))))))))))
(setq ll (cond ((eq n 'n) (cons (caar l) l))
(cond ((and n (not (numberp n))) (setq n 1)))
lp (cond ((edit4f1 s x maxlevel)
(setq l (nconc (car ff) ll))
(cond ((null (setq ll (cdr ll))) (err nil))
((and (setq x (member x (car ll)))
(null (atom (setq x (cdr x)))))
(cond ((null (greaterp lvl 0)) (return nil)))
lp (cond ((atom a) (return nil))
(equal 0 (setq n (sub1 n)))))
(equal 0 (setq n (sub1 n)))))
(edit4f1 s (car a) (sub1 lvl))
(return (tconc (car a) ff))))
(cond ((null (setq n (cond ((or (null (lessp n 0))
(cond ((equal 0 (car x)) (setq y (car l)))
(t (setq y (car (editnth (car l) (car x))))))
(cond ((null (cdr x)) (setq n 3))
((null (numberp (cadr x))) (go b1))
(setq n (plus (cadr x) 2)))
(setq oldl (printlevel (difference d n)))
(cond ((atom (errset (eprint l) t))
(cond ((or (null a) (atom (car a))) (err nil)))
(rplacd (last (car a)) (cdr a))
(setq b (editnth (car a) n))
(cond ((or (null a) (null b)) (err nil)))
(rplacd a (nconc (cdr b) (cdr a)))
(cond ((null a) (err nil)))
(rplaca a (cons (car a) (cdr a)))
(cond ((or (null a) (atom (car a))) (err nil)))
(setq b (cdr (setq a (editnth x n))))
(cond ((and a (null (greaterp (length a) (length x))))
(rplaca x (cons (car x) (cdr x)))
(cond ((atom (car x)) (err nil)))
(rplacd x (nconc (cdar x) (cdr x)))
(return (rplaca x (caar x))))))
(cond (fl (subpr x y (copy z)))
loop (cond ((or (null c) (null d)) (return z))
(t (dsubst (car d) (car c) z)
loop (cond ((equal a y) (return (reverse b)))
((null a) (return (err nil)))
(t (setq b (cons (car a) b))
(car (edite (eval (car editvx))
((lessp n 0) (cons nil x))
(t (nthcdr (sub1 n)(cdr x))))))
(setq a (cons (car y) (cdr y)))
(def eprint (lambda (x) (print (eprint1 x printlevel))))
(prog (c m em edok copied pf pl)
(cond ((null l) (setq l (list x))))
(cond (ops (cond ((dtpr (errset (mapc
(cond (pf (terpri) (editcom 'p)))
a (cond (edok (return (cdr edok))))
(cond ((atom (errset (setq c (read)) t)) (go ct)))
(cond ((dtpr (errset (editcom c) t))
(lambda (x) (editcom (list 'f x 't))))
a (cond (findflag (setq findflag nil) (editqf c))
((numberp c) (setq l (edit1f c l)))
(setq edok (cons t (last l)))
(errset ($prpr (car l)) t)
(setq l (list (last l))))
((eq c 'copy) (setq copied (copy l)))
((eq c 'restore) (setq l copied))
(cond (m (setq l (car m)))
(cond (m (setq l (car m))
(t (return (editdefault c)))))))
((numberp (setq cc (car c))) (edit2f c))
(cond ((null (cddr c)) nil)
(car (cond ((null (setq c c3)) l)
(cons (cond ((atom c2) c2)
(setq l (cons (editnth cl c2) l)))
(apply1 cc (append (cdr c) (list cl))))
(setq cc (cond ((atom (setq cc c2))
(t (cons (car cc) (cddr c)))))
(cond ((lessp c2 1) (err nil))
(t (setq pl (add 1 c2)))))
(null (cond ((null cc) nil)
(return (editdefault c)))
(subst (cond ((null c) nil)
((and (atom (cdr x)) (cdr x)) x)
(t (mapcar (function (lambda (y) (eprint1 y (sub1 lev))))
((equal e (caar l)) (car l))
(eval (cons f (mapcar '(lambda (z) (list 'quote z))
(prog (poport n f ff l df)
(setq l (cons nil (cadr x)))
(outfile (setq n (concatp 'mkfl))))
l1 (cond ((null (setq l (cdr l))) (go e1)))
((null (setq df (getd f))) (go l1))
(t (setq df (list 'def f df))
(null (eval (cons 'exec (cons '/bin/mv (cons n (cons ff nil)))))))))
(prog (i poport n f ff l df)
(setq l (cons nil (cadr x)))
(outfile (setq n (concatp 'apfl))))
l1 (cond ((eq (setq f (read i poport)) 'eof)
l2 (cond ((null (setq l (cdr l))) (go e1)))
((null (setq df (getd f))) (go l2))
(t (setq df (list 'def f df))
(null (eval (cons 'exec (cons '/bin/mv (cons n (cons ff nil)))))))))
(return (eval (list 'process $handy))))
(concat (concat $handy (car $list))