Some code to add autoindentation:
In Scintilla_OnNotify add
CASE SCN_CHARADDED
IF pNSC->ch = 13 THEN
IF gConfig.AutoIndentation THEN
DIM pDoc AS clsDocument PTR = gTTabCtl.GetActiveDocumentPtr()
IF pDoc THEN
hEdit = pDoc->hWindow
' // Current position
DIM curPos AS LONG = SendMessage(hEdit, SCI_GETCURRENTPOS, 0, 0)
' // Current line
nLine = SendMessage(hEdit, SCI_LINEFROMPOSITION, curPos, 0)
' // Line length of the previous line
DIM LineLen AS LONG = SendMessage(hEdit, SCI_LINELENGTH, nLine - 1, 0)
IF LineLen < 1 THEN EXIT FUNCTION
' // Get the text of the previous line
DIM buffer AS STRING = SPACE(LineLen)
SendMessage(hEdit, SCI_GETLINE, nLine - 1, cast(LPARAM, STRPTR(buffer)))
' // Get the tab width
DIM TabSize AS LONG = SendMessage(hEdit, SCI_GETTABWIDTH, 0, 0)
' // Calculate the number of spaces to fill on the left
DIM nSpaces AS LONG, i AS LONG
FOR i = 1 TO LEN(buffer)
IF MID(buffer, i, 1) <> " " THEN
IF MID(buffer, i, 1) = CHR(9) THEN
nSpaces = nSpaces + TabSize
ELSE
EXIT FOR
END IF
ELSE
nSpaces = nSpaces + 1
END IF
NEXT
DIM strFill AS STRING = ""
' // Remove $CRLF
buffer = FF_Remove(buffer, CHR(13))
buffer = FF_Remove(buffer, CHR(10))
' // Remove spaces and tabs and convert to uppercase
buffer = TRIM(UCASE(buffer), ANY CHR(32, 9))
IF (LEFT$(buffer, 3) = "IF " AND RIGHT$(buffer, 5) = " THEN") OR _
LEFT$(buffer, 4) = "ELSE" OR _
LEFT$(buffer, 7) = "SELECT " OR _
LEFT$(buffer, 5) = "CASE " OR _
LEFT$(buffer, 4) = "FOR " OR _
LEFT$(buffer, 3) = "DO " OR _
buffer = "DO" OR _
LEFT$(buffer, 6) = "WHILE " OR _
buffer = "WHILE" THEN
' // Indentation size
DIM IndentSize AS LONG = SendMessage(hEdit, SCI_GETINDENT, 0, 0)
' // Add spaces to indent the line
strFill = SPACE(nSpaces + IndentSize)
ELSE
' Add the same spaces on the left that the line above
strFill = SPACE(nSpaces)
END IF
' *** TODO: If using tabs, replace spaces with tabs
' // Indents the line
SendMessage(hEdit, SCI_ADDTEXT, LEN(strFill), cast(LPARAM, STRPTR(strFill)))
END IF
END IF
END IF