!* -*-TECO-*-! !~FILENAME~:! !GRIND macros for formating code.! GRIND !Grind Sexp:! !C Grind the sexp after the pointer. Uses QMiser Column to decide where to start using "Miser" format, and QFill Column as the page width to aim for. Can be undone with Undo.! 1:< FDL R !* Find the next list.! F[VB F[VZ FL FSBOUND !* Narrow bounds to that list.! F~MODELISP"N 0[Region_Query_Size' !* If not Lisp mode, query even on small region.! Z: :i*grindM(M.M &_Save_Region_and_Query)f"e ' W J [2 [3 !*** Now normalize the expression; put it into the form PRIN1 would print.! [D 128*5,32:ID !* In QD make a dispatch that! 11.*5:F D -D :M2  !* turns any whitespace into a single space,! 15.*5:F D RK :M2  !* deletes CRLFs and the indentation after them,! 12.*5:F D -D :M2  /*5:F D C !* Handle slashes and vertical bars right.! |*5:F D R @FLL  ;*5:F D L :M3  !* Skip comments, deleting indentation on next line.! (*5:F D :M3  !* Make sure no whitespace follows ('s and ''s! !"! '*5:F D :M3  )*5:F D R M3 C  !* or precedes )'s.! :I2 Z-.< 1A F_ :; D> 32I  :I3 Z-.< 1A F_ :; D>  HFD J .( 0FS VBW 0L .FS VB )J !* Include all of line, up to (, after B,! !* so that FS HPOS is accurate.! !*** Now decode the grinding parameters.! FS WIDTH-10[W !* Figure the width to aim at! FS WIDTH*2/3[C !* and the comment column.! 0FO ..Q Fill_Column F"N UW QWUC' -1FO ..Q Comment_Column +1F"G -1UC' QC[M !* Figure the place to switch to Miser fmt.! -1FO ..Q Miser_Column +1F"G -1UM' [R :IR /8+1*8 0FO ..Q Comment_Rounding F"N UR' M.M &_Indent [I !* G gets recursive macro to grind and pass 1 sexp.! !* It expects numerc arg = depth in parens.! [G @:IG` [2 S' R !* Pass by all leading quotes.! 1A-("N @FWL ' !* Atoms, just skip over.! FL-.-QW++(FS HPOSU2 Q2)"L FLL ' !* Lists that fit in line, skip over.! C Q2-QM"L !* If not yet far enough for Miser fmt,! !"! 1A F';()"L @FWL 1A-32"E C''' !* Skip 1st element, so get 2 on 1st line.! !* But if 1st element is a list, use miser fmt anyway.! FS HPOS U2 !* Q2 gets column to put rest of elements at.! !LP! 1a-32"E D O LP' !* Don't be confused by whitespace.! 1A-)"E C ' !* Until end of this list,! FS HPOSU3 1A-;"E !* Put comments at the comment column,! Q3-QC"G QC' "# Q3 R' MI L' Q3-Q2"N 13I 10I !* and for lists, indent to right place! Q2/8,9I Q2&7,32I' +1MG O LP !* and recursively grind.! ` 0MG !* DO IT! J 7F~ (DEFUN_"E !* Now, if list is (DEFUN FOO..., then! @FLL 8F= ______"E 8D .U3 L !* Get the thing after FOO onto first line,! Q3,. F~FEXPR *(Q3,. F~MACRO )"E !* and if it is a function property name,! -2D 6D''' !* get it on that line too.! J HU2U3 > !* end errset! J Z: !* Leave region around the ground sexp.! Q3,Q2 !MACSYMA Grind:! !C Format MACYSMA code. When called from ^R mode it grinds from . to , unless it is given an argument in which case it does the command point is in. When called from regular TECO it the whole buffer if given no argument or MACSYMA commands after the . if given an argument .! [0[1[9 0F[ S ERROR 1F[ BOTHCASE 0FO..Q Fundamental ..D F"E Q..D'[..D !*READ ARGS AND SET UP ..N! FS^RMODE"N F-1"G 1U0 ' !* IN ^R AND WITH ARG => DO ONE CMD! "# (B-(:))*(Z-(:))"G !* CHECK IS REASONABLE! :I*MOB Mark_out_of_boundsFSERR ' .,(:)FU1J 0U0 F=MODEMACSYMA"N OConfirm' .,q1-1000"g !Confirm! @FT Do_you_really_want_to_Grind_this_s-expression?_(Y_or_N): FI :FC - Y(  FS Echo Display C FS Echo Display) "N '' .(<.,Q1FB\$\;; %0W>)J '' !* IN ^R AND NO ARG => DO .,! "# "G U0 ' !* REG TECO WITH NON-NEG ARG => DO ^X CMDS! "# J 0U0 J ' ' !* REG TECO WITH ZERO ARG => DO EVERYTHING! -S\$\; FS S VALUE"E 0 '"# 2C . 'U9 Q9J Q0<.,(S\$\;; R .)M(M.MGrind_one_MACSYMA_statement) C> Q9+2J  !Grind one MACSYMA statement:! !C Grinds one MACSYMA statement. Args delimit the statement (exclusive of the ; or $)! [1[2[3[4[5[6[7[8[9[0[Y[Z[C[M FXC Q..OUM FS B CREA GC FN QM,Q..OUMU..O QMFSBKILL ZJI] JI[R !* PREVENT LOSSAGE AT ENDS! !*GET RID OF /* TYPE COMMENTS PUSH THEM ONTO Q-R D MARK THEM WITH $1$ COMMENTS NOT ALLOWED WITHIN ATOMS! !*GET RID OF STUFF IN DOUBLE QUOTES PUSH THEM ONTO Q-R A MARK WITH $%%%$! J I$> !*GET RID OF \ED STUFF PUSH ONTO Q-R B MARK WITH $$! J !*CHANGE / TO \ SO FLL ETC WORK! J !*GET RID OF CRS AND TABS! J J !*SAVE IMPORTANT SPACES ^H AFTER IF AND BEFORE THEN ELSE, ^R AFTER THEN ELSE ^P AFTER DO ETC AND ^R BEFORE (IF THERE WAS A SPACE THERE, ^R EITHER SIDE OF AND ETC! J J J< SDOFORINFROMNEXTSTEPTHRUUNLESSWHILE; RI R-S 1A-32"EDI'"#C'> J !*DELETE REMAINING SPACES AND REMOVE SPURIOUS CONTROL CHARS AND CHANGE [S TO (S MARKING WITH ^A! J J J J J !*PUT IN SPACES AROUND = ETC! J J;RI_C 1A-="EC'I_> !*START GRINDING, START FROM BOTTOM Q6 IS DEPTH! 0U6 J <1::; %6> < < !*SET BOUNDS ROUND EITHER FOO(...) OR ^A(....^A) SAVE OLD BOUNDS IN Q-R Y AND Z! R-S 1A-1"NC' .U9 FLL Z-.UZ BUY Q9,.FSBOUNDW 0U5 J !* IF FOO = BLOCK OR LAMBDA OR IF COMPOUND STATEMENT THEN GRIND (Q5=1)! S(R B-."E S,FS S VALUE"N 1U5'' "#B,.FBBLOCKLAMBDA FS S VALUE"L1U5' ' !*LOOK FOR IF OR DO STATEMENT (MARKED BY ^P FOR DO OR ^H FOR IF! J Q7FSQPUNWI 0; ' 0A-"E -1A-O"E 0U3 '"# -1U3 ' ' "#-1A-F"E 1U3 '"# -1A-N"E2U3'"# 3U3 ' ' ' R-S (1A-)*(1A-)"N 1U2 .U9 -S Q9-.-20"G C.U4 1A-"E FLL Q9-."E OL2 ' '"# 1A-("E FLL Q9-."E RIQ4J I 2+Q9U9 2+Q8U8 OL2 ' ' ' Q4J I ( Q9+2J I ) 4+Q9U9 4+Q8U8 ' !L2! Q9J' "# 0U2 ' Q2"ECI ( Q8+2U8 [1 Q3U1' "# ' S> > !*END OF DO AND IF HACKING! J Q5"E J' "#J JS(RI Z-1JI ' ZJ QY,Z+QZFSBOUND 1::;> Q6-1U6 -Q6"E0;' JQ6FDL> 0U8J ' "#(1A-()"ECI %8' "#0A- "NRI__C' C Q8-1U8 (1A-)*(1A- )"N (1A-)*(1A-)*(1A-;)"EC' I  Q8 ' ' '> J J J J J J JDI  ZJ-DI  J BU9 J J ZJ <.U9 0:L Q9-.-2"E2D'"#0;' > ZJ<-S$$;2DI\ GB 0A-13"EI ' ]B> ZJ<-S%$;CDI"R.U9-S$DI".,Q9KGA ]A> ZJ<-S$1$;3D0LS_0A-13"ED-D0K'"#0L' I/**/ 4RGD ]D> HFXC -1FS QP UNWIND FK GC