mini-editor.red 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. % <PSL.KERNEL>MINI-EDITOR.RED.3, 21-Sep-82 11:14:10, Edit by BENSON
  2. % Flagged internal functions
  3. %. PSL Structure Editor Module;
  4. %. Adapted By D. Morrison for PSL V1.
  5. %. Based on Nordstroms trimmed InterLISP editor
  6. %. Cleaned Up and commented by M. L. Griss,
  7. %. 8:57pm Monday, 2 November 1981
  8. %. See PH:Editor.Hlp for guide
  9. CompileTime flag('(EDIT0 QEDNTH EDCOPY RPLACEALL FINDFIRST XCHANGE XINS),
  10. 'InternalFunction);
  11. FLUID '(QEDITFNS %. Keep track of which changed
  12. !*EXPERT %. Do not print "help" if NIL
  13. !*VERBOSE %. Dont do implicit "P" if NIL
  14. PROMPTSTRING!* %. For "nicer" interface
  15. EditorReader!* %. Use RLISP etc Syntax, ala Break
  16. EditorPrinter!*
  17. CL
  18. );
  19. QEDITFNS:=NIL;
  20. !*Expert := NIL;
  21. !*Verbose := NIL;
  22. lisp procedure EDITF(FN); %. Edit a Copy of Function Body
  23. Begin scalar BRFL,X,SAVE,TRFL;
  24. %/ Capture !*BREAK, reset to NIL?
  25. X := GETD FN;
  26. If ATOM X OR CODEP CDR X then
  27. StdError BldMsg("%r is not an editable function", Fn);
  28. SAVE:=COPY CDR X;
  29. EDIT CDR X;
  30. If YESP "Change Definition?" then GO TO YES;
  31. RPLACW(CDR X,SAVE); %/ Why not Just PUTD again?
  32. RETURN NIL;
  33. YES: If NULL (FN MEMBER QEDITFNS) then
  34. QEDITFNS:=FN.QEDITFNS;
  35. RETURN FN;
  36. END;
  37. lisp procedure EDIT S; %. Edit a Structure, S
  38. begin scalar PROMPTSTRING!*;
  39. PROMPTSTRING!* := "edit> ";
  40. TERPRI();
  41. If NOT !*EXPERT then
  42. PRIN2T "Type HELP<CR> for a list of commands.";
  43. %/ Savea copy for UNDO?
  44. RETURN EDIT0(S,EDITORREADER!* OR 'READ,EDITORPRINTER!* OR 'PRINT)
  45. END;
  46. lisp procedure EDIT0(S,READER,PRINTER);
  47. Begin scalar CL,CTLS,CTL,PLEVEL,TOP,TEMP,X,NNN;
  48. TOP:=LIST S;
  49. PLEVEL:=3;
  50. B: CTL:=TOP; CTLS:=LIST CTL; CL:=CAR TOP;
  51. NEXT: If !*VERBOSE then APPLY(PRINTER,LIST EDCOPY(CL,PLEVEL));
  52. X:=APPLY(READER,NIL);
  53. If ATOM X then GO TO ATOMX else
  54. If NUMBERP CAR X then
  55. If CAR X = 0 then GO TO ILLG else
  56. If CAR X > 0 then XCHANGE(QEDNTH(CAR X - 1,CL),CTL,CDR X,CAR X)
  57. else XINS(QEDNTH(-(CAR X + 1),CL),CTL,CDR X,CAR X) else
  58. If CAR X = 'R then RPLACEALL(CADR X,CADDR X,CL) else GO TO ILLG;
  59. GO TO NEXT;
  60. F: TEMP:=FINDFIRST(APPLY(READER,NIL),CL,CTLS);
  61. If NULL TEMP
  62. then <<PRIN2T "NOT FOUND"; GO TO NEXT>>;
  63. CL:=CAR TEMP;
  64. CTLS:=CDR TEMP;
  65. CTL:=CAR CTLS;
  66. GO TO NEXT;
  67. ATOMX: If NUMBERP X then If X = 0 then CL:=CAR CTL else GO TO NUMBX
  68. else
  69. If X = 'P then !*VERBOSE OR APPLY(PRINTER,LIST EDCOPY(CL,PLEVEL)) else
  70. If X = 'OK then RETURN CAR TOP else
  71. If X = 'UP then GO TO UP else
  72. If X = 'B then BREAK() else
  73. If X = 'F then GO TO F else
  74. If X = 'PL then PLEVEL:=APPLY(READER,NIL) else
  75. If X MEMQ '(HELP !?) then EHELP() else
  76. If X EQ 'E then Apply(PRINTER,LIST EVAL Apply(READER,NIL)) else
  77. If X = 'T then GO TO B else GO TO ILLG;
  78. GO TO NEXT;
  79. UP: If CDR CTLS then GO TO UP1;
  80. PRIN2T "You are already at the top level";
  81. GO TO NEXT;
  82. UP1: CTLS:=CDR CTLS;
  83. CTL:=CAR CTLS;
  84. CL:=CAR CTL;
  85. GO TO NEXT;
  86. NUMBX: NNN := X;
  87. X:=QEDNTH(ABS(X),CL);
  88. If NULL X then <<
  89. PRIN2T "List empty";
  90. GO TO NEXT >>;
  91. If NNN > 0 then
  92. CL:=CAR X;
  93. CTL:=X;
  94. CTLS:=CTL.CTLS;
  95. GO TO NEXT;
  96. ILLG: PRIN2T "Illegal command";
  97. GO TO NEXT
  98. END;
  99. lisp procedure QEDNTH(N,L);
  100. If ATOM L then NIL else If N > 1 then QEDNTH(N-1,CDR L) else L;
  101. lisp procedure EDCOPY(L,N);
  102. If ATOM L then L else If N < 0 then
  103. "***" else EDCOPY(CAR L,N-1).EDCOPY(CDR L,N);
  104. lisp procedure RPLACEALL(A,NEW,S);
  105. If ATOM S then NIL else If CAR S = A then
  106. RPLACEALL(A,NEW,CDR RPLACA(S,NEW)) else
  107. <<RPLACEALL(A,NEW,CAR S); RPLACEALL(A,NEW,CDR S)>>;
  108. lisp procedure FINDFIRST(A,S,TRC); %. FIND Occurance of A in S
  109. Begin scalar RES;
  110. If ATOM S then RETURN NIL;
  111. If A MEMBER S then RETURN S. TRC;
  112. RETURN(FINDFIRST(A,CAR S,S.TRC) or FINDFIRST(A,CDR S,TRC));
  113. %/ Add a PMAT here
  114. END;
  115. lisp procedure XCHANGE(S,CTL,NEW,N);
  116. If ATOM S then <<PRIN2T "List empty"; NIL>> else
  117. If N = 1 then <<RPLACA(CTL,NCONC(NEW,CDR S)); CL:=CAR CTL>> else
  118. RPLACD(S,NCONC(NEW,If CDDR S then CDDR S else NIL));
  119. lisp procedure XINS(S,CTL,NEW,N);
  120. If ATOM S then <<PRIN2T "List empty"; NIL>> else
  121. If N = 1 then <<RPLACA(CTL,NCONC(NEW,S)); CL:=CAR CTL>> else
  122. RPLACD(S,NCONC(NEW,CDR S));
  123. UNFLUID '(CL);
  124. lisp procedure EHELP;
  125. << EvLoad '(Help);
  126. DisplayHelpFile 'Editor >>;
  127. PUT('EDIT, 'HelpFunction, 'EHELP);
  128. PUT('EDITF, 'HelpFunction, 'EHELP);
  129. PUT('EDITOR, 'HelpFunction, 'EHELP);
  130. END;