;(QUOTE (((EDIT X) - The Lisp List Editor) (TYPE: % MACRO) (ARGUMENT: % X - A Literal Atom with a list or EXPR value) (VALUE: % X) (SIDE EFFECTS: Invokes the list editor on a copy of (DEFEXP X) ,) (% i.e. on an expression which defines X, and evaluates) (% the result of the editing.) (ERRORS: % None) (EXAMPLES:) ((EDIT EXEC) - invokes the editor on the expression:) (% (DEFINE EXEC (QUOTE (PRINT (EVAL (READ)))))) ((EDIT EDIT) - invokes the editor on the expression:) (% (MACRO EDIT FORM (EDITL (DEFEXP (CADR FORM)))))))
(MACRO EDIT FORM (EDITL (DEFEXP (CADR FORM))))
(QUOTE ())
;(QUOTE (((EDITL L) - edit a list) (TYPE: % EXPR) (ARGUMENT: % L - a non nil list) (VALUE: % The edited value of L) (SIDE EFFECTS: Invokes the lisp list editor on a copy of L.) (ERRORS: % None) (EXAMPLES:) ((SETQ FileFns (EDITL (DIRFILE (QUOTE FILE)))) - Sets the variable FileFns) (% % to the result of editing a list of the functions on the file FILE.) ((EDITL (QUOTE (A B C))) - lets you edit the list (A B C) . The value is the) (% % new list.)))
;(QUOTE (((EditMove CHAIN COM) - the editor%'s move operation) (ARGUMENTS: CHAIN - the editor chain) (% % % % % % % % % % COM - a number 0 <= COM <= (LENGTH (CAR CHAIN))) (VALUE: A new value for CHAIN) (DESCRIPTION: If COM = 0, EditMove returns (CDR CHAIN) , i.e. it) (% % moves up the chain. Otherwise it returns (CONS (NTH CHAIN COM) CHAIN) ,) (% % i.e. it adds the specified element to the edit chain, or, it moves down) (% % into the current expression.)))
;(QUOTE (((EditMod CURRENT LENGTH COM AUX A1 A2) - the list modification routine) (ARGUMENTS: CURRENT - the top of the edit chain) (% % % % % % % % % % LENGTH - the length of CURRENT) (% % % % % % % % % % COM - the 1st element of the editor command) (% % % % % % % % % % AUX - the rest of the editor command) (% % % % % % % % % % A1 - (CAR AUX)) (% % % % % % % % % % A2 - (CADR AUX)) (VALUE: NOT USEFUL) (DESCRIPTION: Performs the specified modification of CURRENT. EditMod is) (% % performed solely for its side effect%; its value will vary from one use) (% % to another.)))
(DEFINE EditMod (CURRENT LENGTH COM AUX A1 A2) (IF (AND (NUMBERP COM) (<= (ABS COM) (ADD1 LENGTH))) (SPLICE CURRENT AUX COM) (SELECTQ COM (T (EditMod CURRENT LENGTH A1 (READLINES) () ())) (N (SPLICE CURRENT AUX (ADD1 LENGTH))) (R (DSUBST A2 A1 CURRENT)) (PI (IF (AND (<= 1 A1) (<= A1 A2) (<= A2 LENGTH)) (LET ((X (CDRS CURRENT (SUB1 A1))) (N (ADD1 (- A2 A1)))) (RPLACD (RPLACA X (CARS X N)) (CDRS X N))) (EditErr COM))) (PO (IF (LISTP (NTH CURRENT A1)) (EditMod CURRENT LENGTH A1 (NTH CURRENT A1) () ()) (EditErr COM))) (EditErr COM))))
(QUOTE ())
;(QUOTE (((SPLICE L L1 N) - the list splicing function) (ARGUMENTS: L% - the list to be changed) (% % % % % % % % % % L1 - the list to be spliced into L) (% % % % % % % % % % N - the position indicator) (VALUE: NOT USEFUL) (DESCRIPTION: Splices L1 into L at a position indicated by N.) (% % IF N > 0 then the elements of L1 replace the Nth element of L,) (% % otherwise, the elements of L1 are inserted before the (ABS N) th) (% % element of L.)))
(DEFINE SPLICE (L L1 N) (COND ((< N -1) ((LAMBDA (L) (RPLACD L (NCONC L1 (CDR L)))) (CDRS L (- (MINUS N) 2)))) ((< N 1) (RPLACAD L (NCONC L1 (CONS (CAR L) (CDR L))))) ((< N 2) (RPLACAD L (NCONC L1 (CDR L)))) (T (LET ((L (CDRS L (- N 2)))) (RPLACD L (NCONC L1 (CDDR L)))))))
(QUOTE ())
;(QUOTE (((EditFind CHAIN TARGET XFN) - find the specified expression) (ARGUMENTS: CHAIN - the edit chain) (% % % % % % % % % % TARGET - the expression to be found) (% % % % % % % % % % XFN - an escape object to be invoked on the new edit chain) (VALUE: a new edit chain) (DESCRIPTION: Performs a depth first search of the top of the edit chain,) (% % looking for TARGET. Returns a new CHAIN if it finds TARGET, or just) (% % CHAIN if it doesn%'t)))
;(QUOTE (((EditSearch CHAIN PAT XFN) - the editor search routine) (ARGUMENTS: CHAIN - the edit chain) (% % % % % % % % % % PAT - the pattern to search for) (% % % % % % % % % % XFN - an escape function for aborting via OK!) (VALUE: NOT USEFUL) (DESCRIPTION: Invokes the list editor on each list in (CAR CHAIN) which) (contains PAT.)))
(DEFINE EditSearch (CHAIN PAT XFN) (PROGN (IF (MEMBER PAT (CAR CHAIN)) (Edit1 CHAIN () XFN)) (MAPNIL (LAMBDA (X) (IF (LISTP X) (EditSearch (CONS X CHAIN) PAT XFN))) (CAR CHAIN))))
(QUOTE ())
;(QUOTE (((READLINES) - read a series of pseudo text lines) (VALUE: A list of lists of atoms) (DESCRIPTION: Repeatedly reads lines of expressions until) (% % an empty one is encountered.)))
;(QUOTE (((EditErr EXP) - cause an edit error) (ARGUMENT: EXP - the offending expression) (VALUE: NOT USEFUL) (DESCRIPTION: Causes an iLISP error passing along EXP.)))
;(QUOTE (((EditRead CURRENT) - read the next editor command) (ARGUMENT: CURRENT - the top of the edit chain) (VALUE: The next expression on CON:) (DESCRIPTION: If there are no expressions left on CON:,) (% % EditRead clears the screen and re-presents the current) (% % expression before perforing a READ. It also binds the) (% % read macro character # so you can refer to elements of) (% % the current expression.)))
(DEFINE EditRead (CURRENT) (LET ((# (QUOTE (COPY (NTH CURRENT (READ))))) (N 1)) (IF (NULL (READP)) (MAP (LAMBDA (X) (PROGN (PRIN1 N) (TAB 3) (PRINT X) (SETQ N (ADD1 N)))) CURRENT EQ (CS))) (CAR (ERRORSET T (READ)))))
(QUOTE ())
;(QUOTE (((Edit1 CHAIN COM XFN) - the iLISP list editor) (TYPE: EXPR) (ARGUMENTS: CHAIN - the edit chain, a list of current expressions) (% % % % % % % % % % COM - the editor command to be performed) (% % % % % % % % % % XFN - the escape function to be executed by OK!) (VALUE: Returns CHAIN when COM = OK) (DESCRIPTION: Performs the editing operation described by COM. This may) (% % involve adding to or modifying CHAIN. If COM = OK then Edit1 simply) (% % returns CHAIN, otherwise it recalls itself on the new CHAIN calling) (% % EditRead for the next value of COM.)))