home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR36
/
KEXX.ZIP
/
SINDENT.KML
< prev
next >
Wrap
Text File
|
1989-12-20
|
6KB
|
165 lines
*
* Smart autoindenting support - determine indentation based on context
* Some Template Logic to support matching braces and do-end pairs
*
:NUMENTER
*
'Editv Getf Smart'; If Smart = "" Then Smart = 0
If \Smart Then Do
* Just do normal ENTER function
'Macro ENTER'
Exit
End
LeftMargin = Margins.1()
'Editv Getf CSupport'; If CSupport = "" Then CSupport = 0
'Editv Getf RexxSupport'; If RexxSupport = "" Then RexxSupport = 0
'Editv Getf Templates'; If Templates = "" Then Templates = 0
If Templates = "" Then Templates = 0
TabOffset.2 = 1
TabCmd.2 = "Tab"
* Decipher Template Relative Tab Values
If Templates Then Do
TabOffset.1 = 1; TabOffset.2 = 1; TabOffset.3 = 1
*Parse would help out handling this
'Editv Getf Indents'
Do XX = 1 to 3
YY = Word(Indents, XX); If YY \= "" Then TabOffset.XX = YY
TabCmd.XX = "Tab"
If TabOffset.XX < 0 Then Do
TabOffset.XX = - TabOffset.XX
TabCmd.XX = 'TabB'
End
End
End
TabsBack = TabOffset.2
If TabCmd.2 = "Tab"
Then TabsBackCmd = "TabB"
Else TabsBackCmd = "Tab"
Drop XX YY Temp X
* Put cursor at first character in appropriate line
If Command() Then 'SOS Current FirstChar'
Else If EOF() Then 'SOS CUp FirstChar'
Else If \Blank() Then 'SOS FirstChar'
* Set commonly referenced values
C = Lower(Curline.3()); L = Length(C)
***** C Language Support ****
If CSupport Then Do
LastChar = SubStr(C, Max(L, 1))
W = Lower(Word(C, 1))
If SubStr(W, 1, 2) = '/*' | substr(c, max(l - 1, 1), 1) = '*/' Then Do
If \Tab() Then Do TabsBack; 'SOS' TabsBackCmd; End
End
Else If Pos(' 'W' ',' if else for while ') \= 0 Then Do
If LastChar = ')' | LastChar = '{' | C = 'else' Then Do
If LastChar = '{' & Templates Then Do
* Handle matching braces
'SOS SaveCol'
Do TabOffset.3; 'SOS' TabCmd.3; End
'SOS LineAdd'; 'Text }'; 'Up'; 'SOS RestoreCol'
End
Do TabOffset.2; 'SOS' TabCmd.2; End
End
End
Else If W = '}' | W = 'break;' Then Do TabsBack; 'SOS' TabsBackCmd; End
Else If W = 'switch' | (W = 'else' & LastChar \= ';') Then Do
Do TabOffset.2; 'SOS' TabCmd.2; End
End
Else If W = 'do' | LastChar = ')' | LastChar = ':' Then Do
Do TabOffset.2; 'SOS' TabCmd.2; End
End
Else If Lastchar = ';' Then Do
'Up'
L1 = Lower(Curline.3()); PrevLast = SubStr(L1, Max(Length(L1), 1))
W1 = Word(L1, 1)
If SubStr(L1, 1, Cursor.4() - 1) \= '' & SubStr(L1, 1, 1) = '' Then
If Prevlast \= '{' & Prevlast \= ':' Then Do
Do TabsBack; 'SOS' TabsBackCmd; End
End
Else Nop
Else If Pos(' 'W1' ', ' if while else for ') \= 0 Then Do
Do TabsBack; 'SOS' TabsBackCmd; End
End
'Down'
End
Else If Word(C, 1) = '{' & Templates Then Do
Do TabsBack; 'SOS' TabsBackCmd; End
'SOS SaveCol'
Do TabOffset.1; 'SOS' TabCmd.1; End
'Set Margins' Cursor.4() '*'; 'LeftAdjust'; 'SOS RestoreCol'
Do TabOffset.3; 'SOS' TabCmd.3; End
'SOS LineAdd'; 'Text }'; 'Up'; 'SOS RestoreCol'
Do TabOffset.2; 'SOS' TabCmd.2; End
End
End
***** KEX KML REX CMD RXT ****
Else If RexxSupport Then Do
* note: multiple IFs are used so everything fits in 80 columns
If SubStr(C, Max(L - 3, 1)) = 'then' | C = 'else' Then Do
Do TabOffset.2; 'SOS' TabCmd.2; End
End
Else If SubStr(C, Max(L-1, 1), 2) = 'do' | Word(C, 1) = 'do' Then Do
If Templates Then Do
CC = ' 'Curline.3()' '; I = ' Do DO do '; J = 'End END end '
Matching = 'end'
Do K = 1 To 9 By 4
If Pos(SubStr(I, K, 4), CC) \= 0 Then Matching = SubStr(J, K, 3)
End
'SOS SaveCol'
Do TabOffset.3; 'SOS' TabCmd.3; End
'SOS LineAdd'; 'Text' Matching; 'Up'; 'SOS RestoreCol'
End
Do TabOffset.2; 'SOS' TabCmd.2; End
End
Else If Pos('then do', C) \= 0 | Pos('else do', c) \= 0 Then Do
If Templates Then Do
CC = ' 'Curline.3()' '; I = ' Do DO do '; J = 'End END end '
Matching = 'end'
Do K = 1 To 9 By 4
If Pos(SubStr(I, K, 4), CC) \= 0 Then Matching = SubStr(J, K, 3)
End
'SOS SaveCol'
Do TabOffset.3; 'SOS' TabCmd.3; End
'SOS LineAdd'; 'Text' Matching; 'Up'; 'SOS RestoreCol'
End
Do TabOffset.2; 'SOS' TabCmd.2; End
End
Else If Word(C, 1) = 'if' Then Do TabOffset.2; 'SOS' TabCmd.2; End
Else If Word(C, 1) = 'select' Then Do TabOffset.2; 'SOS' TabCmd.2; End
Else If Word(C, 1) = 'when'Then Do TabOffset.2; 'SOS' TabCmd.2; End
Else If Word(C, 1) = 'otherwise' Then Do TabOffset.2; 'SOS' TabCmd.2; End
Else If Word(C, 1) = 'end' & Column.1() \= Word(Tabs.1(), 1) Then Do
Do TabsBack; 'SOS' TabsBackCmd; End
End
Else If TOF() Then 'SOS FirstChar'
Else Do
'Up'
C = Lower(CurLine.3())
If SubStr(C, Max(Length(C) - 3, 1)) = 'then' | C = 'else' Then Do
Do TabsBack; 'SOS' TabsBackCmd; End
End
Else If Word(c, 1) = 'otherwise' & Word(c, 2) = '' Then Do
Do TabsBack; 'SOS' TabsBackCmd; End
End
'Down'
End
End
***** COMMON HANDLING ****
'Set Margins' Cursor.4() '*'
'SOS LineAdd Marginl'
* If Regular Indenting isn't being run, then unset the left margin setting
'Editv Getf Regular'; If Regular = "" Then Regular = 0
If \Regular Then 'Set Margins' LeftMargin '*'
Exit