$macro_file BASIC;

{******************************************************************************}
{                                MULTI-EDIT MACRO                              }
{                                                                              }
{Name: BASTEMP                                                                 }
{                                                                              }
{Description: Creates compiled or interpreted basic language constructs based  }
{  on a single character to the left of the current cursor position.           }
{                                                                              }
{               (C) Copyright 1988 by American Cybernetics, Inc.               }
{******************************************************************************}

$MACRO BASTEMP;

	DEF_INT(Temp_Col,Temp_Insert,Temp_Line_Num,Next_Line_Num,For);

	Temp_Insert := Insert_Mode;
	If (At_EOL = FALSE) Then
		Goto END_OF_MAC;
	End;

	Insert_Mode := True;
	Temp_Col := C_COL;

	Left;
{check the character to the left of the cursor}

	If (XPos(Cur_Char,'Ii',1)) Then
{If it is an 'I', then make an 'IF THEN' construct}
		Goto_Col(Temp_Col);
{Create construct}
		Text('F  THEN');
		Goto_Col(Temp_Col + 2);
		Goto END_OF_MAC;
	End;

	If (XPos(Cur_Char,'WwFf',1)) Then
{If it is an 'W', then make an 'WHILE WEND' construct}
{If it is an 'F', then make an 'FOR NEXT' construct}
		For := (XPos(Cur_Char,'Ff',1) > 0);
		Goto MAKE_FOR_WHILE;
	End;

{If none of the above, then return cursor to the original position and exit}
	Goto_Col(Temp_Col);
	Goto END_OF_MAC;


MAKE_FOR_WHILE:
{See if line numbers are used}
	Goto_Col(1);
	If ((Val(Temp_Line_Num,Get_Word(' ')) > 0) or (C_Col = 1)) Then
{If not, set the variable to zero so no line number with be created}
		Temp_Line_Num := 0;
	End
	Else
{if so, check to see if there is a line number below}
		Down;
		Goto_Col(1);
		If ((Val(Next_Line_Num,Get_Word(' ')) > 0) or (C_Col = 1)) Then
			Next_Line_Num := 0;
		End;
		Up;
	End;
	Goto_Col(Temp_Col);
{Create first line of construct}
	If (For) Then
		Text('OR');
	End
	Else
		Text('HILE');
	End;
{Create a new line}
	Cr;
	If (Temp_Line_Num <> 0) Then
{If line numbers are used, then..}
		Goto_Col(1);
		If (Next_Line_Num <> 0) Then
{If inserting between two numbered lines, then increment next line number by 1
to allow as much room as possible for the body of the construct}
			Text(Str(Temp_Line_Num + 1));
		End
		Else
{Otherwise, increment by the "standard" 10}
			Text(Str(Temp_Line_Num + 10));
		End;
	End;
{Create the last line of the construct}
	Cr;
	If (Temp_Line_Num <> 0) Then
		Goto_Col(1);
		If (Next_Line_Num <> 0) Then
{If inserting between two numbered lines, then number the last line one less
than the next line to allow as much room as possible for the body of the
construct}
			Text(Str(Next_Line_Num - 1));
		End
		Else
{Otherwise, increment by the "standard" 10}
			Text(Str(Temp_Line_Num + 20));
		End;
	End;
	Goto_Col(Temp_Col - 1);
{Insert the proper ending statement}
	If (For) Then
		Text('NEXT');
	End
	Else
		Text('WEND');
	End;

{Place cursor in the proper place for the user to begin writing the condition
clause}
	Up;
	Up;
	Eol;
	Right;
	Goto END_OF_MAC;

END_OF_MAC:
	Insert_Mode := Temp_Insert;

END_MACRO;


{******************************************************************************}
{                                MULTI-EDIT MACRO                              }
{                                                                              }
{Name: BAS_IND                                                                 }
{                                                                              }
{Discription: Performs semi-smart indenting for BASIC source code.             }
{                                                                              }
{               (C) Copyright 1988 by American Cybernetics, Inc.               }
{******************************************************************************}
$MACRO BAS_IND;
	DEF_STR(Temp_String);
	DEF_INT(Temp_Col,Temp_Line_Num,Temp_Col2,Next_Line_Num);

	If (At_EOL = False) Then
{If we are not at the end of a line, then do a carrige return and exit}
		Cr;
		Goto END_OF_MAC;
	End;
	Temp_Col := C_COL;
{See if we are using line numbers}
	First_Word;
	Temp_Col2 := C_Col;
	GOTO_COL(1);

	Temp_String := Get_Word(' ');

	If ((Temp_String = '') or (Val(Temp_Line_Num,Temp_String) > 0) or
																										 (Temp_Line_Num <= 0)) Then
{If we aren't using line numbers do a carriage return and park cursor at the
same indent level as the line above}
		Eol;
		Cr;
		GOTO_COL(Temp_Col2);
		Goto END_OF_MAC;
	End;
{From here down means we are using line numbers}
	Eol;
	Cr;
{See if there is another line Number below}
	Down;
	Temp_String := Get_Word(' ');
	Up;
	Goto_Col(1);

	If ((Temp_String = '') or (Val(Next_Line_Num,Temp_String) > 0) or
																										 (Next_Line_Num <= 0)) Then
{If there is no line number below, just increment the "standard" 10}
		Text(Str(Temp_Line_Num + 10));
	End
	Else
{Otherwise make increment approx. halfway between the line number above and the
line number below}
		Text(Str(Temp_Line_Num + ((Next_Line_Num - Temp_Line_Num) / 2)));
	End;
	Right;

END_OF_MAC:
	Redraw;
END_MACRO;

